├── .gitignore
├── .hgignore
├── Deps
├── Newtonsoft.Json.dll
├── Newtonsoft.Json.pdb
└── Newtonsoft.Json.xml
├── LICENSE.txt
├── PaymentTest
├── PaymentTest.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── app.config
├── README
├── XamarinStripe.sln
└── XamarinStripe
├── DateTimeExtensions.cs
├── IUrlEncoderInfo.cs
├── Properties
└── AssemblyInfo.cs
├── StripeAccount.cs
├── StripeBalance.cs
├── StripeBalanceTransaction.cs
├── StripeCard.cs
├── StripeCharge.cs
├── StripeCollection.cs
├── StripeCoupon.cs
├── StripeCouponDuration.cs
├── StripeCouponInfo.cs
├── StripeCreditCardInfo.cs
├── StripeCreditCardToken.cs
├── StripeCustomer.cs
├── StripeCustomerInfo.cs
├── StripeCvcCheck.cs
├── StripeDateTimeInfo.cs
├── StripeDiscount.cs
├── StripeDispute.cs
├── StripeDisputeReason.cs
├── StripeDisputeStatus.cs
├── StripeEnumConverter.cs
├── StripeError.cs
├── StripeEvent.cs
├── StripeException.cs
├── StripeFeeDetail.cs
├── StripeInvoice.cs
├── StripeInvoiceItem.cs
├── StripeInvoiceItemInfo.cs
├── StripeInvoiceLineItems.cs
├── StripeLineItem.cs
├── StripeObject.cs
├── StripeObjectConverter.cs
├── StripePayment.cs
├── StripePeriod.cs
├── StripePlan.cs
├── StripePlanInfo.cs
├── StripePlanInterval.cs
├── StripeSubscription.cs
├── StripeSubscriptionInfo.cs
├── StripeSubscriptionStatus.cs
├── StripeTransfer.cs
├── StripeUpdateCreditCardInfo.cs
├── UnixDateTimeConverter.cs
├── XamarinStripe.csproj
├── XamarinStripe.nuspec
└── packages.config
/.gitignore:
--------------------------------------------------------------------------------
1 | *.suo
2 | bin
3 | obj
4 |
5 | packages
6 |
7 |
--------------------------------------------------------------------------------
/.hgignore:
--------------------------------------------------------------------------------
1 | syntax: glob
2 | PaymentTest/bin/*
3 | XamarinStripe/bin/*
4 | *.userprefs
5 | *.pidb
6 | PaymentTest/obj/*
7 | XamarinStripe/obj/*
8 | *.suo
9 |
--------------------------------------------------------------------------------
/Deps/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xamarin/XamarinStripe/287012e052d992e09120bef6f945f2bd237302d0/Deps/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/Deps/Newtonsoft.Json.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xamarin/XamarinStripe/287012e052d992e09120bef6f945f2bd237302d0/Deps/Newtonsoft.Json.pdb
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | Apache License
4 | Version 2.0, January 2004
5 | http://www.apache.org/licenses/
6 |
7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8 |
9 | 1. Definitions.
10 |
11 | "License" shall mean the terms and conditions for use, reproduction,
12 | and distribution as defined by Sections 1 through 9 of this document.
13 |
14 | "Licensor" shall mean the copyright owner or entity authorized by
15 | the copyright owner that is granting the License.
16 |
17 | "Legal Entity" shall mean the union of the acting entity and all
18 | other entities that control, are controlled by, or are under common
19 | control with that entity. For the purposes of this definition,
20 | "control" means (i) the power, direct or indirect, to cause the
21 | direction or management of such entity, whether by contract or
22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 | outstanding shares, or (iii) beneficial ownership of such entity.
24 |
25 | "You" (or "Your") shall mean an individual or Legal Entity
26 | exercising permissions granted by this License.
27 |
28 | "Source" form shall mean the preferred form for making modifications,
29 | including but not limited to software source code, documentation
30 | source, and configuration files.
31 |
32 | "Object" form shall mean any form resulting from mechanical
33 | transformation or translation of a Source form, including but
34 | not limited to compiled object code, generated documentation,
35 | and conversions to other media types.
36 |
37 | "Work" shall mean the work of authorship, whether in Source or
38 | Object form, made available under the License, as indicated by a
39 | copyright notice that is included in or attached to the work
40 | (an example is provided in the Appendix below).
41 |
42 | "Derivative Works" shall mean any work, whether in Source or Object
43 | form, that is based on (or derived from) the Work and for which the
44 | editorial revisions, annotations, elaborations, or other modifications
45 | represent, as a whole, an original work of authorship. For the purposes
46 | of this License, Derivative Works shall not include works that remain
47 | separable from, or merely link (or bind by name) to the interfaces of,
48 | the Work and Derivative Works thereof.
49 |
50 | "Contribution" shall mean any work of authorship, including
51 | the original version of the Work and any modifications or additions
52 | to that Work or Derivative Works thereof, that is intentionally
53 | submitted to Licensor for inclusion in the Work by the copyright owner
54 | or by an individual or Legal Entity authorized to submit on behalf of
55 | the copyright owner. For the purposes of this definition, "submitted"
56 | means any form of electronic, verbal, or written communication sent
57 | to the Licensor or its representatives, including but not limited to
58 | communication on electronic mailing lists, source code control systems,
59 | and issue tracking systems that are managed by, or on behalf of, the
60 | Licensor for the purpose of discussing and improving the Work, but
61 | excluding communication that is conspicuously marked or otherwise
62 | designated in writing by the copyright owner as "Not a Contribution."
63 |
64 | "Contributor" shall mean Licensor and any individual or Legal Entity
65 | on behalf of whom a Contribution has been received by Licensor and
66 | subsequently incorporated within the Work.
67 |
68 | 2. Grant of Copyright License. Subject to the terms and conditions of
69 | this License, each Contributor hereby grants to You a perpetual,
70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 | copyright license to reproduce, prepare Derivative Works of,
72 | publicly display, publicly perform, sublicense, and distribute the
73 | Work and such Derivative Works in Source or Object form.
74 |
75 | 3. Grant of Patent License. Subject to the terms and conditions of
76 | this License, each Contributor hereby grants to You a perpetual,
77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 | (except as stated in this section) patent license to make, have made,
79 | use, offer to sell, sell, import, and otherwise transfer the Work,
80 | where such license applies only to those patent claims licensable
81 | by such Contributor that are necessarily infringed by their
82 | Contribution(s) alone or by combination of their Contribution(s)
83 | with the Work to which such Contribution(s) was submitted. If You
84 | institute patent litigation against any entity (including a
85 | cross-claim or counterclaim in a lawsuit) alleging that the Work
86 | or a Contribution incorporated within the Work constitutes direct
87 | or contributory patent infringement, then any patent licenses
88 | granted to You under this License for that Work shall terminate
89 | as of the date such litigation is filed.
90 |
91 | 4. Redistribution. You may reproduce and distribute copies of the
92 | Work or Derivative Works thereof in any medium, with or without
93 | modifications, and in Source or Object form, provided that You
94 | meet the following conditions:
95 |
96 | (a) You must give any other recipients of the Work or
97 | Derivative Works a copy of this License; and
98 |
99 | (b) You must cause any modified files to carry prominent notices
100 | stating that You changed the files; and
101 |
102 | (c) You must retain, in the Source form of any Derivative Works
103 | that You distribute, all copyright, patent, trademark, and
104 | attribution notices from the Source form of the Work,
105 | excluding those notices that do not pertain to any part of
106 | the Derivative Works; and
107 |
108 | (d) If the Work includes a "NOTICE" text file as part of its
109 | distribution, then any Derivative Works that You distribute must
110 | include a readable copy of the attribution notices contained
111 | within such NOTICE file, excluding those notices that do not
112 | pertain to any part of the Derivative Works, in at least one
113 | of the following places: within a NOTICE text file distributed
114 | as part of the Derivative Works; within the Source form or
115 | documentation, if provided along with the Derivative Works; or,
116 | within a display generated by the Derivative Works, if and
117 | wherever such third-party notices normally appear. The contents
118 | of the NOTICE file are for informational purposes only and
119 | do not modify the License. You may add Your own attribution
120 | notices within Derivative Works that You distribute, alongside
121 | or as an addendum to the NOTICE text from the Work, provided
122 | that such additional attribution notices cannot be construed
123 | as modifying the License.
124 |
125 | You may add Your own copyright statement to Your modifications and
126 | may provide additional or different license terms and conditions
127 | for use, reproduction, or distribution of Your modifications, or
128 | for any such Derivative Works as a whole, provided Your use,
129 | reproduction, and distribution of the Work otherwise complies with
130 | the conditions stated in this License.
131 |
132 | 5. Submission of Contributions. Unless You explicitly state otherwise,
133 | any Contribution intentionally submitted for inclusion in the Work
134 | by You to the Licensor shall be under the terms and conditions of
135 | this License, without any additional terms or conditions.
136 | Notwithstanding the above, nothing herein shall supersede or modify
137 | the terms of any separate license agreement you may have executed
138 | with Licensor regarding such Contributions.
139 |
140 | 6. Trademarks. This License does not grant permission to use the trade
141 | names, trademarks, service marks, or product names of the Licensor,
142 | except as required for reasonable and customary use in describing the
143 | origin of the Work and reproducing the content of the NOTICE file.
144 |
145 | 7. Disclaimer of Warranty. Unless required by applicable law or
146 | agreed to in writing, Licensor provides the Work (and each
147 | Contributor provides its Contributions) on an "AS IS" BASIS,
148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 | implied, including, without limitation, any warranties or conditions
150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 | PARTICULAR PURPOSE. You are solely responsible for determining the
152 | appropriateness of using or redistributing the Work and assume any
153 | risks associated with Your exercise of permissions under this License.
154 |
155 | 8. Limitation of Liability. In no event and under no legal theory,
156 | whether in tort (including negligence), contract, or otherwise,
157 | unless required by applicable law (such as deliberate and grossly
158 | negligent acts) or agreed to in writing, shall any Contributor be
159 | liable to You for damages, including any direct, indirect, special,
160 | incidental, or consequential damages of any character arising as a
161 | result of this License or out of the use or inability to use the
162 | Work (including but not limited to damages for loss of goodwill,
163 | work stoppage, computer failure or malfunction, or any and all
164 | other commercial damages or losses), even if such Contributor
165 | has been advised of the possibility of such damages.
166 |
167 | 9. Accepting Warranty or Additional Liability. While redistributing
168 | the Work or Derivative Works thereof, You may choose to offer,
169 | and charge a fee for, acceptance of support, warranty, indemnity,
170 | or other liability obligations and/or rights consistent with this
171 | License. However, in accepting such obligations, You may act only
172 | on Your own behalf and on Your sole responsibility, not on behalf
173 | of any other Contributor, and only if You agree to indemnify,
174 | defend, and hold each Contributor harmless for any liability
175 | incurred by, or claims asserted against, such Contributor by reason
176 | of your accepting any such warranty or additional liability.
177 |
178 | END OF TERMS AND CONDITIONS
179 |
180 | APPENDIX: How to apply the Apache License to your work.
181 |
182 | To apply the Apache License to your work, attach the following
183 | boilerplate notice, with the fields enclosed by brackets "[]"
184 | replaced with your own identifying information. (Don't include
185 | the brackets!) The text should be enclosed in the appropriate
186 | comment syntax for the file format. We also recommend that a
187 | file or class name and description of purpose be included on the
188 | same "printed page" as the copyright notice for easier
189 | identification within third-party archives.
190 |
191 | Copyright [yyyy] [name of copyright owner]
192 |
193 | Licensed under the Apache License, Version 2.0 (the "License");
194 | you may not use this file except in compliance with the License.
195 | You may obtain a copy of the License at
196 |
197 | http://www.apache.org/licenses/LICENSE-2.0
198 |
199 | Unless required by applicable law or agreed to in writing, software
200 | distributed under the License is distributed on an "AS IS" BASIS,
201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 | See the License for the specific language governing permissions and
203 | limitations under the License.
204 |
--------------------------------------------------------------------------------
/PaymentTest/PaymentTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}
9 | Exe
10 | Properties
11 | PaymentTest
12 | PaymentTest
13 | 512
14 |
15 |
16 | x86
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | x86
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | False
37 | ..\packages\Newtonsoft.Json.5.0.6\lib\net40\Newtonsoft.Json.dll
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}
54 | XamarinStripe
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
69 |
--------------------------------------------------------------------------------
/PaymentTest/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Xamarin, Inc., Joe Dluzen
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | * Joe Dluzen (jdluzen@gmail.com)
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | using System;
21 | using System.Collections.Generic;
22 | using Xamarin.Payments.Stripe;
23 | using Newtonsoft.Json;
24 |
25 | namespace PaymentTest {
26 | class Program {
27 | static void Main (string [] args)
28 | {
29 | StripePayment payment = new StripePayment ("vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE");
30 | TestSimpleCharge (payment);
31 | //TestPartialRefund (payment);
32 | //TestCustomer (payment);
33 | TestCustomerAndCharge (payment);
34 | //TestGetCharges (payment);
35 | TestGetCustomers (payment);
36 | //TestCreateGetToken (payment);
37 | //TestCreatePlanGetPlan (payment);
38 | //TestCreateSubscription (payment);
39 | //TestCreateInvoiceItems (payment);
40 | //TestInvoices (payment);
41 | //TestInvoices2 (payment);
42 | TestDeserializePastDue ();
43 | }
44 |
45 | static StripeCreditCardInfo GetCC ()
46 | {
47 | StripeCreditCardInfo cc = new StripeCreditCardInfo ();
48 | cc.CVC = "1234";
49 | cc.ExpirationMonth = 6;
50 | cc.ExpirationYear = 2015;
51 | cc.Number = "4242424242424242";
52 | return cc;
53 | }
54 |
55 | static StripePlanInfo GetPlanInfo ()
56 | {
57 | return new StripePlanInfo {
58 | Amount = 1999,
59 | ID = "myplan",
60 | Interval = StripePlanInterval.Month,
61 | Name = "My standard plan",
62 | TrialPeriod = 7
63 | };
64 | }
65 |
66 | static StripeInvoiceItemInfo GetInvoiceItemInfo ()
67 | {
68 | return new StripeInvoiceItemInfo {
69 | Amount = 1999,
70 | Description = "Invoice item: " + Guid.NewGuid ().ToString ()
71 | };
72 | }
73 |
74 | static void TestSimpleCharge (StripePayment payment)
75 | {
76 | StripeCreditCardInfo cc = GetCC ();
77 | StripeCharge charge = payment.Charge (5001, "usd", cc, "Test charge");
78 | Console.WriteLine (charge);
79 | string charge_id = charge.ID;
80 | StripeCharge charge_info = payment.GetCharge (charge_id);
81 | Console.WriteLine (charge_info);
82 |
83 | StripeCharge refund = payment.Refund (charge_info.ID);
84 | Console.WriteLine (refund.Created);
85 | }
86 |
87 | static void TestPartialRefund (StripePayment payment)
88 | {
89 | StripeCreditCardInfo cc = GetCC ();
90 | StripeCharge charge = payment.Charge (5001, "usd", cc, "Test partial refund");
91 | Console.WriteLine (charge.ID);
92 | StripeCharge refund = payment.Refund (charge.ID, 2499);
93 | Console.WriteLine (refund.Amount);
94 | }
95 |
96 | static void TestCustomer (StripePayment payment)
97 | {
98 | StripeCustomerInfo customer = new StripeCustomerInfo ();
99 | //customer.Card = GetCC ();
100 | StripeCustomer customer_resp = payment.CreateCustomer (customer);
101 | string customer_id = customer_resp.ID;
102 | StripeCustomer customer_info = payment.GetCustomer (customer_id);
103 | Console.WriteLine (customer_info);
104 | StripeCustomer ci2 = payment.DeleteCustomer (customer_id);
105 | if (ci2.Deleted == false)
106 | throw new Exception ("Failed to delete " + customer_id);
107 | }
108 |
109 | static void TestCustomerAndCharge (StripePayment payment)
110 | {
111 | StripeCustomerInfo customer = new StripeCustomerInfo ();
112 | //customer.Card = GetCC ();
113 | StripeCustomer response = payment.CreateCustomer (customer);
114 | string customer_id = response.ID;
115 | StripeCustomer customer_info = payment.GetCustomer (customer_id);
116 | Console.WriteLine (customer_info);
117 | StripeCustomerInfo info_update = new StripeCustomerInfo ();
118 | info_update.Card = GetCC ();
119 | StripeCustomer update_resp = payment.UpdateCustomer (customer_id, info_update);
120 | Console.Write ("Customer updated with CC. Press ENTER to continue...");
121 | Console.Out.Flush ();
122 | Console.ReadLine ();
123 | StripeCustomer ci2 = payment.DeleteCustomer (customer_id);
124 | if (ci2.Deleted == false)
125 | throw new Exception ("Failed to delete " + customer_id);
126 | }
127 |
128 | static void TestGetCharges (StripePayment payment)
129 | {
130 | var charges = payment.GetCharges (0, 10);
131 | Console.WriteLine (charges.Data.Count);
132 | }
133 |
134 | static void TestGetCustomers (StripePayment payment)
135 | {
136 | var customers = payment.GetCustomers (0, 10);
137 | Console.WriteLine (customers.Data.Count);
138 | }
139 |
140 | static void TestCreateGetToken (StripePayment payment)
141 | {
142 | StripeCreditCardToken tok = payment.CreateToken (GetCC ());
143 | StripeCreditCardToken tok2 = payment.GetToken (tok.ID);
144 | }
145 |
146 | static void TestCreatePlanGetPlan (StripePayment payment)
147 | {
148 | StripePlan plan = CreatePlan (payment);
149 | var plans = payment.GetPlans (10, 10);
150 | Console.WriteLine (plans.Total);
151 | }
152 |
153 | static StripePlan CreatePlan (StripePayment payment)
154 | {
155 | StripePlan plan = payment.CreatePlan (GetPlanInfo ());
156 | StripePlan plan2 = payment.GetPlan (plan.ID);
157 | //DeletePlan (plan2, payment);
158 | return plan2;
159 | }
160 |
161 | static StripePlan DeletePlan (StripePlan plan, StripePayment payment)
162 | {
163 | StripePlan deleted = payment.DeletePlan (plan.ID);
164 | return deleted;
165 | }
166 |
167 | static void TestCreateSubscription (StripePayment payment)
168 | {
169 | StripeCustomer cust = payment.CreateCustomer (new StripeCustomerInfo {
170 | Card = GetCC ()
171 | });
172 | //StripePlan temp = new StripePlan { ID = "myplan" };
173 | //DeletePlan (temp, payment);
174 | StripePlan plan = CreatePlan (payment);
175 | StripeSubscription sub = payment.Subscribe (cust.ID, new StripeSubscriptionInfo {
176 | Card = GetCC (),
177 | Plan = "myplan",
178 | Prorate = true
179 | });
180 | StripeSubscription sub2 = payment.GetSubscription (sub.CustomerID);
181 | TestDeleteSubscription (cust, payment);
182 | DeletePlan (plan, payment);
183 | }
184 |
185 | static StripeSubscription TestDeleteSubscription (StripeCustomer customer, StripePayment payment)
186 | {
187 | StripeSubscription sub = payment.Unsubscribe (customer.ID, true);
188 | return sub;
189 | }
190 |
191 | static void TestCreateInvoiceItems (StripePayment payment)
192 | {
193 | StripeCustomer cust = payment.CreateCustomer (new StripeCustomerInfo ());
194 | StripeInvoiceItemInfo info = GetInvoiceItemInfo ();
195 | info.CustomerID = cust.ID;
196 | StripeInvoiceItem item = payment.CreateInvoiceItem (info);
197 | StripeInvoiceItemInfo newInfo = GetInvoiceItemInfo ();
198 | newInfo.Description = "Invoice item: " + Guid.NewGuid ().ToString ();
199 | StripeInvoiceItem item2 = payment.UpdateInvoiceItem (item.ID, newInfo);
200 | StripeInvoiceItem item3 = payment.GetInvoiceItem (item2.ID);
201 | if (item.Description == item3.Description)
202 | throw new Exception ("Update failed");
203 | StripeInvoiceItem deleted = payment.DeleteInvoiceItem (item2.ID);
204 | if (!deleted.Deleted.HasValue && deleted.Deleted.Value)
205 | throw new Exception ("Delete failed");
206 | var items = payment.GetInvoiceItems (10, 10, null);
207 | Console.WriteLine (items.Total);
208 | payment.DeleteCustomer (cust.ID);
209 | }
210 |
211 | static void TestInvoices (StripePayment payment)
212 | {
213 | var invoices = payment.GetInvoices (10, 10);
214 | StripeInvoice inv = payment.GetInvoice (invoices.Data [0].ID);
215 | StripeCustomer cust = payment.CreateCustomer (new StripeCustomerInfo ());
216 | StripeSubscription sub = payment.Subscribe (cust.ID, new StripeSubscriptionInfo {
217 | Card = GetCC ()
218 | });
219 | StripeInvoice inv2 = payment.GetUpcomingInvoice (cust.ID);
220 | payment.Unsubscribe (cust.ID, true);
221 | payment.DeleteCustomer (cust.ID);
222 | }
223 |
224 | static void TestInvoices2 (StripePayment payment)
225 | {
226 | StripeCustomer cust = payment.GetCustomer ("cus_ulcOcy5Seu2dpq");
227 | StripePlanInfo planInfo = new StripePlanInfo{
228 | Amount = 1999,
229 | ID = "testplan",
230 | Interval = StripePlanInterval.Month,
231 | Name = "The Test Plan",
232 | //TrialPeriod = 7
233 | };
234 | //payment.DeletePlan (planInfo.ID);
235 | StripePlan plan = payment.CreatePlan (planInfo);
236 | StripeSubscriptionInfo subInfo = new StripeSubscriptionInfo{
237 | Card = GetCC (),
238 | Plan = planInfo.ID,
239 | Prorate = true
240 | };
241 | StripeSubscription sub = payment.Subscribe (cust.ID, subInfo);
242 | payment.CreateInvoiceItem (new StripeInvoiceItemInfo {
243 | CustomerID = cust.ID,
244 | Amount = 1337,
245 | Description = "Test single charge"
246 | });
247 |
248 | var invoices = payment.GetInvoices (0, 10, cust.ID);
249 | StripeInvoice upcoming = payment.GetUpcomingInvoice (cust.ID);
250 | payment.Unsubscribe (cust.ID, true);
251 | payment.DeletePlan (planInfo.ID);
252 | foreach (StripeLineItem line in upcoming) {
253 | Console.WriteLine ("{0} for type {1}", line.Amount, line.GetType ());
254 | }
255 |
256 | }
257 |
258 | static void TestDeserializePastDue ()
259 | {
260 | string json = @"{
261 | ""status"": ""past_due"",
262 | }";
263 | StripeSubscription sub = JsonConvert.DeserializeObject (json);
264 | if (sub.Status != StripeSubscriptionStatus.PastDue)
265 | throw new Exception ("Failed to deserialize `StripeSubscriptionStatus.PastDue`");
266 | string json2 = JsonConvert.SerializeObject(sub);
267 | }
268 | }
269 | }
270 |
--------------------------------------------------------------------------------
/PaymentTest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("PaymentTest")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("PaymentTest")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("e657f563-9428-4b35-80de-6030958c0295")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/PaymentTest/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | XamarinStripe provides .NET bindings to process online payments with Stripe.com.
2 |
3 | XamarinStripe/
4 |
5 | Source code for the assembly.
6 |
7 | PaymentTest/
8 |
9 | Sample program using the library
10 |
--------------------------------------------------------------------------------
/XamarinStripe.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamarinStripe", "XamarinStripe\XamarinStripe.csproj", "{218CF4C2-C457-43E4-9D1B-0880D10181FF}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaymentTest", "PaymentTest\PaymentTest.csproj", "{8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|Mixed Platforms = Debug|Mixed Platforms
12 | Debug|x86 = Debug|x86
13 | Release|Any CPU = Release|Any CPU
14 | Release|Mixed Platforms = Release|Mixed Platforms
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
21 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
22 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Debug|x86.ActiveCfg = Debug|Any CPU
23 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
26 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
27 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}.Release|x86.ActiveCfg = Release|Any CPU
28 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Debug|Any CPU.ActiveCfg = Debug|x86
29 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
30 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Debug|Mixed Platforms.Build.0 = Debug|x86
31 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Debug|x86.ActiveCfg = Debug|x86
32 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Debug|x86.Build.0 = Debug|x86
33 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Release|Any CPU.ActiveCfg = Release|x86
34 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Release|Mixed Platforms.ActiveCfg = Release|x86
35 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Release|Mixed Platforms.Build.0 = Release|x86
36 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Release|x86.ActiveCfg = Release|x86
37 | {8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Release|x86.Build.0 = Release|x86
38 | EndGlobalSection
39 | GlobalSection(MonoDevelopProperties) = preSolution
40 | StartupItem = PaymentTest\PaymentTest.csproj
41 | Policies = $0
42 | $0.TextStylePolicy = $1
43 | $1.FileWidth = 120
44 | $1.RemoveTrailingWhitespace = True
45 | $1.inheritsSet = VisualStudio
46 | $1.inheritsScope = text/plain
47 | $1.scope = text/x-csharp
48 | $0.CSharpFormattingPolicy = $2
49 | $2.NamespaceBraceStyle = EndOfLine
50 | $2.ClassBraceStyle = EndOfLine
51 | $2.InterfaceBraceStyle = EndOfLine
52 | $2.SpacesAfterTypecast = True
53 | $2.inheritsSet = Mono
54 | $2.inheritsScope = text/x-csharp
55 | $2.scope = text/x-csharp
56 | $0.StandardHeader = $3
57 | $3.Text =
58 | $3.IncludeInNewFiles = True
59 | EndGlobalSection
60 | GlobalSection(SolutionProperties) = preSolution
61 | HideSolutionNode = FALSE
62 | EndGlobalSection
63 | EndGlobal
64 |
--------------------------------------------------------------------------------
/XamarinStripe/DateTimeExtensions.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 |
21 | namespace Xamarin.Payments.Stripe {
22 | public static class DateTimeExtensions {
23 | static DateTime epoch = new DateTime (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
24 |
25 | public static DateTime FromUnixEpoch (this int utc_unix)
26 | {
27 | return epoch.AddSeconds (utc_unix);
28 | }
29 |
30 | public static DateTime FromUnixEpoch (this long utc_unix)
31 | {
32 | return epoch.AddSeconds (utc_unix);
33 | }
34 |
35 | public static long ToUnixEpoch (this DateTime dt)
36 | {
37 | dt = dt.ToUniversalTime ();
38 | return Convert.ToInt64 ((dt - epoch).TotalSeconds);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/XamarinStripe/IUrlEncoderInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */using System;
19 | using System.Text;
20 |
21 | namespace Xamarin.Payments.Stripe {
22 | public interface IUrlEncoderInfo {
23 | void UrlEncode (StringBuilder sb);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/XamarinStripe/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("XamarinStripe")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("XamarinStripe")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("f7f2695f-edeb-4107-bcff-139981ad8e93")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeAccount.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Xamarin, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | using System;
17 | using System.Collections.Generic;
18 | using System.Linq;
19 | using System.Text;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | class StripeAccount : StripeId {
24 | [JsonProperty ("email")]
25 | public string Email { get; set; }
26 | [JsonProperty ("statement_descriptor")]
27 | public string StatementDescriptor { get; set; }
28 | [JsonProperty ("details_submitted")]
29 | public bool DetailsSubmitted { get; set; }
30 | [JsonProperty ("charge_enabled")]
31 | public bool ChargeEnabled { get; set; }
32 | [JsonProperty ("currencies_supported")]
33 | public List CurrenciesSupported { get; set; }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeBalance.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Newtonsoft.Json;
6 |
7 | namespace Xamarin.Payments.Stripe {
8 | public class StripeBalance :StripeObject {
9 | [JsonProperty ("pending")]
10 | public List Pending { get; set; }
11 | [JsonProperty ("available")]
12 | public List Available { get; set; }
13 |
14 | public class Value {
15 | [JsonProperty ("amount")]
16 | public int Amount { get; set; }
17 |
18 | [JsonProperty ("currency")]
19 | public string Currency { get; set; }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeBalanceTransaction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Newtonsoft.Json;
6 |
7 | namespace Xamarin.Payments.Stripe {
8 |
9 | [JsonConverter (typeof (StripeEnumConverter))]
10 | public enum StripeBalanceTransactionType {
11 | Charge,
12 | Refund,
13 | Adjustment,
14 | ApplicationFee,
15 | ApplicationFeeRefund,
16 | Transfer,
17 | TransferCancel,
18 | TransferFailure
19 | }
20 |
21 | public class StripeBalanceTransaction : StripeObject {
22 | [JsonProperty ("source")]
23 | public string Source { get; set; }
24 |
25 | [JsonProperty ("amount")]
26 | public int Amount { get; set; }
27 |
28 | [JsonProperty ("currency")]
29 | public string Currency { get; set; }
30 |
31 | [JsonProperty ("available_on")]
32 | public int Net { get; set; }
33 |
34 | [JsonProperty ("fee")]
35 | public int Fee { get; set; }
36 |
37 | [JsonProperty ("description")]
38 | public string Description { get; set; }
39 |
40 | [JsonProperty ("status")]
41 | public string Status { get; set; }
42 |
43 | [JsonProperty ("type")]
44 | public StripeBalanceTransactionType Type { get; set; }
45 |
46 | [JsonProperty ("available_on")]
47 | [JsonConverter (typeof (UnixDateTimeConverter))]
48 | public DateTime AvailableOn { get; set; }
49 |
50 | [JsonProperty ("created")]
51 | [JsonConverter (typeof (UnixDateTimeConverter))]
52 | public DateTime Created { get; set; }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCard.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 - 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | * Joe Dluzen (jdluzen@gmail.com)
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeCard : StripeId {
25 | [JsonProperty (PropertyName = "type")]
26 | public string Type { get; set; }
27 | [JsonProperty (PropertyName = "country")]
28 | public string Country { get; set; }
29 | [JsonProperty (PropertyName = "exp_month")]
30 | public int ExpirationMonth { get; set; }
31 | [JsonProperty (PropertyName = "exp_year")]
32 | public int ExpirationYear { get; set; }
33 | [JsonProperty (PropertyName = "last4")]
34 | public string Last4 { get; set; }
35 | [JsonProperty (PropertyName = "cvc_check")]
36 | public StripeCvcCheck? CvcCheck { get; set; }
37 | [JsonProperty (PropertyName = "address_country")]
38 | public string AddressCountry { get; set; }
39 | [JsonProperty (PropertyName = "address_state")]
40 | public string AddressState { get; set; }
41 | [JsonProperty (PropertyName = "address_zip")]
42 | public string AddressZip { get; set; }
43 | [JsonProperty (PropertyName = "address_line1")]
44 | public string AddressLine1 { get; set; }
45 | [JsonProperty (PropertyName = "address_line2")]
46 | public string AddressLine2 { get; set; }
47 | [JsonProperty (PropertyName = "address_zip_check")]
48 | public string AddressZipCheck { get; set; }
49 | [JsonProperty (PropertyName = "name")]
50 | public string Name { get; set; }
51 | [JsonProperty (PropertyName = "fingerprint")]
52 | public string Fingerprint { get; set; }
53 | [JsonProperty (PropertyName = "deleted")]
54 | public bool Deleted { get; set; }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCharge.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 - 2012 Xamarin, Inc., 2011 - 2012 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | * Joe Dluzen (jdluzen@gmail.com)
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | using System;
21 | using Newtonsoft.Json;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | [JsonObject (MemberSerialization.OptIn)]
25 | public class StripeCharge : StripeId {
26 | [JsonProperty (PropertyName = "attempted")]
27 | public bool Attempted { get; set; }
28 | [JsonProperty (PropertyName = "refunded")]
29 | public bool Refunded { get; set; }
30 | [JsonProperty (PropertyName = "amount_refunded")]
31 | public int AmountRefunded { get; set; }
32 | [JsonProperty (PropertyName = "paid")]
33 | public bool Paid { get; set; }
34 | [JsonProperty (PropertyName = "amount")]
35 | public int Amount { get; set; }
36 | [JsonProperty (PropertyName = "fee")]
37 | public int Fee { get; set; }
38 | [JsonProperty (PropertyName = "livemode")]
39 | public bool LiveMode { get; set; }
40 | /* api changed */
41 | /*
42 | [JsonProperty (PropertyName = "disputed")]
43 | public bool Disputed { get; set; }
44 | */
45 | [JsonProperty (PropertyName = "dispute")]
46 | public StripeDispute Dispute { get; set; }
47 | [JsonProperty (PropertyName = "description")]
48 | public string Description { get; set; }
49 | [JsonProperty (PropertyName = "currency")]
50 | public string Currency { get; set; }
51 | [JsonProperty (PropertyName = "created")]
52 | [JsonConverter (typeof (UnixDateTimeConverter))]
53 | public DateTime? Created { get; set; }
54 | [JsonProperty (PropertyName = "card")]
55 | public StripeCard Card { get; set; }
56 | [JsonProperty (PropertyName = "customer")]
57 | public string Customer { get; set; }
58 | [JsonProperty (PropertyName = "fee_details")]
59 | public StripeFeeDetail [] FeeDetails { get; set; }
60 | [JsonProperty (PropertyName = "failure_message")]
61 | public string FailureMessage { get; set; }
62 | [JsonProperty (PropertyName = "invoice")]
63 | public string Invoice { get; set; }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCollection.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Xamarin, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | using System;
17 | using System.Collections.Generic;
18 | using System.Linq;
19 | using System.Text;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeCollection : IEnumerable {
25 | [JsonProperty ("url")]
26 | public string Url { get; set; }
27 |
28 | [JsonProperty ("count")]
29 | public int Total { get; set; }
30 |
31 | [JsonProperty ("data")]
32 | public List Data { get; set; }
33 |
34 | #region IEnumerable[T] implementation
35 | public IEnumerator GetEnumerator ()
36 | {
37 | return Data.GetEnumerator ();
38 | }
39 | #endregion
40 |
41 | #region IEnumerable implementation
42 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
43 | {
44 | return GetEnumerator ();
45 | }
46 | #endregion
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCoupon.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeCoupon : StripeId {
25 | [JsonProperty (PropertyName = "times_redeemed")]
26 | public int TimesRedeemed { get; set; }
27 |
28 | [JsonProperty (PropertyName = "livemode")]
29 | public bool LiveMode { get; set; }
30 |
31 | [JsonProperty (PropertyName = "duration")]
32 | public StripeCouponDuration Duration { get; set; }
33 |
34 | [JsonProperty (PropertyName = "percent_off")]
35 | public int? PercentOff { get; set; }
36 |
37 | [JsonProperty(PropertyName = "amount_off")]
38 | public int? AmountOff { get; set; }
39 |
40 | [JsonProperty (PropertyName = "deleted")]
41 | public bool? Deleted { get; set; }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCouponDuration.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 | using Newtonsoft.Json.Converters;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | [JsonConverter (typeof (StripeEnumConverter))]
25 | public enum StripeCouponDuration {
26 | Forever,
27 | Once,
28 | Repeating
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCouponInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Text;
21 | using System.Web;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | public class StripeCouponInfo : IUrlEncoderInfo {
25 | public string ID { get; set; }
26 |
27 | public int PercentOff { get; set; }
28 |
29 | public StripeCouponDuration Duration { get; set; }
30 |
31 | public int MonthsForDuration { get; set; }
32 |
33 | public int MaxRedemptions { get; set; }
34 |
35 | public DateTime RedeemBy { get; set; }
36 |
37 | #region IUrlEncoderInfo implementation
38 | public virtual void UrlEncode (StringBuilder sb)
39 | {
40 | sb.AppendFormat ("percent_off={0}&duration={1}&", PercentOff, HttpUtility.UrlEncode (Duration.ToString ().ToLower ()));
41 | if (!string.IsNullOrEmpty (ID))
42 | sb.AppendFormat ("id={0}&", HttpUtility.UrlEncode (ID));
43 | if (MonthsForDuration > 0)
44 | sb.AppendFormat ("duration_in_months={0}&", MonthsForDuration);
45 | if (MaxRedemptions > 0)
46 | sb.AppendFormat ("max_redemptions={0}&", MaxRedemptions);
47 | if (RedeemBy != DateTime.MinValue)
48 | sb.AppendFormat ("redeem_by={0}&", RedeemBy.ToUnixEpoch ());
49 | }
50 | #endregion
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCreditCardInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Text;
21 | using System.Web;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | public class StripeCreditCardInfo : IUrlEncoderInfo {
25 | // Mandatory
26 | public string Number { get; set; }
27 | // Mandatory when Number is a not one-time token instead of a number
28 | public int ExpirationMonth { get; set; }
29 | public int ExpirationYear { get; set; }
30 | // Optional, highly recommended
31 | public string CVC { get; set; }
32 | // Optional, recommended
33 | public string FullName { get; set; }
34 | public string AddressLine1 { get; set; }
35 | public string AddressLine2 { get; set; }
36 | public string ZipCode { get; set; }
37 | public string StateOrProvince { get; set; }
38 | public string Country { get; set; }
39 |
40 | public virtual void UrlEncode (StringBuilder sb)
41 | {
42 | if (String.IsNullOrEmpty (Number))
43 | throw new ArgumentNullException ("Number");
44 |
45 | bool is_number = Char.IsDigit (Number [0]);
46 | if (is_number && (ExpirationMonth <= 0 || ExpirationMonth > 12))
47 | throw new ArgumentOutOfRangeException ("ExpirationMonth");
48 | if (is_number && ExpirationYear <= 0)
49 | throw new ArgumentOutOfRangeException ("ExpirationYear");
50 |
51 | if (!is_number) {
52 | // One-time token
53 | sb.AppendFormat ("card={0}&", HttpUtility.UrlEncode (Number));
54 | return;
55 | }
56 | sb.AppendFormat ("card[number]={0}&card[exp_month]={1}&card[exp_year]={2}&",
57 | HttpUtility.UrlEncode (Number), ExpirationMonth, ExpirationYear);
58 | if (!String.IsNullOrEmpty (CVC))
59 | sb.AppendFormat ("card[cvc]={0}&", HttpUtility.UrlEncode (CVC));
60 | if (!String.IsNullOrEmpty (FullName))
61 | sb.AppendFormat ("card[name]={0}&", HttpUtility.UrlEncode (FullName));
62 | if (!String.IsNullOrEmpty (AddressLine1))
63 | sb.AppendFormat ("card[address_line1]={0}&", HttpUtility.UrlEncode (AddressLine1));
64 | if (!String.IsNullOrEmpty (AddressLine2))
65 | sb.AppendFormat ("card[address_line2]={0}&", HttpUtility.UrlEncode (AddressLine2));
66 | if (!String.IsNullOrEmpty (ZipCode))
67 | sb.AppendFormat ("card[address_zip]={0}&", HttpUtility.UrlEncode (ZipCode));
68 | if (!String.IsNullOrEmpty (StateOrProvince))
69 | sb.AppendFormat ("card[address_state]={0}&", HttpUtility.UrlEncode (StateOrProvince));
70 | if (!String.IsNullOrEmpty (Country))
71 | sb.AppendFormat ("card[address_country]={0}&", HttpUtility.UrlEncode (Country));
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCreditCardToken.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | public class StripeCreditCardToken : StripeId {
24 | [JsonProperty (PropertyName = "created")]
25 | [JsonConverter (typeof(UnixDateTimeConverter))]
26 | public DateTime Created { get; set; }
27 |
28 | [JsonProperty (PropertyName = "currency")]
29 | public string Currency { get; set; }
30 |
31 | [JsonProperty (PropertyName = "used")]
32 | public bool Used { get; set; }
33 |
34 | [JsonProperty (PropertyName = "amount")]
35 | public int MinimumAmount { get; set; }
36 |
37 | [JsonProperty (PropertyName = "livemode")]
38 | public bool Live { get; set; }
39 |
40 | [JsonProperty (PropertyName = "card")]
41 | public StripeCard Card { get; set; }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCustomer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 - 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeCustomer : StripeId {
25 |
26 | [JsonProperty (PropertyName = "livemode")]
27 | public bool LiveMode { get; set; }
28 |
29 | [JsonProperty (PropertyName = "description")]
30 | public string Description { get; set; }
31 |
32 | [JsonProperty (PropertyName = "created")]
33 | [JsonConverter (typeof (UnixDateTimeConverter))]
34 | public DateTime? Created { get; set; }
35 |
36 | [JsonProperty (PropertyName = "deleted")]
37 | public bool Deleted { get; set; }
38 |
39 | [JsonProperty (PropertyName = "active_card")]
40 | public StripeCard Card { get; set; }
41 |
42 | [JsonProperty (PropertyName = "account_balance")]
43 | public int AccountBalance { get; set; }
44 |
45 | [JsonProperty (PropertyName = "deliquent")]
46 | public bool? Deliquent { get; set; }
47 |
48 | [JsonProperty (PropertyName = "email")]
49 | public string Email { get; set; }
50 |
51 | [JsonProperty (PropertyName = "discount")]
52 | public StripeDiscount Discount { get; set; }
53 |
54 | [JsonProperty (PropertyName = "subscription")]
55 | public StripeSubscription Subscription { get; set; }
56 |
57 | [JsonProperty (PropertyName = "cards")]
58 | public StripeCollection Cards { get; set; }
59 |
60 | [JsonProperty (PropertyName = "default_card")]
61 | public string DefaultCard { get; set; }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCustomerInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Globalization;
21 | using System.Text;
22 | using System.Web;
23 |
24 | namespace Xamarin.Payments.Stripe {
25 | public class StripeCustomerInfo : IUrlEncoderInfo {
26 | public StripeCreditCardInfo Card { get; set; }
27 | // The strings allow ""
28 | public string Coupon { get; set; }
29 | public string Email { get; set; } //TODO: Validate this using System.Net.Mail.MailAddress?
30 | public string Description { get; set; }
31 | public string Plan { get; set; }
32 | public DateTime? TrialEnd { get; set; }
33 | public bool? Validate { get; set; }
34 | public string DefaultCardId { get; set; }
35 |
36 | public virtual void UrlEncode (StringBuilder sb)
37 | {
38 | if (Card != null)
39 | Card.UrlEncode (sb);
40 | if (Coupon != null)
41 | sb.AppendFormat ("coupon={0}&", HttpUtility.UrlEncode (Coupon));
42 | if (Email != null)
43 | sb.AppendFormat ("email={0}&", HttpUtility.UrlEncode (Email));
44 | if (Description != null)
45 | sb.AppendFormat ("description={0}&", HttpUtility.UrlEncode (Description));
46 | if (Plan != null)
47 | sb.AppendFormat ("plan={0}&", HttpUtility.UrlEncode (Plan));
48 | if (TrialEnd.HasValue)
49 | sb.AppendFormat ("trial_end={0}&", TrialEnd.Value.ToUnixEpoch ());
50 | if (Validate.HasValue)
51 | sb.AppendFormat ("validate={0}&", Validate.Value.ToString (CultureInfo.InvariantCulture).ToLowerInvariant ());
52 | if (DefaultCardId != null)
53 | sb.AppendFormat ("default_card={0}&", HttpUtility.UrlEncode (DefaultCardId));
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeCvcCheck.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 | using Newtonsoft.Json.Converters;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | [JsonConverter (typeof (StripeEnumConverter))]
25 | public enum StripeCvcCheck {
26 | Unknown,
27 | Pass,
28 | Fail,
29 | Unchecked
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeDateTimeInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Web;
6 |
7 | namespace Xamarin.Payments.Stripe {
8 | public class StripeDateTimeInfo : IUrlEncoderInfo {
9 | public DateTime gt { set { values["gt"] = value; } }
10 | public DateTime gte { set { values["gte"] = value; } }
11 | public DateTime lt { set { values["lt"] = value; } }
12 | public DateTime lte { set { values["lte"] = value; } }
13 | public DateTime on { set { values ["on"] = value; } }
14 |
15 | Dictionary values = new Dictionary ();
16 | internal string Prefix { get; set; }
17 |
18 | public virtual void UrlEncode (StringBuilder sb)
19 | {
20 | if (values.ContainsKey ("on")) {
21 | sb.AppendFormat ("{0}={1}&", Prefix, values ["on"].ToUnixEpoch ());
22 | } else {
23 | foreach (var key in values.Keys) {
24 | var date = values [key];
25 | sb.AppendFormat ("{0}[{1}]={2}&", Prefix, HttpUtility.UrlEncode (key), date.ToUnixEpoch ());
26 | }
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeDiscount.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Xamarin, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | using System;
17 | using System.Collections.Generic;
18 | using System.Linq;
19 | using System.Text;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeDiscount : StripeId {
25 | [JsonProperty (PropertyName = "customer")]
26 | public string Customer { get; set; }
27 |
28 | [JsonProperty (PropertyName = "coupon")]
29 | public string Coupon { get; set; }
30 |
31 | [JsonProperty (PropertyName = "start")]
32 | [JsonConverter (typeof (UnixDateTimeConverter))]
33 | public DateTime? Start { get; set; }
34 |
35 | [JsonProperty (PropertyName = "end")]
36 | [JsonConverter (typeof (UnixDateTimeConverter))]
37 | public DateTime? End { get; set; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeDispute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Newtonsoft.Json;
6 |
7 | namespace Xamarin.Payments.Stripe {
8 | public class StripeDispute : StripeObject {
9 | [JsonProperty("status")]
10 | public StripeDisputeStatus Status { get; set; }
11 |
12 | [JsonProperty ("evidence")]
13 | public string Evidence { get; set; }
14 |
15 | [JsonProperty ("charge")]
16 | public string Charge { get; set; }
17 |
18 | [JsonProperty ("created")]
19 | [JsonConverter (typeof (UnixDateTimeConverter))]
20 | public DateTime? Created { get; set; }
21 |
22 | [JsonProperty ("currency")]
23 | public string Currency { get; set; }
24 |
25 | [JsonProperty ("amount")]
26 | public int Amount;
27 |
28 | [JsonProperty ("livemode")]
29 | public bool LiveMode { get; set; }
30 |
31 | [JsonProperty ("reason")]
32 | public StripeDisputeReason Reason { get; set; }
33 |
34 | [JsonProperty ("evidence_due_by")]
35 | [JsonConverter (typeof (UnixDateTimeConverter))]
36 | public DateTime? EvidenceDueBy { get; set; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeDisputeReason.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Newtonsoft.Json;
6 |
7 | namespace Xamarin.Payments.Stripe {
8 | /* duplicate, fraudulent, subscription_canceled, product_unacceptable, product_not_received, unrecognized, credit_not_processed, general */
9 | [JsonConverter (typeof (StripeEnumConverter))]
10 | public enum StripeDisputeReason {
11 | Duplicate,
12 | Fraudulent,
13 | SubscriptionCanceled,
14 | ProductUnacceptable,
15 | ProductNotReceived,
16 | Unrecognized,
17 | CreditNotProcessed,
18 | General
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeDisputeStatus.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Newtonsoft.Json;
6 |
7 | namespace Xamarin.Payments.Stripe {
8 | /* won, lost, needs_response, under_review */
9 | [JsonConverter (typeof (StripeEnumConverter))]
10 | public enum StripeDisputeStatus {
11 | Won,
12 | Lost,
13 | NeedsResponse,
14 | UnderReview
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeEnumConverter.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Text.RegularExpressions;
22 | using Newtonsoft.Json;
23 | using Newtonsoft.Json.Converters;
24 |
25 | namespace Xamarin.Payments.Stripe {
26 | public class StripeEnumConverter : JsonConverter where T : struct, IConvertible {
27 | Dictionary values;
28 | public StripeEnumConverter ()
29 | {
30 | values = new Dictionary ();
31 | if (!typeof (T).IsEnum)
32 | throw new InvalidCastException ("Specified type T must be an enum");
33 | }
34 |
35 | public override bool CanConvert (Type objectType)
36 | {
37 | return objectType == typeof (T);
38 | }
39 |
40 | public override object ReadJson (JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
41 | {
42 | if (reader.Value == null)
43 | return null;
44 |
45 | var name = reader.Value as string;
46 | name = name.Replace ("_", "");
47 |
48 | return Enum.Parse (typeof (T), name, true);
49 | }
50 |
51 | public override void WriteJson (JsonWriter writer, object value, JsonSerializer serializer)
52 | {
53 | string key = value.ToString ();
54 | string result;
55 |
56 | if (!values.TryGetValue (key, out result)) {
57 | result = Regex.Replace (key, @"(? (json);
37 | result.StatusCode = code;
38 | return result;
39 | }
40 |
41 | public override string Message {
42 | get {
43 | return StripeError.Message;
44 | }
45 | }
46 |
47 | [JsonProperty (PropertyName="error")]
48 | public StripeError StripeError { get; internal set; }
49 |
50 | public HttpStatusCode StatusCode { get; internal set; }
51 | }
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeFeeDetail.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Xamarin, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | using System;
17 | using System.Collections.Generic;
18 | using System.Linq;
19 | using System.Text;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeFeeDetail {
25 | [JsonProperty (PropertyName = "type")]
26 | string Type { get; set; }
27 | [JsonProperty (PropertyName = "currency")]
28 | string Currency { get; set; }
29 | [JsonProperty (PropertyName = "application")]
30 | string Application { get; set; }
31 | [JsonProperty (PropertyName = "description")]
32 | string Description { get; set; }
33 | [JsonProperty (PropertyName = "amount")]
34 | public int Amount { get; set; }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeInvoice.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Collections.Generic;
21 | using Newtonsoft.Json;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | [JsonObject (MemberSerialization.OptIn)]
25 | public class StripeInvoice : StripeId, IEnumerable {
26 | [JsonProperty ("subtotal")]
27 | public int Subtotal { get; set; }
28 |
29 | [JsonProperty (PropertyName = "total")]
30 | public int Total { get; set; }
31 |
32 | [JsonProperty (PropertyName = "lines")]
33 | #if NEW_INVOICES
34 | public StripeCollection LineItems { get; set; }
35 | #else
36 | public StripeInvoiceLineItems LineItems { get; set; }
37 | #endif
38 |
39 | [JsonProperty ("attempted")]
40 | public bool Attempted { get; set; }
41 |
42 | [JsonProperty ("attempt_count")]
43 | public int AttemptCount { get; set; }
44 |
45 | [JsonProperty ("closed")]
46 | public bool Closed { get; set; }
47 |
48 | [JsonProperty ("customer")]
49 | public string CustomerID { get; set; }
50 |
51 | [JsonProperty ("date")]
52 | [JsonConverter (typeof (UnixDateTimeConverter))]
53 | public DateTime Date { get; set; }
54 |
55 | [JsonProperty ("paid")]
56 | public bool Paid { get; set; }
57 |
58 | [JsonProperty ("period_start")]
59 | [JsonConverter (typeof (UnixDateTimeConverter))]
60 | public DateTime Start { get; set; }
61 |
62 | [JsonProperty ("period_end")]
63 | [JsonConverter (typeof (UnixDateTimeConverter))]
64 | public DateTime End { get; set; }
65 |
66 | [JsonProperty ("starting_balance")]
67 | public int StartingBalance { get; set; }
68 |
69 | [JsonProperty ("ending_balance")]
70 | public int? EndingBalance { get; set; }
71 |
72 | [JsonProperty ("next_payment_attempt")]
73 | [JsonConverter (typeof (UnixDateTimeConverter))]
74 | public DateTime? NextPaymentAttempt { get; set; }
75 |
76 | #region IEnumerable[StripeInvoiceLineItem] implementation
77 | public IEnumerator GetEnumerator ()
78 | {
79 | return LineItems.GetEnumerator ();
80 | }
81 | #endregion
82 |
83 | #region IEnumerable implementation
84 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
85 | {
86 | return GetEnumerator ();
87 | }
88 | #endregion
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeInvoiceItem.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeInvoiceItem : StripeId {
25 | [JsonProperty (PropertyName = "customer")]
26 | public string CustomerID { get; set; }
27 |
28 | [JsonProperty (PropertyName = "currency")]
29 | public string Currency { get; set; }
30 |
31 | [JsonProperty (PropertyName = "livemode")]
32 | public bool LiveMode { get; set; }
33 |
34 | [JsonProperty (PropertyName = "date")]
35 | [JsonConverter (typeof (UnixDateTimeConverter))]
36 | public DateTime Date { get; set; }
37 |
38 | [JsonProperty (PropertyName = "description")]
39 | public string Description { get; set; }
40 |
41 | [JsonProperty (PropertyName = "deleted")]
42 | public bool? Deleted { get; set; }
43 |
44 | [JsonProperty (PropertyName = "invoice")]
45 | public string InvoiceID { get; set; }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeInvoiceItemInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Text;
21 | using System.Web;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | public class StripeInvoiceItemInfo : IUrlEncoderInfo {
25 | public string CustomerID { get; set; }
26 |
27 | public string InvoiceID { get; set; }
28 |
29 | public int Amount { get; set; }
30 |
31 | public string Currency { get; set; }
32 |
33 | public string Description { get; set; }
34 |
35 | #region IUrlEncoderInfo implementation
36 | public virtual void UrlEncode (StringBuilder sb)
37 | {
38 | sb.AppendFormat ("customer={0}&amount={1}¤cy={2}&",
39 | HttpUtility.UrlEncode (CustomerID), Amount, HttpUtility.UrlEncode (Currency ?? "usd"));
40 | if (!string.IsNullOrEmpty (Description))
41 | sb.AppendFormat ("description={0}&", HttpUtility.UrlEncode (Description));
42 | if (!string.IsNullOrEmpty (InvoiceID))
43 | sb.AppendFormat ("invoice={0}&", HttpUtility.UrlEncode (InvoiceID));
44 | }
45 | #endregion
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeInvoiceLineItems.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using Newtonsoft.Json;
23 |
24 | namespace Xamarin.Payments.Stripe {
25 | [JsonObject (MemberSerialization.OptIn)]
26 | public class StripeInvoiceLineItems : IEnumerable {
27 | [JsonProperty (PropertyName = "invoiceitems")]
28 | public List InvoiceItems { get; set; }
29 |
30 | [JsonProperty (PropertyName = "prorations")]
31 | public List Prorations { get; set; }
32 |
33 | [JsonProperty (PropertyName = "subscriptions")]
34 | public List Subscriptions { get; set; }
35 |
36 | #region IEnumerable[StripeLineItem] implementation
37 | public IEnumerator GetEnumerator ()
38 | {
39 | return ((IEnumerable)InvoiceItems).Concat (Prorations).Concat (Subscriptions).GetEnumerator();
40 | }
41 | #endregion
42 |
43 | #region IEnumerable implementation
44 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
45 | {
46 | return GetEnumerator();
47 | }
48 | #endregion
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeLineItem.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeLineItem : StripeId {
25 | [JsonProperty ("livemode")]
26 | public bool LiveMode { get; set; }
27 | [JsonProperty ("type")]
28 | public string Type { get; set; }
29 | [JsonProperty ("amount")]
30 | public int Amount { get; set; }
31 | [JsonProperty ("period")]
32 | public StripePeriod Period { get; set; }
33 | [JsonProperty ("proration")]
34 | public bool Proration { get; set; }
35 | [JsonProperty ("quantity")]
36 | public int? Quantity { get; set; }
37 | [JsonProperty ("description")]
38 | public string Description { get; set; }
39 | [JsonProperty ("currency")]
40 | public string Currency { get; set; }
41 | [JsonProperty ("plan")]
42 | public StripePlan Plan { get; set; }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeObject.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 | using Newtonsoft.Json.Converters;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | public class StripeObject {
25 | [JsonProperty (PropertyName = "object")]
26 | public StripeObjectType Object { get; set; }
27 | }
28 |
29 | public class StripeId : StripeObject {
30 | [JsonProperty (PropertyName = "id")]
31 | public string ID { get; set; }
32 | }
33 |
34 | [JsonConverter (typeof (StripeEnumConverter))]
35 | public enum StripeObjectType {
36 | Unknown,
37 | Account,
38 | Balance,
39 | BalanceTransaction,
40 | Card,
41 | Charge,
42 | Coupon,
43 | Customer,
44 | Discount,
45 | Dispute,
46 | Event,
47 | InvoiceItem,
48 | Invoice,
49 | LineItem,
50 | Plan,
51 | Subscription,
52 | Token,
53 | Transfer,
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeObjectConverter.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Xamarin, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | using System;
17 | using System.Collections.Generic;
18 | using System.Linq;
19 | using System.Text;
20 | using Newtonsoft.Json.Linq;
21 | using Newtonsoft.Json;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | public class StripeObjectConverter : JsonConverter {
25 | public override bool CanWrite { get { return false; } }
26 |
27 | public override bool CanConvert (Type objectType)
28 | {
29 | return typeof (StripeObject).IsAssignableFrom (objectType);
30 | }
31 |
32 | StripeObject FindType (JObject jobj)
33 | {
34 | var type = (string) jobj.Property ("object");
35 | switch (type) {
36 | case "account":
37 | return new StripeAccount ();
38 | case "balance":
39 | return new StripeBalance ();
40 | case "balance_transaction":
41 | return new StripeBalanceTransaction ();
42 | case "charge":
43 | return new StripeCharge ();
44 | case "event":
45 | return new StripeEvent ();
46 | case "discount":
47 | return new StripeDiscount ();
48 | case "dispute":
49 | return new StripeDispute ();
50 | case "coupon":
51 | return new StripeCoupon ();
52 | case "customer":
53 | return new StripeCustomer ();
54 | case "line_item":
55 | return new StripeLineItem ();
56 | case "plan":
57 | return new StripePlan ();
58 | case "token":
59 | return new StripeCreditCardToken ();
60 | case "subscription":
61 | return new StripeSubscription ();
62 | case "invoiceitem":
63 | return new StripeInvoiceItem ();
64 | case "invoice":
65 | return new StripeInvoice ();
66 | case "transfer":
67 | return new StripeTransfer ();
68 | }
69 | return new StripeObject ();
70 | }
71 |
72 | public override object ReadJson (JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
73 | {
74 | var jobj = JObject.Load (reader);
75 |
76 | var target = FindType (jobj);
77 |
78 | serializer.Populate (jobj.CreateReader (), target);
79 |
80 | return target;
81 | }
82 |
83 | public override void WriteJson (JsonWriter writer, object value, JsonSerializer serializer)
84 | {
85 | var obj = JObject.FromObject (value);
86 | obj.WriteTo (writer);
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/XamarinStripe/StripePayment.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 - 2012 Xamarin, Inc., 2011 - 2012 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | * Joe Dluzen (jdluzen@gmail.com)
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | using System;
21 | using System.Collections.Generic;
22 | using System.Globalization;
23 | using System.IO;
24 | using System.Net;
25 | using System.Text;
26 | using System.Web;
27 |
28 | using Newtonsoft.Json;
29 |
30 | namespace Xamarin.Payments.Stripe {
31 | public class StripePayment {
32 | static readonly string api_endpoint = "https://api.stripe.com/v1";
33 | static readonly string subscription_path = "{0}/customers/{1}/subscription";
34 | static readonly string user_agent = "Stripe .NET v1";
35 | static readonly Encoding encoding = Encoding.UTF8;
36 | ICredentials credential;
37 |
38 | public StripePayment (string api_key)
39 | {
40 | credential = new NetworkCredential (api_key, "");
41 | TimeoutSeconds = 80;
42 | }
43 | #region Shared
44 | protected virtual WebRequest SetupRequest (string method, string url)
45 | {
46 | WebRequest req = (WebRequest) WebRequest.Create (url);
47 | req.Method = method;
48 | if (req is HttpWebRequest) {
49 | ((HttpWebRequest) req).UserAgent = user_agent;
50 | }
51 | req.Credentials = credential;
52 | req.PreAuthenticate = true;
53 | req.Timeout = TimeoutSeconds * 1000;
54 | if (method == "POST")
55 | req.ContentType = "application/x-www-form-urlencoded";
56 | return req;
57 | }
58 |
59 | static string GetResponseAsString (WebResponse response)
60 | {
61 | using (StreamReader sr = new StreamReader (response.GetResponseStream (), encoding)) {
62 | return sr.ReadToEnd ();
63 | }
64 | }
65 |
66 | protected virtual T DoRequest (string endpoint, string method = "GET", string body = null)
67 | {
68 | var json = DoRequest (endpoint, method, body);
69 | return JsonConvert.DeserializeObject (json);
70 | }
71 |
72 | protected virtual string DoRequest (string endpoint)
73 | {
74 | return DoRequest (endpoint, "GET", null);
75 | }
76 |
77 | protected virtual string DoRequest (string endpoint, string method, string body)
78 | {
79 | string result = null;
80 | WebRequest req = SetupRequest (method, endpoint);
81 | if (body != null) {
82 | byte [] bytes = encoding.GetBytes (body.ToString ());
83 | req.ContentLength = bytes.Length;
84 | using (Stream st = req.GetRequestStream ()) {
85 | st.Write (bytes, 0, bytes.Length);
86 | }
87 | }
88 |
89 | try {
90 | using (WebResponse resp = (WebResponse) req.GetResponse ()) {
91 | result = GetResponseAsString (resp);
92 | }
93 | } catch (WebException wexc) {
94 | if (wexc.Response != null) {
95 | string json_error = GetResponseAsString (wexc.Response);
96 | HttpStatusCode status_code = HttpStatusCode.BadRequest;
97 | HttpWebResponse resp = wexc.Response as HttpWebResponse;
98 | if (resp != null)
99 | status_code = resp.StatusCode;
100 |
101 | if ((int) status_code <= 500)
102 | throw StripeException.GetFromJSON (status_code, json_error);
103 | }
104 | throw;
105 | }
106 | return result;
107 | }
108 |
109 | protected virtual StringBuilder UrlEncode (IUrlEncoderInfo infoInstance)
110 | {
111 | StringBuilder str = new StringBuilder ();
112 | infoInstance.UrlEncode (str);
113 | if (str.Length > 0)
114 | str.Length--;
115 | return str;
116 | }
117 |
118 | #endregion
119 | #region Charge
120 | public StripeCharge Charge (int amount_cents, string currency, string customer, string description)
121 | {
122 | if (String.IsNullOrEmpty (customer))
123 | throw new ArgumentNullException ("customer");
124 |
125 | return Charge (amount_cents, currency, customer, null, description);
126 | }
127 |
128 | public StripeCharge Charge (int amount_cents, string currency, StripeCreditCardInfo card, string description)
129 | {
130 | if (card == null)
131 | throw new ArgumentNullException ("card");
132 |
133 | return Charge (amount_cents, currency, null, card, description);
134 | }
135 |
136 | StripeCharge Charge (int amount_cents, string currency, string customer, StripeCreditCardInfo card, string description)
137 | {
138 | if (amount_cents < 0)
139 | throw new ArgumentOutOfRangeException ("amount_cents", "Must be greater than or equal 0");
140 | if (String.IsNullOrEmpty (currency))
141 | throw new ArgumentNullException ("currency");
142 | if (currency != "usd")
143 | throw new ArgumentException ("The only supported currency is 'usd'");
144 |
145 | StringBuilder str = new StringBuilder ();
146 | str.AppendFormat ("amount={0}&", amount_cents);
147 | str.AppendFormat ("currency={0}&", currency);
148 | if (!String.IsNullOrEmpty (description)) {
149 | str.AppendFormat ("description={0}&", HttpUtility.UrlEncode (description));
150 | }
151 |
152 | if (card != null) {
153 | card.UrlEncode (str);
154 | } else {
155 | // customer is non-empty
156 | str.AppendFormat ("customer={0}&", HttpUtility.UrlEncode (customer));
157 | }
158 | str.Length--;
159 | string ep = String.Format ("{0}/charges", api_endpoint);
160 | return DoRequest (ep, "POST", str.ToString ());
161 | }
162 |
163 | public StripeCharge GetCharge (string charge_id)
164 | {
165 | if (String.IsNullOrEmpty (charge_id))
166 | throw new ArgumentNullException ("charge_id");
167 |
168 | string ep = String.Format ("{0}/charges/{1}", api_endpoint, HttpUtility.UrlEncode (charge_id));
169 | return DoRequest (ep);
170 | }
171 |
172 | public StripeCollection GetCharges (int offset = 0, int count = 10, string customer_id = null, StripeDateTimeInfo created = null)
173 | {
174 | if (offset < 0)
175 | throw new ArgumentOutOfRangeException ("offset");
176 | if (count < 1 || count > 100)
177 | throw new ArgumentOutOfRangeException ("count");
178 |
179 | StringBuilder str = new StringBuilder ();
180 | str.AppendFormat ("offset={0}&", offset);
181 | str.AppendFormat ("count={0}&", count);
182 | if (!String.IsNullOrEmpty (customer_id))
183 | str.AppendFormat ("customer={0}&", HttpUtility.UrlEncode (customer_id));
184 |
185 | if (created != null) {
186 | created.Prefix = "created";
187 | created.UrlEncode (str);
188 | }
189 |
190 | str.Length--;
191 | string ep = String.Format ("{0}/charges?{1}", api_endpoint, str);
192 | return DoRequest> (ep);
193 | }
194 |
195 | public StripeDispute UpdateDispute (string charge_id, string evidence)
196 | {
197 | if (String.IsNullOrEmpty (charge_id))
198 | throw new ArgumentNullException ("charge_id");
199 |
200 | if (String.IsNullOrEmpty (evidence))
201 | throw new ArgumentNullException ("evidence");
202 |
203 | string ep = String.Format ("{0}/charges/{1}/dispute", api_endpoint, HttpUtility.UrlEncode (charge_id));
204 | return DoRequest (ep, "POST", String.Format ("evidence={0}", HttpUtility.UrlEncode (evidence)));
205 | }
206 |
207 | #endregion
208 | #region Refund
209 | public StripeCharge Refund (string charge_id)
210 | {
211 | if (String.IsNullOrEmpty (charge_id))
212 | throw new ArgumentNullException ("charge_id");
213 |
214 | string ep = String.Format ("{0}/charges/{1}/refund", api_endpoint, HttpUtility.UrlEncode (charge_id));
215 | return DoRequest (ep, "POST", null);
216 | }
217 |
218 | public StripeCharge Refund (string charge_id, int amount)
219 | {
220 | if (String.IsNullOrEmpty (charge_id))
221 | throw new ArgumentNullException ("charge_id");
222 | if (amount <= 0)
223 | throw new ArgumentException ("Amount must be greater than zero.", "amount");
224 |
225 | string ep = String.Format ("{0}/charges/{1}/refund?amount={2}", api_endpoint, HttpUtility.UrlEncode (charge_id), amount);
226 | return DoRequest (ep, "POST", null);
227 | }
228 | #endregion
229 | #region Customer
230 | StripeCustomer CreateOrUpdateCustomer (string id, StripeCustomerInfo customer)
231 | {
232 | StringBuilder str = UrlEncode (customer);
233 |
234 | string format = "{0}/customers"; // Create
235 | if (id != null)
236 | format = "{0}/customers/{1}"; // Update
237 | string ep = String.Format (format, api_endpoint, HttpUtility.UrlEncode (id));
238 | return DoRequest (ep, "POST", str.ToString ());
239 | }
240 |
241 | public StripeCustomer CreateCustomer (StripeCustomerInfo customer)
242 | {
243 | if (customer == null)
244 | throw new ArgumentNullException ("customer");
245 |
246 | return CreateOrUpdateCustomer (null, customer);
247 | }
248 |
249 | public StripeCustomer UpdateCustomer (string id, StripeCustomerInfo customer)
250 | {
251 | if (String.IsNullOrEmpty (id))
252 | throw new ArgumentNullException ("id");
253 | if (customer == null)
254 | throw new ArgumentNullException ("customer");
255 |
256 | return CreateOrUpdateCustomer (id, customer);
257 | }
258 |
259 | public StripeCustomer GetCustomer (string customer_id)
260 | {
261 | if (String.IsNullOrEmpty (customer_id))
262 | throw new ArgumentNullException ("customer_id");
263 |
264 | string ep = String.Format ("{0}/customers/{1}", api_endpoint, HttpUtility.UrlEncode (customer_id));
265 | return DoRequest (ep);
266 | }
267 |
268 | public StripeCollection GetCustomers (int offset = 0, int count = 10)
269 | {
270 | if (offset < 0)
271 | throw new ArgumentOutOfRangeException ("offset");
272 | if (count < 1 || count > 100)
273 | throw new ArgumentOutOfRangeException ("count");
274 |
275 | string str = String.Format ("offset={0}&count={1}", offset, count);
276 | string ep = String.Format ("{0}/customers?{1}", api_endpoint, str);
277 | return DoRequest> (ep);
278 | }
279 |
280 | public StripeCustomer DeleteCustomer (string customer_id)
281 | {
282 | if (String.IsNullOrEmpty (customer_id))
283 | throw new ArgumentNullException ("customer_id");
284 |
285 | string ep = String.Format ("{0}/customers/{1}", api_endpoint, HttpUtility.UrlEncode (customer_id));
286 | return DoRequest (ep, "DELETE", null);
287 | }
288 | #endregion
289 | #region Events
290 | public StripeEvent GetEvent (string eventId)
291 | {
292 | string ep = string.Format ("{0}/events/{1}", api_endpoint, HttpUtility.UrlEncode (eventId));
293 | return DoRequest (ep);
294 | }
295 |
296 | public StripeCollection GetEvents (int offset = 0, int count = 10, string type = null, StripeDateTimeInfo created = null)
297 | {
298 | if (offset < 0)
299 | throw new ArgumentOutOfRangeException ("offset");
300 | if (count < 1 || count > 100)
301 | throw new ArgumentOutOfRangeException ("count");
302 |
303 | StringBuilder str = new StringBuilder ();
304 | str.AppendFormat ("offset={0}&count={1}&", offset, count);
305 |
306 | if (!string.IsNullOrEmpty (type))
307 | str.AppendFormat ("type={0}&", HttpUtility.UrlEncode (type));
308 |
309 | if (created != null) {
310 | created.Prefix = "created";
311 | created.UrlEncode (str);
312 | }
313 |
314 | str.Length--;
315 |
316 | string ep = String.Format ("{0}/events?{1}", api_endpoint, str);
317 | return DoRequest> (ep);
318 | }
319 |
320 | #endregion
321 |
322 | #region Tokens
323 | public StripeCreditCardToken CreateToken (StripeCreditCardInfo card)
324 | {
325 | if (card == null)
326 | throw new ArgumentNullException ("card");
327 | StringBuilder str = UrlEncode (card);
328 |
329 | string ep = string.Format ("{0}/tokens", api_endpoint);
330 | return DoRequest (ep, "POST", str.ToString ());
331 | }
332 |
333 | public StripeCreditCardToken GetToken (string tokenId)
334 | {
335 | if (string.IsNullOrEmpty (tokenId))
336 | throw new ArgumentNullException (tokenId);
337 |
338 | string ep = string.Format ("{0}/tokens/{1}", api_endpoint, HttpUtility.UrlEncode (tokenId));
339 | return DoRequest (ep);
340 | }
341 | #endregion
342 | #region Plans
343 | public StripePlan CreatePlan (StripePlanInfo plan)
344 | {
345 | if (plan == null)
346 | throw new ArgumentNullException ("plan");
347 | StringBuilder str = UrlEncode (plan);
348 |
349 | string ep = string.Format ("{0}/plans", api_endpoint);
350 | return DoRequest (ep, "POST", str.ToString ());
351 | }
352 |
353 | public StripePlan GetPlan (string planId)
354 | {
355 | if (string.IsNullOrEmpty (planId))
356 | throw new ArgumentNullException ("id");
357 |
358 | string ep = string.Format ("{0}/plans/{1}", api_endpoint, HttpUtility.UrlEncode (planId));
359 | return DoRequest (ep);
360 | }
361 |
362 | public StripePlan DeletePlan (string planId)
363 | {
364 | if (string.IsNullOrEmpty (planId))
365 | throw new ArgumentNullException ("id");
366 |
367 | string ep = string.Format ("{0}/plans/{1}", api_endpoint, HttpUtility.UrlEncode (planId));
368 | return DoRequest (ep, "DELETE", null);
369 | }
370 |
371 | public StripeCollection GetPlans (int offset = 0, int count = 10)
372 | {
373 | string str = string.Format ("count={0}&offset={1}", count, offset);
374 | string ep = string.Format ("{0}/plans?{1}", api_endpoint, str);
375 | return DoRequest> (ep);
376 | }
377 | #endregion
378 | #region Subscriptions
379 | public StripeSubscription Subscribe (string customerId, StripeSubscriptionInfo subscription)
380 | {
381 | StringBuilder str = UrlEncode (subscription);
382 | string ep = string.Format (subscription_path, api_endpoint, HttpUtility.UrlEncode (customerId));
383 | return DoRequest (ep, "POST", str.ToString ());
384 | }
385 |
386 | public StripeSubscription GetSubscription (string customerId)
387 | {
388 | if (string.IsNullOrEmpty (customerId))
389 | throw new ArgumentNullException ("customerId");
390 | string ep = string.Format (subscription_path, api_endpoint, HttpUtility.UrlEncode (customerId));
391 | return DoRequest(ep);
392 | }
393 |
394 | public StripeSubscription Unsubscribe (string customerId, bool atPeriodEnd)
395 | {
396 | string ep = string.Format (subscription_path + "?at_period_end={2}", api_endpoint, HttpUtility.UrlEncode (customerId), atPeriodEnd.ToString (CultureInfo.InvariantCulture).ToLowerInvariant ());
397 | return DoRequest (ep, "DELETE", null);
398 | }
399 | #endregion
400 | #region Invoice items
401 | public StripeInvoiceItem CreateInvoiceItem (StripeInvoiceItemInfo item)
402 | {
403 | if (string.IsNullOrEmpty (item.CustomerID))
404 | throw new ArgumentNullException ("item.CustomerID");
405 | StringBuilder str = UrlEncode (item);
406 | string ep = string.Format ("{0}/invoiceitems", api_endpoint);
407 | return DoRequest (ep, "POST", str.ToString ());
408 | }
409 |
410 | public StripeInvoiceItem GetInvoiceItem (string invoiceItemId)
411 | {
412 | if (string.IsNullOrEmpty (invoiceItemId))
413 | throw new ArgumentNullException ("invoiceItemId");
414 | string ep = string.Format ("{0}/invoiceitems/{1}", api_endpoint, invoiceItemId);
415 | return DoRequest (ep);
416 | }
417 |
418 | public StripeInvoiceItem UpdateInvoiceItem (string invoiceItemId, StripeInvoiceItemInfo item)
419 | {
420 | StringBuilder str = UrlEncode (item);
421 | string ep = string.Format ("{0}/invoiceitems/{1}", api_endpoint, invoiceItemId);
422 | return DoRequest (ep, "POST", str.ToString ());
423 | }
424 |
425 | public StripeInvoiceItem DeleteInvoiceItem (string invoiceItemId)
426 | {
427 | string ep = string.Format ("{0}/invoiceitems/{1}", api_endpoint, invoiceItemId);
428 | return DoRequest (ep, "DELETE", null);
429 | }
430 |
431 | public StripeCollection GetInvoiceItems (int offset = 0, int count = 10, string customerId = null, StripeDateTimeInfo created = null)
432 | {
433 | if (offset < 0)
434 | throw new ArgumentOutOfRangeException ("offset");
435 | if (count < 1 || count > 100)
436 | throw new ArgumentOutOfRangeException ("count");
437 |
438 | StringBuilder str = new StringBuilder ();
439 | str.AppendFormat ("offset={0}&", offset);
440 | str.AppendFormat ("count={0}&", count);
441 | if (!string.IsNullOrEmpty (customerId))
442 | str.AppendFormat ("customer={0}&", HttpUtility.UrlEncode (customerId));
443 |
444 | if (created != null) {
445 | created.Prefix = "created";
446 | created.UrlEncode (str);
447 | }
448 |
449 | str.Length--;
450 | string ep = String.Format ("{0}/invoiceitems?{1}", api_endpoint, str);
451 | return DoRequest> (ep);
452 | }
453 |
454 | #endregion
455 | #region Invoices
456 | public StripeInvoice GetInvoice (string invoiceId)
457 | {
458 | if (string.IsNullOrEmpty (invoiceId))
459 | throw new ArgumentNullException ("invoiceId");
460 | string ep = string.Format ("{0}/invoices/{1}", api_endpoint, invoiceId);
461 | return DoRequest (ep);
462 | }
463 |
464 | public StripeCollection GetInvoices (int offset = 0, int count = 10, string customerId = null)
465 | {
466 | if (offset < 0)
467 | throw new ArgumentOutOfRangeException ("offset");
468 | if (count < 1 || count > 100)
469 | throw new ArgumentOutOfRangeException ("count");
470 |
471 | StringBuilder str = new StringBuilder ();
472 | str.AppendFormat ("offset={0}&", offset);
473 | str.AppendFormat ("count={0}&", count);
474 | if (!string.IsNullOrEmpty (customerId))
475 | str.AppendFormat ("customer={0}&", HttpUtility.UrlEncode (customerId));
476 |
477 | str.Length--;
478 | string ep = String.Format ("{0}/invoices?{1}", api_endpoint, str);
479 | return DoRequest>(ep);
480 | }
481 |
482 | public StripeInvoice GetUpcomingInvoice (string customerId)
483 | {
484 | if (string.IsNullOrEmpty (customerId))
485 | throw new ArgumentOutOfRangeException ("customerId");
486 | string ep = String.Format ("{0}/invoices/upcoming?customer={1}", api_endpoint, customerId);
487 | return DoRequest (ep);
488 | }
489 |
490 | public StripeCollection GetInvoiceLines (string invoiceId)
491 | {
492 | if (string.IsNullOrEmpty (invoiceId))
493 | throw new ArgumentNullException ("invoiceId");
494 | string ep = string.Format ("{0}/invoices/{1}/lines", api_endpoint, invoiceId);
495 | return DoRequest> (ep);
496 | }
497 | #endregion
498 | #region Coupons
499 | public StripeCoupon CreateCoupon (StripeCouponInfo coupon)
500 | {
501 | if (coupon == null)
502 | throw new ArgumentNullException ("coupon");
503 | if (coupon.PercentOff < 1 || coupon.PercentOff > 100)
504 | throw new ArgumentOutOfRangeException ("coupon.PercentOff");
505 | if (coupon.Duration == StripeCouponDuration.Repeating && coupon.MonthsForDuration < 1)
506 | throw new ArgumentException ("MonthsForDuration must be greater than 1 when Duration = Repeating");
507 | StringBuilder str = UrlEncode (coupon);
508 | string ep = string.Format ("{0}/coupons", api_endpoint);
509 | return DoRequest (ep, "POST", str.ToString ());
510 | }
511 |
512 | public StripeCoupon GetCoupon (string couponId)
513 | {
514 | if (string.IsNullOrEmpty (couponId))
515 | throw new ArgumentNullException ("couponId");
516 | string ep = string.Format ("{0}/coupons/{1}", api_endpoint, couponId);
517 | return DoRequest (ep);
518 | }
519 |
520 | public StripeCoupon DeleteCoupon (string couponId)
521 | {
522 | if (string.IsNullOrEmpty (couponId))
523 | throw new ArgumentNullException ("couponId");
524 | string ep = string.Format ("{0}/coupons/{1}", api_endpoint, couponId);
525 | return DoRequest (ep, "DELETE", null);
526 | }
527 |
528 | public StripeCollection GetCoupons (int offset = 0, int count = 10)
529 | {
530 | if (offset < 0)
531 | throw new ArgumentOutOfRangeException ("offset");
532 | if (count > 100)
533 | throw new ArgumentOutOfRangeException ("count");
534 | string ep = string.Format ("{0}/coupons?offset={0}&count={1}", api_endpoint, offset, count);
535 | return DoRequest> (ep);
536 | }
537 | #endregion
538 | #region Cards
539 | public StripeCard CreateCard (string customer_id, StripeCreditCardInfo card)
540 | {
541 | if (string.IsNullOrWhiteSpace (customer_id)) {
542 | throw new ArgumentNullException ("customer_id");
543 | }
544 |
545 | StringBuilder str = UrlEncode (card);
546 | string ep = String.Format ("{0}/customers/{1}/cards", api_endpoint, HttpUtility.UrlEncode (customer_id));
547 | return DoRequest (ep, "POST", str.ToString ());
548 | }
549 |
550 | public StripeCard DeleteCard (string customer_id, string card_id)
551 | {
552 | if (string.IsNullOrWhiteSpace (customer_id)) {
553 | throw new ArgumentNullException ("customer_id");
554 | }
555 | if (string.IsNullOrWhiteSpace (card_id)) {
556 | throw new ArgumentNullException ("card_id");
557 | }
558 |
559 | string ep = string.Format ("{0}/customers/{1}/cards/{2}", api_endpoint, HttpUtility.UrlEncode (customer_id),
560 | HttpUtility.UrlEncode (card_id));
561 | return DoRequest (ep, "DELETE", null);
562 | }
563 |
564 | public StripeCard UpdateCard (string customer_id, StripeUpdateCreditCardInfo card)
565 | {
566 | if (string.IsNullOrWhiteSpace (customer_id))
567 | throw new ArgumentNullException ("customer_id");
568 | if (null == card)
569 | throw new ArgumentNullException ("card");
570 | if (string.IsNullOrWhiteSpace (card.ID))
571 | throw new ArgumentNullException ("card.ID");
572 |
573 | StringBuilder str = UrlEncode (card);
574 | string format = "{0}/customers/{1}/cards/{2}";
575 | string ep = string.Format (format, api_endpoint, HttpUtility.UrlEncode (customer_id),
576 | HttpUtility.UrlEncode (card.ID));
577 | return DoRequest (ep, "POST", str.ToString ());
578 | }
579 | #endregion
580 | public int TimeoutSeconds { get; set; }
581 | }
582 | }
583 |
--------------------------------------------------------------------------------
/XamarinStripe/StripePeriod.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripePeriod {
25 | [JsonProperty (PropertyName = "start")]
26 | [JsonConverter (typeof(UnixDateTimeConverter))]
27 | public DateTime Start { get; set; }
28 |
29 | [JsonProperty (PropertyName = "end")]
30 | [JsonConverter (typeof(UnixDateTimeConverter))]
31 | public DateTime End { get; set; }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/XamarinStripe/StripePlan.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripePlan : StripeId {
25 | [JsonProperty (PropertyName = "livemode")]
26 | public bool LiveMode { get; set; }
27 |
28 | [JsonProperty (PropertyName = "amount")]
29 | public int Amount { get; set; }
30 |
31 | [JsonProperty (PropertyName = "currency")]
32 | public string Currency { get; set; }
33 |
34 | // deleted was deleted
35 | /*
36 | [JsonProperty(PropertyName = "deleted")]
37 | public bool? Deleted { get; set; }
38 | */
39 |
40 | [JsonProperty(PropertyName = "identifier")]
41 | public string Identifier { get; set; }
42 |
43 | [JsonProperty (PropertyName = "interval")]
44 | public StripePlanInterval Interval { get; set; }
45 |
46 | [JsonProperty (PropertyName = "name")]
47 | public string Name { get; set; }
48 |
49 | [JsonProperty (PropertyName = "trial_period_days")]
50 | public int? TrialPeriod { get; set; }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/XamarinStripe/StripePlanInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Text;
21 | using System.Web;
22 |
23 | namespace Xamarin.Payments.Stripe {
24 | public class StripePlanInfo : IUrlEncoderInfo {
25 | public string ID { get; set; }
26 |
27 | public int Amount { get; set; }
28 |
29 | public string Currency { get; set; }
30 |
31 | public StripePlanInterval Interval { get; set; }
32 |
33 | public int? IntervalCount { get; set; }
34 |
35 | public string Name { get; set; }
36 |
37 | public int? TrialPeriod { get; set; }
38 |
39 | #region IUrlEncoderInfo Members
40 |
41 | public virtual void UrlEncode (StringBuilder sb)
42 | {
43 | sb.AppendFormat ("id={0}&amount={1}¤cy={2}&interval={3}&name={4}&",
44 | HttpUtility.UrlEncode (ID), Amount, HttpUtility.UrlEncode (Currency ?? "usd"), HttpUtility.UrlEncode (Interval.ToString().ToLower ()), HttpUtility.UrlEncode (Name));
45 |
46 | if (IntervalCount.HasValue)
47 | sb.AppendFormat ("interval_count={0}&", IntervalCount.Value);
48 |
49 | if (TrialPeriod.HasValue)
50 | sb.AppendFormat ("trial_period_days={0}&", TrialPeriod.Value);
51 | }
52 |
53 | #endregion
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/XamarinStripe/StripePlanInterval.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonConverter (typeof (StripeEnumConverter))]
24 | public enum StripePlanInterval {
25 | Month,
26 | Year
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeSubscription.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011, 2012 Joe Dluzen, 2012 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeSubscription: StripeObject {
25 | [JsonProperty (PropertyName = "current_period_end")]
26 | [JsonConverter (typeof(UnixDateTimeConverter))]
27 | public DateTime? CurrentPeriodEnd { get; set; }
28 |
29 | [JsonProperty (PropertyName = "status")]
30 | [JsonConverter (typeof(StripeEnumConverter))]
31 | public StripeSubscriptionStatus Status { get; set; }
32 |
33 | [JsonProperty (PropertyName = "plan")]
34 | public StripePlan Plan { get; set; }
35 |
36 | [JsonProperty (PropertyName = "current_period_start")]
37 | [JsonConverter (typeof(UnixDateTimeConverter))]
38 | public DateTime? CurrentPeriodStart { get; set; }
39 |
40 | [JsonProperty (PropertyName = "start")]
41 | [JsonConverter (typeof(UnixDateTimeConverter))]
42 | public DateTime? Start { get; set; }
43 |
44 | [JsonProperty (PropertyName = "trial_start")]
45 | [JsonConverter (typeof(UnixDateTimeConverter))]
46 | public DateTime? TrialStart { get; set; }
47 |
48 | [JsonProperty (PropertyName = "cancel_at_period_end")]
49 | public bool? CancelAtPeriodEnd { get; set; }
50 |
51 | [JsonProperty (PropertyName = "trial_end")]
52 | [JsonConverter (typeof(UnixDateTimeConverter))]
53 | public DateTime? TrialEnd { get; set; }
54 |
55 | [JsonProperty (PropertyName = "canceled_at")]
56 | [JsonConverter (typeof(UnixDateTimeConverter))]
57 | public DateTime? CanceledAt { get; set; }
58 |
59 | [JsonProperty (PropertyName = "ended_at")]
60 | [JsonConverter (typeof(UnixDateTimeConverter))]
61 | public DateTime? EndedAt { get; set; }
62 |
63 | [JsonProperty (PropertyName = "customer")]
64 | public string CustomerID { get; set; }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeSubscriptionInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 | using System.Globalization;
21 | using System.Text;
22 | using System.Web;
23 |
24 | namespace Xamarin.Payments.Stripe {
25 | public class StripeSubscriptionInfo : IUrlEncoderInfo {
26 | public string Plan { get; set; }
27 |
28 | public string Coupon { get; set; }
29 |
30 | public bool? Prorate { get; set; }
31 |
32 | public DateTime? TrialEnd { get; set; }
33 |
34 | public StripeCreditCardInfo Card { get; set; }
35 |
36 | public virtual void UrlEncode (StringBuilder sb)
37 | {
38 | sb.AppendFormat ("plan={0}&", HttpUtility.UrlEncode (Plan));
39 | if (!string.IsNullOrEmpty (Coupon))
40 | sb.AppendFormat ("coupon={0}&", HttpUtility.UrlEncode (Coupon));
41 | if (Prorate != null && Prorate.HasValue)
42 | sb.AppendFormat ("prorate={0}&", Prorate.Value.ToString (CultureInfo.InvariantCulture).ToLowerInvariant ());
43 | if (TrialEnd != null)
44 | sb.AppendFormat ("trial_end={0}&", TrialEnd.Value.ToUnixEpoch ());
45 | if (Card != null)
46 | Card.UrlEncode(sb);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeSubscriptionStatus.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Joe Dluzen
3 | *
4 | * Author(s):
5 | * Joe Dluzen (jdluzen@gmail.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 |
21 | namespace Xamarin.Payments.Stripe {
22 | public enum StripeSubscriptionStatus {
23 | Unknown,
24 | Trialing,
25 | Active,
26 | PastDue,
27 | Canceled,
28 | Unpaid
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeTransfer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Xamarin, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | using System;
17 | using System.Collections.Generic;
18 | using System.Linq;
19 | using System.Text;
20 | using Newtonsoft.Json;
21 |
22 | namespace Xamarin.Payments.Stripe {
23 | [JsonObject (MemberSerialization.OptIn)]
24 | public class StripeTransfer : StripeId {
25 | [JsonProperty (PropertyName = "amount")]
26 | public int Amount { get; set; }
27 |
28 | [JsonProperty (PropertyName = "date")]
29 | [JsonConverter (typeof (UnixDateTimeConverter))]
30 | public DateTime Date { get; set; }
31 |
32 | [JsonProperty (PropertyName = "transactions")]
33 | public StripeCollection Transactions { get; set; }
34 |
35 | [JsonProperty (PropertyName = "other_transfers")]
36 | public List OtherTransfers { get; set; }
37 |
38 | [JsonProperty (PropertyName = "status")]
39 | public string Status { get; set; }
40 |
41 | [JsonProperty (PropertyName = "summary")]
42 | public TransferSummary Summary { get; set; }
43 |
44 | public class TransferSummary {
45 | [JsonProperty (PropertyName = "adjustment_count")]
46 | public int AdjustmentCount { get; set; }
47 |
48 | [JsonProperty (PropertyName = "adjustment_fee_details")]
49 | public List AdjustmentFeeDetails { get; set; }
50 |
51 | [JsonProperty (PropertyName = "adjustment_fees")]
52 | public int AdjustmentFees { get; set; }
53 |
54 | [JsonProperty (PropertyName = "adjustment_gross")]
55 | public int AdjustmentGross { get; set; }
56 |
57 | [JsonProperty (PropertyName = "charge_count")]
58 | public int ChargeCount { get; set; }
59 |
60 | [JsonProperty (PropertyName = "charge_fee_details")]
61 | public List ChargeFeeDetails { get; set; }
62 |
63 | [JsonProperty (PropertyName = "charge_fees")]
64 | public int ChargeFees { get; set; }
65 |
66 | [JsonProperty (PropertyName = "charge_gross")]
67 | public int ChargeGross { get; set; }
68 |
69 | [JsonProperty (PropertyName = "currency")]
70 | public string Currency { get; set; }
71 |
72 | [JsonProperty (PropertyName = "net")]
73 | public int Net { get; set; }
74 |
75 | [JsonProperty (PropertyName = "refund_count")]
76 | public int RefundCount { get; set; }
77 |
78 | [JsonProperty (PropertyName = "refund_fees")]
79 | public int RefundFees { get; set; }
80 |
81 | [JsonProperty (PropertyName = "refund_gross")]
82 | public int RefundGross { get; set; }
83 |
84 | [JsonProperty (PropertyName = "validation_count")]
85 | public int ValidationCount { get; set; }
86 |
87 | [JsonProperty (PropertyName = "validation_fees")]
88 | public int ValidationFees { get; set; }
89 | }
90 |
91 | [JsonProperty (PropertyName = "description")]
92 | public string Description { get; set; }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/XamarinStripe/StripeUpdateCreditCardInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Web;
4 |
5 | namespace Xamarin.Payments.Stripe
6 | {
7 | public class StripeUpdateCreditCardInfo : StripeId, IUrlEncoderInfo
8 | {
9 | // All fields optional when performing an update
10 | public int? ExpirationMonth { get; set; }
11 | public int? ExpirationYear { get; set; }
12 | public string FullName { get; set; }
13 | public string AddressLine1 { get; set; }
14 | public string AddressLine2 { get; set; }
15 | public string ZipCode { get; set; }
16 | public string StateOrProvince { get; set; }
17 | public string Country { get; set; }
18 | public string City { get; set; }
19 |
20 | public virtual void UrlEncode (StringBuilder sb)
21 | {
22 | if (ExpirationMonth.HasValue && (ExpirationMonth <= 0 || ExpirationMonth > 12))
23 | throw new ArgumentOutOfRangeException ("ExpirationMonth");
24 | if (ExpirationYear.HasValue && ExpirationYear <= 0)
25 | throw new ArgumentOutOfRangeException ("ExpirationYear");
26 |
27 | if (ExpirationMonth.HasValue)
28 | sb.AppendFormat ("exp_month={0}&", HttpUtility.UrlEncode (ExpirationMonth.Value.ToString ()));
29 | if (ExpirationYear.HasValue)
30 | sb.AppendFormat ("exp_year={0}&", HttpUtility.UrlEncode (ExpirationYear.Value.ToString ()));
31 | if (!String.IsNullOrEmpty (FullName))
32 | sb.AppendFormat ("name={0}&", HttpUtility.UrlEncode (FullName));
33 | if (!String.IsNullOrEmpty (AddressLine1))
34 | sb.AppendFormat ("address_line1={0}&", HttpUtility.UrlEncode (AddressLine1));
35 | if (!String.IsNullOrEmpty (AddressLine2))
36 | sb.AppendFormat ("address_line2={0}&", HttpUtility.UrlEncode (AddressLine2));
37 | if (!String.IsNullOrEmpty (ZipCode))
38 | sb.AppendFormat ("address_zip={0}&", HttpUtility.UrlEncode (ZipCode));
39 | if (!String.IsNullOrEmpty (StateOrProvince))
40 | sb.AppendFormat ("address_state={0}&", HttpUtility.UrlEncode (StateOrProvince));
41 | if (!String.IsNullOrEmpty (Country))
42 | sb.AppendFormat ("address_country={0}&", HttpUtility.UrlEncode (Country));
43 | if (!String.IsNullOrEmpty (City))
44 | sb.AppendFormat ("address_city={0}&", HttpUtility.UrlEncode (City));
45 |
46 | if (sb.Length == 0)
47 | throw new InvalidOperationException ("No card information provided");
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/XamarinStripe/UnixDateTimeConverter.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Xamarin, Inc.
3 | *
4 | * Author(s):
5 | * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | using System;
20 |
21 | using Newtonsoft.Json;
22 | using Newtonsoft.Json.Converters;
23 |
24 | namespace Xamarin.Payments.Stripe {
25 | public class UnixDateTimeConverter : DateTimeConverterBase {
26 | static bool IsNullable (Type type)
27 | {
28 | if (!type.IsValueType)
29 | return true; // ref-type
30 | if (Nullable.GetUnderlyingType (type) != null)
31 | return true; // Nullable
32 | return false; // value-type
33 | }
34 |
35 | public override object ReadJson (JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
36 | {
37 | bool nullable = IsNullable (objectType);
38 | Type t = (nullable) ? Nullable.GetUnderlyingType (objectType) : objectType;
39 | if (reader.TokenType == JsonToken.Null) {
40 | if (!nullable)
41 | throw new Exception (String.Format ("Cannot convert null value to {0}.", objectType));
42 | return null;
43 | }
44 |
45 | if (reader.TokenType != JsonToken.Integer)
46 | throw new Exception (String.Format ("Unexpected token parsing date. Expected Integer, got {0}.", reader.TokenType));
47 |
48 | return ((long) reader.Value).FromUnixEpoch ();
49 | }
50 |
51 | public override void WriteJson (JsonWriter writer, object value, JsonSerializer serializer)
52 | {
53 | if (!(value is DateTime))
54 | throw new Exception ("Invalid value");
55 |
56 | DateTime dt = (DateTime) value;
57 | writer.WriteValue (dt.ToUnixEpoch ());
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/XamarinStripe/XamarinStripe.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {218CF4C2-C457-43E4-9D1B-0880D10181FF}
9 | Library
10 | Properties
11 | Xamarin.Payments.Stripe
12 | XamarinStripe
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 | False
35 | ..\packages\Newtonsoft.Json.5.0.6\lib\net40\Newtonsoft.Json.dll
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
104 |
--------------------------------------------------------------------------------
/XamarinStripe/XamarinStripe.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Xamarin.Stripe
5 | $version$
6 | Xamarin Stripe client library
7 | Larry Ewing
8 | Larry Ewing
9 | Xamarin Stripe client library.
10 | Initial release.
11 | Copyright (C) Xamarin 2013
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/XamarinStripe/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------