Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2 from jdluzen/master

New features
  • Loading branch information...
commit f137e6089566895b0d0ae69334543ba6f38af920 2 parents 59a0f46 + 381ae89
@gonzalop gonzalop authored
Showing with 1,760 additions and 47 deletions.
  1. +8 −0 .hgignore
  2. +4 −4 PaymentTest/PaymentTest.csproj
  3. +181 −8 PaymentTest/Program.cs
  4. +21 −0 XamarinStripe.sln
  5. +25 −0 XamarinStripe/IUrlEncoderInfo.cs
  6. +6 −1 XamarinStripe/StripeCard.cs
  7. +9 −2 XamarinStripe/StripeCharge.cs
  8. +45 −0 XamarinStripe/StripeChargeCollection.cs
  9. +46 −0 XamarinStripe/StripeCoupon.cs
  10. +46 −0 XamarinStripe/StripeCouponCollection.cs
  11. +27 −0 XamarinStripe/StripeCouponDuration.cs
  12. +52 −0 XamarinStripe/StripeCouponInfo.cs
  13. +2 −2 XamarinStripe/StripeCreditCardInfo.cs
  14. +49 −0 XamarinStripe/StripeCreditCardToken.cs
  15. +48 −0 XamarinStripe/StripeCustomerCollection.cs
  16. +2 −2 XamarinStripe/StripeCustomerInfo.cs
  17. +29 −0 XamarinStripe/StripeCvcCheck.cs
  18. +83 −0 XamarinStripe/StripeInvoice.cs
  19. +47 −0 XamarinStripe/StripeInvoiceCollection.cs
  20. +50 −0 XamarinStripe/StripeInvoiceItem.cs
  21. +46 −0 XamarinStripe/StripeInvoiceItemCollection.cs
  22. +43 −0 XamarinStripe/StripeInvoiceItemInfo.cs
  23. +28 −0 XamarinStripe/StripeInvoiceLineItem.cs
  24. +48 −0 XamarinStripe/StripeInvoiceLineItems.cs
  25. +33 −0 XamarinStripe/StripeObject.cs
  26. +343 −22 XamarinStripe/StripePayment.cs
  27. +33 −0 XamarinStripe/StripePeriod.cs
  28. +55 −0 XamarinStripe/StripePlan.cs
  29. +47 −0 XamarinStripe/StripePlanCollection.cs
  30. +49 −0 XamarinStripe/StripePlanInfo.cs
  31. +26 −0 XamarinStripe/StripePlanInterval.cs
  32. +69 −0 XamarinStripe/StripeSubscription.cs
  33. +49 −0 XamarinStripe/StripeSubscriptionInfo.cs
  34. +30 −0 XamarinStripe/StripeSubscriptionStatus.cs
  35. +51 −0 XamarinStripe/SubscriptionStatusConverter.cs
  36. +30 −6 XamarinStripe/XamarinStripe.csproj
View
8 .hgignore
@@ -0,0 +1,8 @@
+syntax: glob
+PaymentTest/bin/*
+XamarinStripe/bin/*
+*.userprefs
+*.pidb
+PaymentTest/obj/*
+XamarinStripe/obj/*
+*.suo
View
8 PaymentTest/PaymentTest.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,9 +10,6 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PaymentTest</RootNamespace>
<AssemblyName>PaymentTest</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <TargetFrameworkProfile>
- </TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -42,6 +39,9 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\Deps\Newtonsoft.Json.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
View
189 PaymentTest/Program.cs
@@ -1,8 +1,9 @@
/*
- * Copyright 2011 Xamarin, Inc.
+ * Copyright 2011 Xamarin, Inc., Joe Dluzen
*
* Author(s):
- * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
+ * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
+ * Joe Dluzen (jdluzen@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,17 +20,26 @@
using System;
using System.Collections.Generic;
using Xamarin.Payments.Stripe;
+using Newtonsoft.Json;
namespace PaymentTest {
class Program {
static void Main (string [] args)
{
- StripePayment payment = new StripePayment ("YOURSECRETKEYGOESHERE");
- TestSimpleCharge (payment);
- TestCustomer (payment);
- TestCustomerAndCharge (payment);
- TestGetCharges (payment);
- TestGetCustomers (payment);
+ StripePayment payment = new StripePayment ("vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE");
+ //TestSimpleCharge (payment);
+ //TestPartialRefund (payment);
+ //TestCustomer (payment);
+ //TestCustomerAndCharge (payment);
+ //TestGetCharges (payment);
+ //TestGetCustomers (payment);
+ //TestCreateGetToken (payment);
+ //TestCreatePlanGetPlan (payment);
+ //TestCreateSubscription (payment);
+ //TestCreateInvoiceItems (payment);
+ //TestInvoices (payment);
+ //TestInvoices2 (payment);
+ TestDeserializePastDue ();
}
static StripeCreditCardInfo GetCC ()
@@ -42,6 +52,25 @@ static StripeCreditCardInfo GetCC ()
return cc;
}
+ static StripePlanInfo GetPlanInfo ()
+ {
+ return new StripePlanInfo {
+ Amount = 1999,
+ ID = "myplan",
+ Interval = StripePlanInterval.Month,
+ Name = "My standard plan",
+ TrialPeriod = 7
+ };
+ }
+
+ static StripeInvoiceItemInfo GetInvoiceItemInfo ()
+ {
+ return new StripeInvoiceItemInfo {
+ Amount = 1999,
+ Description = "Invoice item: " + Guid.NewGuid ().ToString ()
+ };
+ }
+
static void TestSimpleCharge (StripePayment payment)
{
StripeCreditCardInfo cc = GetCC ();
@@ -50,6 +79,18 @@ static void TestSimpleCharge (StripePayment payment)
string charge_id = charge.ID;
StripeCharge charge_info = payment.GetCharge (charge_id);
Console.WriteLine (charge_info);
+
+ StripeCharge refund = payment.Refund (charge_info.ID);
+ Console.WriteLine (refund.Created);
+ }
+
+ static void TestPartialRefund (StripePayment payment)
+ {
+ StripeCreditCardInfo cc = GetCC ();
+ StripeCharge charge = payment.Charge (5001, "usd", cc, "Test partial refund");
+ Console.WriteLine (charge.ID);
+ StripeCharge refund = payment.Refund (charge.ID, 2499);
+ Console.WriteLine (refund.Amount);
}
static void TestCustomer (StripePayment payment)
@@ -95,5 +136,137 @@ static void TestGetCustomers (StripePayment payment)
List<StripeCustomer> customers = payment.GetCustomers (0, 10);
Console.WriteLine (customers.Count);
}
+
+ static void TestCreateGetToken (StripePayment payment)
+ {
+ StripeCreditCardToken tok = payment.CreateToken (GetCC ());
+ StripeCreditCardToken tok2 = payment.GetToken (tok.ID);
+ }
+
+ static void TestCreatePlanGetPlan (StripePayment payment)
+ {
+ StripePlan plan = CreatePlan (payment);
+ int total;
+ List<StripePlan> plans = payment.GetPlans (10, 10, out total);
+ Console.WriteLine (total);
+ }
+
+ static StripePlan CreatePlan (StripePayment payment)
+ {
+ StripePlan plan = payment.CreatePlan (GetPlanInfo ());
+ StripePlan plan2 = payment.GetPlan (plan.ID);
+ //DeletePlan (plan2, payment);
+ return plan2;
+ }
+
+ static StripePlan DeletePlan (StripePlan plan, StripePayment payment)
+ {
+ StripePlan deleted = payment.DeletePlan (plan.ID);
+ return deleted;
+ }
+
+ static void TestCreateSubscription (StripePayment payment)
+ {
+ StripeCustomer cust = payment.CreateCustomer (new StripeCustomerInfo {
+ Card = GetCC ()
+ });
+ //StripePlan temp = new StripePlan { ID = "myplan" };
+ //DeletePlan (temp, payment);
+ StripePlan plan = CreatePlan (payment);
+ StripeSubscription sub = payment.Subscribe (cust.ID, new StripeSubscriptionInfo {
+ Card = GetCC (),
+ Plan = "myplan",
+ Prorate = true
+ });
+ StripeSubscription sub2 = payment.GetSubscription (sub.CustomerID);
+ TestDeleteSubscription (cust, payment);
+ DeletePlan (plan, payment);
+ }
+
+ static StripeSubscription TestDeleteSubscription (StripeCustomer customer, StripePayment payment)
+ {
+ StripeSubscription sub = payment.Unsubscribe (customer.ID, true);
+ return sub;
+ }
+
+ static void TestCreateInvoiceItems (StripePayment payment)
+ {
+ StripeCustomer cust = payment.CreateCustomer (new StripeCustomerInfo ());
+ StripeInvoiceItemInfo info = GetInvoiceItemInfo ();
+ info.CustomerID = cust.ID;
+ StripeInvoiceItem item = payment.CreateInvoiceItem (info);
+ StripeInvoiceItemInfo newInfo = GetInvoiceItemInfo ();
+ newInfo.Description = "Invoice item: " + Guid.NewGuid ().ToString ();
+ StripeInvoiceItem item2 = payment.UpdateInvoiceItem (item.ID, newInfo);
+ StripeInvoiceItem item3 = payment.GetInvoiceItem (item2.ID);
+ if (item.Description == item3.Description)
+ throw new Exception ("Update failed");
+ StripeInvoiceItem deleted = payment.DeleteInvoiceItem (item2.ID);
+ if (!deleted.Deleted.HasValue && deleted.Deleted.Value)
+ throw new Exception ("Delete failed");
+ int total;
+ List<StripeInvoiceItem> items = payment.GetInvoiceItems (10, 10, null, out total);
+ Console.WriteLine (total);
+ payment.DeleteCustomer (cust.ID);
+ }
+
+ static void TestInvoices (StripePayment payment)
+ {
+ List<StripeInvoice> invoices = payment.GetInvoices (10, 10);
+ StripeInvoice inv = payment.GetInvoice (invoices [0].ID);
+ StripeCustomer cust = payment.CreateCustomer (new StripeCustomerInfo ());
+ StripeSubscription sub = payment.Subscribe (cust.ID, new StripeSubscriptionInfo {
+ Card = GetCC ()
+ });
+ StripeInvoice inv2 = payment.GetUpcomingInvoice (cust.ID);
+ payment.Unsubscribe (cust.ID, true);
+ payment.DeleteCustomer (cust.ID);
+ }
+
+ static void TestInvoices2 (StripePayment payment)
+ {
+ StripeCustomer cust = payment.GetCustomer ("cus_ulcOcy5Seu2dpq");
+ StripePlanInfo planInfo = new StripePlanInfo{
+ Amount = 1999,
+ ID = "testplan",
+ Interval = StripePlanInterval.Month,
+ Name = "The Test Plan",
+ //TrialPeriod = 7
+ };
+ //payment.DeletePlan (planInfo.ID);
+ StripePlan plan = payment.CreatePlan (planInfo);
+ StripeSubscriptionInfo subInfo = new StripeSubscriptionInfo{
+ Card = GetCC (),
+ Plan = planInfo.ID,
+ Prorate = true
+ };
+ StripeSubscription sub = payment.Subscribe (cust.ID, subInfo);
+ payment.CreateInvoiceItem (new StripeInvoiceItemInfo {
+ CustomerID = cust.ID,
+ Amount = 1337,
+ Description = "Test single charge"
+ });
+
+ int total;
+ List<StripeInvoice> invoices = payment.GetInvoices (0, 10, cust.ID, out total);
+ StripeInvoice upcoming = payment.GetUpcomingInvoice (cust.ID);
+ payment.Unsubscribe (cust.ID, true);
+ payment.DeletePlan (planInfo.ID);
+ foreach (StripeInvoiceLineItem line in upcoming) {
+ Console.WriteLine ("{0} for type {1}", line.Amount, line.GetType ());
+ }
+
+ }
+
+ static void TestDeserializePastDue ()
+ {
+ string json = @"{
+ ""status"": ""past_due"",
+}";
+ StripeSubscription sub = JsonConvert.DeserializeObject<StripeSubscription> (json);
+ if (sub.Status != StripeSubscriptionStatus.PastDue)
+ throw new Exception ("Failed to deserialize `StripeSubscriptionStatus.PastDue`");
+ string json2 = JsonConvert.SerializeObject(sub);
+ }
}
}
View
21 XamarinStripe.sln
@@ -36,6 +36,27 @@ Global
{8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Release|x86.ActiveCfg = Release|x86
{8E81B2FD-1F8C-4C8C-B5B5-B8600709E505}.Release|x86.Build.0 = Release|x86
EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = PaymentTest\PaymentTest.csproj
+ Policies = $0
+ $0.TextStylePolicy = $1
+ $1.FileWidth = 120
+ $1.RemoveTrailingWhitespace = True
+ $1.inheritsSet = VisualStudio
+ $1.inheritsScope = text/plain
+ $1.scope = text/x-csharp
+ $0.CSharpFormattingPolicy = $2
+ $2.NamespaceBraceStyle = EndOfLine
+ $2.ClassBraceStyle = EndOfLine
+ $2.InterfaceBraceStyle = EndOfLine
+ $2.SpacesAfterTypecast = True
+ $2.inheritsSet = Mono
+ $2.inheritsScope = text/x-csharp
+ $2.scope = text/x-csharp
+ $0.StandardHeader = $3
+ $3.Text =
+ $3.IncludeInNewFiles = True
+ EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
View
25 XamarinStripe/IUrlEncoderInfo.cs
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */using System;
+using System.Text;
+
+namespace Xamarin.Payments.Stripe {
+ public interface IUrlEncoderInfo {
+ void UrlEncode (StringBuilder sb);
+ }
+}
View
7 XamarinStripe/StripeCard.cs
@@ -2,7 +2,8 @@
* Copyright 2011 Xamarin, Inc.
*
* Author(s):
- * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
+ * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
+ * Joe Dluzen (jdluzen@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,5 +34,9 @@ public class StripeCard {
public string Last4 { get; set; }
[JsonProperty (PropertyName = "id")]
public string ID { get; set; }
+ [JsonProperty (PropertyName = "cvc_check")]
+ public StripeCvcCheck CvcCheck { get; set; }
+ [JsonProperty (PropertyName = "object")]
+ public StripeObject Object { get; set; }
}
}
View
11 XamarinStripe/StripeCharge.cs
@@ -1,8 +1,9 @@
/*
- * Copyright 2011 Xamarin, Inc.
+ * Copyright 2011 Xamarin, Inc., 2011 - 2012 Joe Dluzen
*
* Author(s):
- * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
+ * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
+ * Joe Dluzen (jdluzen@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,10 +27,14 @@ public class StripeCharge {
public bool Attempted { get; set; }
[JsonProperty (PropertyName = "refunded")]
public bool Refunded { get; set; }
+ [JsonProperty (PropertyName = "amount_refunded")]
+ public int AmountRefunded { get; set; }
[JsonProperty (PropertyName = "paid")]
public bool Paid { get; set; }
[JsonProperty (PropertyName = "amount")]
public int Amount { get; set; }
+ [JsonProperty (PropertyName = "fee")]
+ public int Fee { get; set; }
[JsonProperty (PropertyName = "id")]
public string ID { get; set; }
[JsonProperty (PropertyName = "livemode")]
@@ -41,6 +46,8 @@ public class StripeCharge {
[JsonProperty (PropertyName = "created")]
[JsonConverter (typeof (UnixDateTimeConverter))]
public DateTime? Created { get; set; }
+ [JsonProperty (PropertyName = "object")]
+ public StripeObject Object { get; set; }
[JsonProperty (PropertyName = "card")]
public StripeCard Card { get; set; }
}
View
45 XamarinStripe/StripeChargeCollection.cs
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ public class StripeChargeCollection : IEnumerable<StripeCharge> {
+ [JsonProperty (PropertyName = "count")]
+ public int Total { get; set; }
+
+ [JsonProperty (PropertyName = "data")]
+ public List<StripeCharge> Charges { get; set; }
+
+ #region IEnumerable[StripeCharge] implementation
+ public IEnumerator<StripeCharge> GetEnumerator ()
+ {
+ return Charges.GetEnumerator ();
+ }
+ #endregion
+
+ #region IEnumerable implementation
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator ();
+ }
+ #endregion
+ }
+}
View
46 XamarinStripe/StripeCoupon.cs
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripeCoupon {
+ [JsonProperty (PropertyName = "times_redeemed")]
+ public int TimesRedeemed { get; set; }
+
+ [JsonProperty (PropertyName = "livemode")]
+ public bool LiveMode { get; set; }
+
+ [JsonProperty (PropertyName = "object")]
+ public StripeObject Object { get; set; }
+
+ [JsonProperty (PropertyName = "duration")]
+ public StripeCouponDuration Duration { get; set; }
+
+ [JsonProperty (PropertyName = "id")]
+ public string ID { get; set; }
+
+ [JsonProperty (PropertyName = "percent_off")]
+ public int PercentOff { get; set; }
+
+ [JsonProperty (PropertyName = "deleted")]
+ public bool? Deleted { get; set; }
+ }
+}
View
46 XamarinStripe/StripeCouponCollection.cs
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripeCouponCollection : IEnumerable<StripeCoupon> {
+ [JsonProperty (PropertyName = "count")]
+ public int Total { get; set; }
+
+ [JsonProperty (PropertyName = "data")]
+ public List<StripeCoupon> Coupons { get; set; }
+
+ #region IEnumerable[StripeCoupon] implementation
+ public IEnumerator<StripeCoupon> GetEnumerator ()
+ {
+ return Coupons.GetEnumerator ();
+ }
+ #endregion
+
+ #region IEnumerable implementation
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator ();
+ }
+ #endregion
+ }
+}
View
27 XamarinStripe/StripeCouponDuration.cs
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Xamarin.Payments.Stripe {
+ public enum StripeCouponDuration {
+ Forever,
+ Once,
+ Repeating
+ }
+}
View
52 XamarinStripe/StripeCouponInfo.cs
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Text;
+using System.Web;
+
+namespace Xamarin.Payments.Stripe {
+ public class StripeCouponInfo : IUrlEncoderInfo {
+ public string ID { get; set; }
+
+ public int PercentOff { get; set; }
+
+ public StripeCouponDuration Duration { get; set; }
+
+ public int MonthsForDuration { get; set; }
+
+ public int MaxRedemptions { get; set; }
+
+ public DateTime RedeemBy { get; set; }
+
+ #region IUrlEncoderInfo implementation
+ public virtual void UrlEncode (StringBuilder sb)
+ {
+ sb.AppendFormat ("percent_off={0}&duration={1}&", PercentOff, HttpUtility.UrlEncode (Duration.ToString ().ToLower ()));
+ if (!string.IsNullOrEmpty (ID))
+ sb.AppendFormat ("id={0}&", HttpUtility.UrlEncode (ID));
+ if (MonthsForDuration > 0)
+ sb.AppendFormat ("duration_in_months={0}&", MonthsForDuration);
+ if (MaxRedemptions > 0)
+ sb.AppendFormat ("max_redemptions={0}&", MaxRedemptions);
+ if (RedeemBy != DateTime.MinValue)
+ sb.AppendFormat ("redeem_by={0}&", RedeemBy.ToUnixEpoch ());
+ }
+ #endregion
+ }
+}
View
4 XamarinStripe/StripeCreditCardInfo.cs
@@ -21,7 +21,7 @@
using System.Web;
namespace Xamarin.Payments.Stripe {
- public class StripeCreditCardInfo {
+ public class StripeCreditCardInfo : IUrlEncoderInfo {
// Mandatory
public string Number { get; set; }
// Mandatory when Number is a not one-time token instead of a number
@@ -37,7 +37,7 @@ public class StripeCreditCardInfo {
public string StateOrProvince { get; set; }
public string Country { get; set; }
- public void UrlEncode (StringBuilder sb)
+ public virtual void UrlEncode (StringBuilder sb)
{
if (String.IsNullOrEmpty (Number))
throw new ArgumentNullException ("Number");
View
49 XamarinStripe/StripeCreditCardToken.cs
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ public class StripeCreditCardToken {
+ [JsonProperty (PropertyName = "created")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime Created { get; set; }
+
+ [JsonProperty (PropertyName = "currency")]
+ public string Currency { get; set; }
+
+ [JsonProperty (PropertyName = "used")]
+ public bool Used { get; set; }
+
+ [JsonProperty (PropertyName = "amount")]
+ public int MinimumAmount { get; set; }
+
+ [JsonProperty (PropertyName = "object")]
+ public StripeObject Object { get; set; }
+
+ [JsonProperty (PropertyName = "livemode")]
+ public bool Live { get; set; }
+
+ [JsonProperty (PropertyName = "id")]
+ public string ID { get; set; }
+
+ [JsonProperty (PropertyName = "card")]
+ public StripeCard Card { get; set; }
+ }
+}
View
48 XamarinStripe/StripeCustomerCollection.cs
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject(MemberSerialization.OptIn)]
+ public class StripeCustomerCollection : IEnumerable<StripeCustomer> {
+
+ [JsonProperty(PropertyName = "count")]
+ public int Total { get; set; }
+
+ [JsonProperty(PropertyName = "data")]
+ public List<StripeCustomer> Customers { get; set; }
+
+ #region IEnumerable[StripeCustomer] implementation
+ public IEnumerator<StripeCustomer> GetEnumerator ()
+ {
+ return Customers.GetEnumerator ();
+ }
+ #endregion
+
+ #region IEnumerable implementation
+ IEnumerator IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator ();
+ }
+ #endregion
+ }
+}
View
4 XamarinStripe/StripeCustomerInfo.cs
@@ -22,7 +22,7 @@
using System.Web;
namespace Xamarin.Payments.Stripe {
- public class StripeCustomerInfo {
+ public class StripeCustomerInfo : IUrlEncoderInfo {
public StripeCreditCardInfo Card { get; set; }
// The strings allow ""
public string Coupon { get; set; }
@@ -32,7 +32,7 @@ public class StripeCustomerInfo {
public DateTime? TrialEnd { get; set; }
public bool? Validate { get; set; }
- public void UrlEncode (StringBuilder sb)
+ public virtual void UrlEncode (StringBuilder sb)
{
if (Card != null)
Card.UrlEncode (sb);
View
29 XamarinStripe/StripeCvcCheck.cs
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Xamarin.Payments.Stripe {
+ public enum StripeCvcCheck {
+ Unknown,
+ Pass,
+ Fail,
+ Unchecked
+ }
+}
+
View
83 XamarinStripe/StripeInvoice.cs
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripeInvoice : IEnumerable<StripeInvoiceLineItem> {
+ [JsonProperty (PropertyName = "created")]
+ [JsonConverter (typeof (UnixDateTimeConverter))]
+ public DateTime? Created { get; set; }
+
+ [JsonProperty (PropertyName = "subtotal")]
+ public int Subtotal { get; set; }
+
+ [JsonProperty (PropertyName = "total")]
+ public int Total { get; set; }
+
+ [JsonProperty (PropertyName = "lines")]
+ public StripeInvoiceLineItems LineItems { get; set; }
+
+ [JsonProperty (PropertyName = "object")]
+ public StripeObject Object { get; set; }
+
+ [JsonProperty (PropertyName = "id")]
+ public string ID { get; set; }
+
+ [JsonProperty (PropertyName = "attempted")]
+ public bool Attempted { get; set; }
+
+ [JsonProperty (PropertyName = "closed")]
+ public bool Closed { get; set; }
+
+ [JsonProperty (PropertyName = "customer")]
+ public string CustomerID { get; set; }
+
+ [JsonProperty (PropertyName = "date")]
+ [JsonConverter (typeof (UnixDateTimeConverter))]
+ public DateTime Date { get; set; }
+
+ [JsonProperty (PropertyName = "paid")]
+ public bool Paid { get; set; }
+
+ [JsonProperty (PropertyName = "period_start")]
+ [JsonConverter (typeof (UnixDateTimeConverter))]
+ public DateTime Start { get; set; }
+
+ [JsonProperty (PropertyName = "period_end")]
+ [JsonConverter (typeof (UnixDateTimeConverter))]
+ public DateTime End { get; set; }
+
+ #region IEnumerable[StripeInvoiceLineItem] implementation
+ public IEnumerator<StripeInvoiceLineItem> GetEnumerator ()
+ {
+ return LineItems.GetEnumerator ();
+ }
+ #endregion
+
+ #region IEnumerable implementation
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator ();
+ }
+ #endregion
+ }
+}
View
47 XamarinStripe/StripeInvoiceCollection.cs
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripeInvoiceCollection : IEnumerable<StripeInvoice> {
+ [JsonProperty (PropertyName = "count")]
+ public int Total { get; set; }
+
+ [JsonProperty (PropertyName = "data")]
+ public List<StripeInvoice> Invoices { get; set; }
+
+ #region IEnumerable[StripeInvoice] implementation
+ public IEnumerator<StripeInvoice> GetEnumerator ()
+ {
+ return Invoices.GetEnumerator ();
+ }
+ #endregion
+
+ #region IEnumerable implementation
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator ();
+ }
+ #endregion
+ }
+}
+
View
50 XamarinStripe/StripeInvoiceItem.cs
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripeInvoiceItem : StripeInvoiceLineItem {
+ [JsonProperty (PropertyName = "customer")]
+ public string CustomerID { get; set; }
+
+ [JsonProperty (PropertyName = "currency")]
+ public string Currency { get; set; }
+
+ [JsonProperty (PropertyName = "livemode")]
+ public bool LiveMode { get; set; }
+
+ [JsonProperty (PropertyName = "date")]
+ [JsonConverter (typeof (UnixDateTimeConverter))]
+ public DateTime Date { get; set; }
+
+ [JsonProperty (PropertyName = "object")]
+ public StripeObject Object { get; set; }
+
+ [JsonProperty (PropertyName = "description")]
+ public string Description { get; set; }
+
+ [JsonProperty (PropertyName = "id")]
+ public string ID { get; set; }
+
+ [JsonProperty (PropertyName = "deleted")]
+ public bool? Deleted { get; set; }
+ }
+}
View
46 XamarinStripe/StripeInvoiceItemCollection.cs
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripeInvoiceItemCollection : IEnumerable<StripeInvoiceItem> {
+ [JsonProperty (PropertyName = "count")]
+ public int Total { get; set; }
+
+ [JsonProperty (PropertyName = "data")]
+ public List<StripeInvoiceItem> InvoiceItems { get; set; }
+
+ #region IEnumerable[StripeInvoiceItem] implementation
+ public IEnumerator<StripeInvoiceItem> GetEnumerator ()
+ {
+ return InvoiceItems.GetEnumerator ();
+ }
+ #endregion
+
+ #region IEnumerable implementation
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator ();
+ }
+ #endregion
+ }
+}
View
43 XamarinStripe/StripeInvoiceItemInfo.cs
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Text;
+using System.Web;
+
+namespace Xamarin.Payments.Stripe {
+ public class StripeInvoiceItemInfo : IUrlEncoderInfo {
+ public string CustomerID { get; set; }
+
+ public int Amount { get; set; }
+
+ public string Currency { get; set; }
+
+ public string Description { get; set; }
+
+ #region IUrlEncoderInfo implementation
+ public virtual void UrlEncode (StringBuilder sb)
+ {
+ sb.AppendFormat ("customer={0}&amount={1}&currency={2}&",
+ HttpUtility.UrlEncode (CustomerID), Amount, HttpUtility.UrlEncode (Currency ?? "usd"));
+ if (!string.IsNullOrEmpty (Description))
+ sb.AppendFormat ("description={0}&", HttpUtility.UrlEncode (Description));
+ }
+ #endregion
+ }
+}
View
28 XamarinStripe/StripeInvoiceLineItem.cs
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public abstract class StripeInvoiceLineItem {
+ [JsonProperty (PropertyName = "amount")]
+ public int Amount { get; set; }
+ }
+}
View
48 XamarinStripe/StripeInvoiceLineItems.cs
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripeInvoiceLineItems : IEnumerable<StripeInvoiceLineItem> {
+ [JsonProperty (PropertyName = "invoiceitems")]
+ public List<StripeInvoiceItem> InvoiceItems { get; set; }
+
+ [JsonProperty (PropertyName = "subscriptions")]
+ public List<StripeSubscription> Subscriptions { get; set; }
+
+ #region IEnumerable[StripeInvoiceLineItem] implementation
+ public IEnumerator<StripeInvoiceLineItem> GetEnumerator ()
+ {
+ return ((IEnumerable<StripeInvoiceLineItem>)InvoiceItems).Concat (Subscriptions).GetEnumerator();
+ }
+ #endregion
+
+ #region IEnumerable implementation
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator();
+ }
+ #endregion
+
+ }
+}
View
33 XamarinStripe/StripeObject.cs
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Xamarin.Payments.Stripe {
+ public enum StripeObject {
+ Unknown,
+ Card,
+ Charge,
+ Customer,
+ InvoiceItem,
+ Invoice,
+ Plan,
+ Subscription,
+ Token
+ }
+}
View
365 XamarinStripe/StripePayment.cs
@@ -1,8 +1,9 @@
/*
- * Copyright 2011 Xamarin, Inc.
+ * Copyright 2011 Xamarin, Inc., 2011 - 2012 Joe Dluzen
*
* Author(s):
- * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
+ * Gonzalo Paniagua Javier (gonzalo@xamarin.com)
+ * Joe Dluzen (jdluzen@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +19,7 @@
*/
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
@@ -27,10 +29,10 @@
namespace Xamarin.Payments.Stripe {
public class StripePayment {
- static string api_endpoint = "https://api.stripe.com/v1";
- static string user_agent = "Stripe .NET v1";
- static Encoding encoding = Encoding.UTF8;
-
+ static readonly string api_endpoint = "https://api.stripe.com/v1";
+ static readonly string subscription_path = "{0}/customers/{1}/subscription";
+ static readonly string user_agent = "Stripe .NET v1";
+ static readonly Encoding encoding = Encoding.UTF8;
ICredentials credential;
public StripePayment (string api_key)
@@ -38,7 +40,7 @@ public StripePayment (string api_key)
credential = new NetworkCredential (api_key, "");
TimeoutSeconds = 30;
}
-
+ #region Shared
protected virtual WebRequest SetupRequest (string method, string url)
{
WebRequest req = (WebRequest) WebRequest.Create (url);
@@ -49,8 +51,8 @@ protected virtual WebRequest SetupRequest (string method, string url)
req.Credentials = credential;
req.PreAuthenticate = true;
req.Timeout = TimeoutSeconds * 1000;
- // Perhaps we should only set this for POST. DELETE and GET don't need it.
- req.ContentType = "application/x-www-form-urlencoded";
+ if (method == "POST")
+ req.ContentType = "application/x-www-form-urlencoded";
return req;
}
@@ -61,6 +63,11 @@ static string GetResponseAsString (WebResponse response)
}
}
+ protected virtual string DoRequest (string endpoint)
+ {
+ return DoRequest (endpoint, "GET", null);
+ }
+
protected virtual string DoRequest (string endpoint, string method, string body)
{
string result = null;
@@ -85,7 +92,7 @@ protected virtual string DoRequest (string endpoint, string method, string body)
if (resp != null)
status_code = resp.StatusCode;
- if ((int)status_code <= 500)
+ if ((int) status_code <= 500)
throw StripeException.GetFromJSON (status_code, json_error);
}
throw;
@@ -93,6 +100,15 @@ protected virtual string DoRequest (string endpoint, string method, string body)
return result;
}
+ protected virtual StringBuilder UrlEncode (IUrlEncoderInfo infoInstance)
+ {
+ StringBuilder str = new StringBuilder ();
+ infoInstance.UrlEncode (str);
+ if (str.Length > 0)
+ str.Length--;
+ return str;
+ }
+ #endregion
#region Charge
public StripeCharge Charge (int amount_cents, string currency, string customer, string description)
{
@@ -144,7 +160,7 @@ public StripeCharge GetCharge (string charge_id)
throw new ArgumentNullException ("charge_id");
string ep = String.Format ("{0}/charges/{1}", api_endpoint, HttpUtility.UrlEncode (charge_id));
- string json = DoRequest (ep, "GET", null);
+ string json = DoRequest (ep);
return JsonConvert.DeserializeObject<StripeCharge> (json);
}
@@ -155,11 +171,18 @@ public List<StripeCharge> GetCharges ()
public List<StripeCharge> GetCharges (int offset, int count)
{
- return GetCharges (offset, count, null);
+ int dummy;
+ return GetCharges (offset, count, null, out dummy);
}
public List<StripeCharge> GetCharges (int offset, int count, string customer_id)
{
+ int dummy;
+ return GetCharges (offset, count, customer_id, out dummy);
+ }
+
+ public List<StripeCharge> GetCharges (int offset, int count, string customer_id, out int total)
+ {
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset");
if (count < 1 || count > 100)
@@ -173,8 +196,10 @@ public List<StripeCharge> GetCharges (int offset, int count, string customer_id)
str.Length--;
string ep = String.Format ("{0}/charges?{1}", api_endpoint, str);
- string json = DoRequest (ep, "GET", null);
- return JsonConvert.DeserializeObject<List<StripeCharge>> (json);
+ string json = DoRequest (ep);
+ StripeChargeCollection charges = JsonConvert.DeserializeObject<StripeChargeCollection> (json);
+ total = charges.Total;
+ return charges.Charges;
}
#endregion
#region Refund
@@ -184,17 +209,26 @@ public StripeCharge Refund (string charge_id)
throw new ArgumentNullException ("charge_id");
string ep = String.Format ("{0}/charges/{1}/refund", api_endpoint, HttpUtility.UrlEncode (charge_id));
- string json = DoRequest (ep, "POST", "");
+ string json = DoRequest (ep, "POST", null);
+ return JsonConvert.DeserializeObject<StripeCharge> (json);
+ }
+
+ public StripeCharge Refund (string charge_id, int amount)
+ {
+ if (String.IsNullOrEmpty (charge_id))
+ throw new ArgumentNullException ("charge_id");
+ if (amount <= 0)
+ throw new ArgumentException ("Amount must be greater than zero.", "amount");
+
+ string ep = String.Format ("{0}/charges/{1}/refund?amount={2}", api_endpoint, HttpUtility.UrlEncode (charge_id), amount);
+ string json = DoRequest (ep, "POST", null);
return JsonConvert.DeserializeObject<StripeCharge> (json);
}
#endregion
#region Customer
StripeCustomer CreateOrUpdateCustomer (string id, StripeCustomerInfo customer)
{
- StringBuilder str = new StringBuilder ();
- customer.UrlEncode (str);
- if (str.Length > 0)
- str.Length--;
+ StringBuilder str = UrlEncode (customer);
string format = "{0}/customers"; // Create
if (id != null)
@@ -228,7 +262,7 @@ public StripeCustomer GetCustomer (string customer_id)
throw new ArgumentNullException ("customer_id");
string ep = String.Format ("{0}/customers/{1}", api_endpoint, HttpUtility.UrlEncode (customer_id));
- string json = DoRequest (ep, "GET", null);
+ string json = DoRequest (ep);
return JsonConvert.DeserializeObject<StripeCustomer> (json);
}
@@ -239,6 +273,12 @@ public List<StripeCustomer> GetCustomers ()
public List<StripeCustomer> GetCustomers (int offset, int count)
{
+ int dummy;
+ return GetCustomers (offset, count, out dummy);
+ }
+
+ public List<StripeCustomer> GetCustomers (int offset, int count, out int total)
+ {
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset");
if (count < 1 || count > 100)
@@ -246,8 +286,10 @@ public List<StripeCustomer> GetCustomers (int offset, int count)
string str = String.Format ("offset={0}&count={1}", offset, count);
string ep = String.Format ("{0}/customers?{1}", api_endpoint, str);
- string json = DoRequest (ep, "GET", null);
- return JsonConvert.DeserializeObject<List<StripeCustomer>> (json);
+ string json = DoRequest (ep);
+ StripeCustomerCollection customers = JsonConvert.DeserializeObject<StripeCustomerCollection> (json);
+ total = customers.Total;
+ return customers.Customers;
}
public StripeCustomer DeleteCustomer (string customer_id)
@@ -260,7 +302,286 @@ public StripeCustomer DeleteCustomer (string customer_id)
return JsonConvert.DeserializeObject<StripeCustomer> (json);
}
#endregion
+ #region Tokens
+ public StripeCreditCardToken CreateToken (StripeCreditCardInfo card)
+ {
+ if (card == null)
+ throw new ArgumentNullException ("card");
+ StringBuilder str = UrlEncode (card);
+
+ string ep = string.Format ("{0}/tokens", api_endpoint);
+ string json = DoRequest (ep, "POST", str.ToString ());
+ return JsonConvert.DeserializeObject<StripeCreditCardToken> (json);
+ }
+
+ public StripeCreditCardToken GetToken (string tokenId)
+ {
+ if (string.IsNullOrEmpty (tokenId))
+ throw new ArgumentNullException (tokenId);
+
+ string ep = string.Format ("{0}/tokens/{1}", api_endpoint, HttpUtility.UrlEncode (tokenId));
+ string json = DoRequest (ep);
+ return JsonConvert.DeserializeObject<StripeCreditCardToken> (json);
+ }
+ #endregion
+ #region Plans
+ public StripePlan CreatePlan (StripePlanInfo plan)
+ {
+ if (plan == null)
+ throw new ArgumentNullException ("plan");
+ StringBuilder str = UrlEncode (plan);
+
+ string ep = string.Format ("{0}/plans", api_endpoint);
+ string json = DoRequest (ep, "POST", str.ToString ());
+ return JsonConvert.DeserializeObject<StripePlan> (json);
+ }
+
+ public StripePlan GetPlan (string planId)
+ {
+ if (string.IsNullOrEmpty (planId))
+ throw new ArgumentNullException ("id");
+
+ string ep = string.Format ("{0}/plans/{1}", api_endpoint, HttpUtility.UrlEncode (planId));
+ string json = DoRequest (ep);
+ return JsonConvert.DeserializeObject<StripePlan> (json);
+ }
+
+ public StripePlan DeletePlan (string planId)
+ {
+ if (string.IsNullOrEmpty (planId))
+ throw new ArgumentNullException ("id");
+
+ string ep = string.Format ("{0}/plans/{1}", api_endpoint, HttpUtility.UrlEncode (planId));
+ string json = DoRequest (ep, "DELETE", null);
+ return JsonConvert.DeserializeObject<StripePlan> (json);
+ }
+
+ public List<StripePlan> GetPlans ()
+ {
+ return GetPlans (0, 10);
+ }
+
+ public List<StripePlan> GetPlans (int offset, int count)
+ {
+ int dummy;
+ return GetPlans (offset, count, out dummy);
+ }
+
+ public List<StripePlan> GetPlans (int offset, int count, out int total)
+ {
+ string str = string.Format ("count={0}&offset={1}", count, offset);
+ string ep = string.Format ("{0}/plans?{1}", api_endpoint, str);
+ string json = DoRequest (ep);
+ StripePlanCollection plans = JsonConvert.DeserializeObject<StripePlanCollection> (json);
+ total = plans.Total;
+ return plans.Plans;
+ }
+ #endregion
+ #region Subscriptions
+ public StripeSubscription Subscribe (string customerId, StripeSubscriptionInfo subscription)
+ {
+ StringBuilder str = UrlEncode (subscription);
+ string ep = string.Format (subscription_path, api_endpoint, HttpUtility.UrlEncode (customerId));
+ string json = DoRequest (ep, "POST", str.ToString ());
+ return JsonConvert.DeserializeObject<StripeSubscription> (json);
+ }
+
+ public StripeSubscription GetSubscription (string customerId)
+ {
+ if (string.IsNullOrEmpty (customerId))
+ throw new ArgumentNullException ("customerId");
+ string ep = string.Format (subscription_path, api_endpoint, HttpUtility.UrlEncode (customerId));
+ string json = DoRequest (ep);
+ return JsonConvert.DeserializeObject<StripeSubscription> (json);
+ }
+
+ public StripeSubscription Unsubscribe (string customerId, bool atPeriodEnd)
+ {
+ string ep = string.Format (subscription_path + "?at_period_end={2}", api_endpoint, HttpUtility.UrlEncode (customerId), atPeriodEnd.ToString (CultureInfo.InvariantCulture).ToLowerInvariant ());
+ string json = DoRequest (ep, "DELETE", null);
+ return JsonConvert.DeserializeObject<StripeSubscription> (json);
+ }
+ #endregion
+ #region Invoice items
+ public StripeInvoiceItem CreateInvoiceItem (StripeInvoiceItemInfo item)
+ {
+ if (string.IsNullOrEmpty (item.CustomerID))
+ throw new ArgumentNullException ("item.CustomerID");
+ StringBuilder str = UrlEncode (item);
+ string ep = string.Format ("{0}/invoiceitems", api_endpoint);
+ string json = DoRequest (ep, "POST", str.ToString ());
+ return JsonConvert.DeserializeObject<StripeInvoiceItem> (json);
+ }
+
+ public StripeInvoiceItem GetInvoiceItem (string invoiceItemId)
+ {
+ if (string.IsNullOrEmpty (invoiceItemId))
+ throw new ArgumentNullException ("invoiceItemId");
+ string ep = string.Format ("{0}/invoiceitems/{1}", api_endpoint, invoiceItemId);
+ string json = DoRequest (ep);
+ return JsonConvert.DeserializeObject<StripeInvoiceItem> (json);
+ }
+
+ public StripeInvoiceItem UpdateInvoiceItem (string invoiceItemId, StripeInvoiceItemInfo item)
+ {
+ StringBuilder str = UrlEncode (item);
+ string ep = string.Format ("{0}/invoiceitems/{1}", api_endpoint, invoiceItemId);
+ string json = DoRequest (ep, "POST", str.ToString ());
+ return JsonConvert.DeserializeObject<StripeInvoiceItem> (json);
+ }
+
+ public StripeInvoiceItem DeleteInvoiceItem (string invoiceItemId)
+ {
+ string ep = string.Format ("{0}/invoiceitems/{1}", api_endpoint, invoiceItemId);
+ string json = DoRequest (ep, "DELETE", null);
+ return JsonConvert.DeserializeObject<StripeInvoiceItem> (json);
+ }
+
+ public List<StripeInvoiceItem> GetInvoiceItems ()
+ {
+ return GetInvoiceItems (0, 10);
+ }
+
+ public List<StripeInvoiceItem> GetInvoiceItems (int offset, int count)
+ {
+ return GetInvoiceItems (offset, count, null);
+ }
+
+ public List<StripeInvoiceItem> GetInvoiceItems (int offset, int count, string customerId)
+ {
+ int dummy;
+ return GetInvoiceItems (offset, count, customerId, out dummy);
+ }
+
+ public List<StripeInvoiceItem> GetInvoiceItems (int offset, int count, string customerId, out int total)
+ {
+ if (offset < 0)
+ throw new ArgumentOutOfRangeException ("offset");
+ if (count < 1 || count > 100)
+ throw new ArgumentOutOfRangeException ("count");
+
+ StringBuilder str = new StringBuilder ();
+ str.AppendFormat ("offset={0}&", offset);
+ str.AppendFormat ("count={0}&", count);
+ if (!string.IsNullOrEmpty (customerId))
+ str.AppendFormat ("customer={0}&", HttpUtility.UrlEncode (customerId));
+
+ str.Length--;
+ string ep = String.Format ("{0}/invoiceitems?{1}", api_endpoint, str);
+ string json = DoRequest (ep);
+ StripeInvoiceItemCollection invoiceItems = JsonConvert.DeserializeObject<StripeInvoiceItemCollection> (json);
+ total = invoiceItems.Total;
+ return invoiceItems.InvoiceItems;
+ }
+ #endregion
+ #region Invoices
+ public StripeInvoice GetInvoice (string invoiceId)
+ {
+ if (string.IsNullOrEmpty (invoiceId))
+ throw new ArgumentNullException ("invoiceId");
+ string ep = string.Format ("{0}/invoices/{1}", api_endpoint, invoiceId);
+ string json = DoRequest (ep);
+ return JsonConvert.DeserializeObject<StripeInvoice> (json);
+ }
+
+ public List<StripeInvoice> GetInvoices ()
+ {
+ return GetInvoices (0, 10);
+ }
+
+ public List<StripeInvoice> GetInvoices (int offset, int count)
+ {
+ return GetInvoices (offset, count, null);
+ }
+ public List<StripeInvoice> GetInvoices (int offset, int count, string customerId)
+ {
+ int dummy;
+ return GetInvoices (offset, count, customerId, out dummy);
+ }
+
+ public List<StripeInvoice> GetInvoices (int offset, int count, string customerId, out int total)
+ {
+ if (offset < 0)
+ throw new ArgumentOutOfRangeException ("offset");
+ if (count < 1 || count > 100)
+ throw new ArgumentOutOfRangeException ("count");
+
+ StringBuilder str = new StringBuilder ();
+ str.AppendFormat ("offset={0}&", offset);
+ str.AppendFormat ("count={0}&", count);
+ if (!string.IsNullOrEmpty (customerId))
+ str.AppendFormat ("customer={0}&", HttpUtility.UrlEncode (customerId));
+
+ str.Length--;
+ string ep = String.Format ("{0}/invoices?{1}", api_endpoint, str);
+ string json = DoRequest (ep);
+ StripeInvoiceCollection invoiceItems = JsonConvert.DeserializeObject<StripeInvoiceCollection> (json);
+ total = invoiceItems.Total;
+ return invoiceItems.Invoices;
+ }
+
+ public StripeInvoice GetUpcomingInvoice (string customerId)
+ {
+ if (string.IsNullOrEmpty (customerId))
+ throw new ArgumentOutOfRangeException ("customerId");
+ string ep = String.Format ("{0}/invoices/upcoming?customer={1}", api_endpoint, customerId);
+ string json = DoRequest (ep);
+ return JsonConvert.DeserializeObject<StripeInvoice> (json);
+ }
+ #endregion
+ #region Coupons
+ public StripeCoupon CreateCoupon (StripeCouponInfo coupon)
+ {
+ if (coupon == null)
+ throw new ArgumentNullException ("coupon");
+ if (coupon.PercentOff < 1 || coupon.PercentOff > 100)
+ throw new ArgumentOutOfRangeException ("coupon.PercentOff");
+ if (coupon.Duration == StripeCouponDuration.Repeating && coupon.MonthsForDuration < 1)
+ throw new ArgumentException ("MonthsForDuration must be greater than 1 when Duration = Repeating");
+ StringBuilder str = UrlEncode (coupon);
+ string ep = string.Format ("{0}/coupons", api_endpoint);
+ string json = DoRequest (ep, "POST", str.ToString ());
+ return JsonConvert.DeserializeObject<StripeCoupon> (json);
+ }
+
+ public StripeCoupon GetCoupon (string couponId)
+ {
+ if (string.IsNullOrEmpty (couponId))
+ throw new ArgumentNullException ("couponId");
+ string ep = string.Format ("{0}/coupons/{1}", api_endpoint, couponId);
+ string json = DoRequest (ep);
+ return JsonConvert.DeserializeObject<StripeCoupon> (json);
+ }
+
+ public StripeCoupon DeleteCoupon (string couponId)
+ {
+ if (string.IsNullOrEmpty (couponId))
+ throw new ArgumentNullException ("couponId");
+ string ep = string.Format ("{0}/coupons/{1}", api_endpoint, couponId);
+ string json = DoRequest (ep, "DELETE", null);
+ return JsonConvert.DeserializeObject<StripeCoupon> (json);
+ }
+
+ public List<StripeCoupon> GetCoupons ()
+ {
+ int dummy;
+ return GetCoupons (0, 10, out dummy);
+ }
+
+ public List<StripeCoupon> GetCoupons (int offset, int count, out int total)
+ {
+ if (offset < 0)
+ throw new ArgumentOutOfRangeException ("offset");
+ if (count > 100)
+ throw new ArgumentOutOfRangeException ("count");
+ string ep = string.Format ("{0}/coupons?offset={0}&count={1}", api_endpoint, offset, count);
+ string json = DoRequest (ep);
+ StripeCouponCollection coupons = JsonConvert.DeserializeObject<StripeCouponCollection> (json);
+ total = coupons.Total;
+ return coupons.Coupons;
+ }
+ #endregion
public int TimeoutSeconds { get; set; }
}
}
View
33 XamarinStripe/StripePeriod.cs
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripePeriod {
+ [JsonProperty (PropertyName = "start")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime Start { get; set; }
+
+ [JsonProperty (PropertyName = "end")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime End { get; set; }
+ }
+}
View
55 XamarinStripe/StripePlan.cs
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripePlan {
+ [JsonProperty (PropertyName = "amount")]
+ public int Amount { get; set; }
+
+ [JsonProperty (PropertyName = "currency")]
+ public string Currency { get; set; }
+
+ [JsonProperty(PropertyName = "deleted")]
+ public bool? Deleted { get; set; }
+
+ [JsonProperty(PropertyName = "id")]
+ public string ID { get; set; }
+
+ [JsonProperty(PropertyName = "identifier")]
+ public string Identifier { get; set; }
+
+ [JsonProperty (PropertyName = "interval")]
+ public StripePlanInterval Interval { get; set; }
+
+ [JsonProperty (PropertyName = "livemode")]
+ public bool LiveMode { get; set; }
+
+ [JsonProperty (PropertyName = "name")]
+ public string Name { get; set; }
+
+ [JsonProperty (PropertyName = "object")]
+ public StripeObject Object { get; set; }
+
+ [JsonProperty (PropertyName = "trial_period_days")]
+ public int TrialPeriod { get; set; }
+ }
+}
View
47 XamarinStripe/StripePlanCollection.cs
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject(MemberSerialization.OptIn)]
+ public class StripePlanCollection : IEnumerable<StripePlan> {
+ [JsonProperty (PropertyName = "count")]
+ public int Total { get; set; }
+
+ [JsonProperty (PropertyName = "data")]
+ public List<StripePlan> Plans { get; set; }
+
+ #region IEnumerable[StripePlan] implementation
+ public IEnumerator<StripePlan> GetEnumerator ()
+ {
+ return Plans.GetEnumerator ();
+ }
+ #endregion
+
+ #region IEnumerable implementation
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator ();
+ }
+ #endregion
+ }
+}
+
View
49 XamarinStripe/StripePlanInfo.cs
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Text;
+using System.Web;
+
+namespace Xamarin.Payments.Stripe {
+ public class StripePlanInfo : IUrlEncoderInfo {
+ public string ID { get; set; }
+
+ public int Amount { get; set; }
+
+ public string Currency { get; set; }
+
+ public StripePlanInterval Interval { get; set; }
+
+ public string Name { get; set; }
+
+ public int TrialPeriod { get; set; }
+
+ #region IUrlEncoderInfo Members
+
+ public virtual void UrlEncode (StringBuilder sb)
+ {
+ sb.AppendFormat ("id={0}&amount={1}&currency={2}&interval={3}&name={4}&",
+ HttpUtility.UrlEncode (ID), Amount, HttpUtility.UrlEncode (Currency ?? "usd"), HttpUtility.UrlEncode (Interval.ToString().ToLower ()), HttpUtility.UrlEncode (Name));
+ if (TrialPeriod > 0)
+ sb.AppendFormat ("trial_period_days={0}&", TrialPeriod);
+ }
+
+ #endregion
+ }
+}
View
26 XamarinStripe/StripePlanInterval.cs
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Xamarin.Payments.Stripe {
+ public enum StripePlanInterval {
+ Month,
+ Year
+ }
+}
View
69 XamarinStripe/StripeSubscription.cs
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2011, 2012 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Newtonsoft.Json;
+
+namespace Xamarin.Payments.Stripe {
+ [JsonObject (MemberSerialization.OptIn)]
+ public class StripeSubscription : StripeInvoiceLineItem {
+ [JsonProperty (PropertyName = "current_period_end")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime? CurrentPeriodEnd { get; set; }
+
+ [JsonProperty (PropertyName = "status")]
+ [JsonConverter (typeof(SubscriptionStatusConverter))]
+ public StripeSubscriptionStatus Status { get; set; }
+
+ [JsonProperty (PropertyName = "plan")]
+ public StripePlan Plan { get; set; }
+
+ [JsonProperty (PropertyName = "current_period_start")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime? CurrentPeriodStart { get; set; }
+
+ [JsonProperty (PropertyName = "start")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime? Start { get; set; }
+
+ [JsonProperty (PropertyName = "object")]
+ public StripeObject? Object { get; set; }
+
+ [JsonProperty (PropertyName = "trial_start")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime? TrialStart { get; set; }
+
+ [JsonProperty (PropertyName = "trial_end")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime? TrialEnd { get; set; }
+
+ [JsonProperty (PropertyName = "canceled_at")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime? CanceledAt { get; set; }
+
+ [JsonProperty (PropertyName = "ended_at")]
+ [JsonConverter (typeof(UnixDateTimeConverter))]
+ public DateTime? EndedAt { get; set; }
+
+ [JsonProperty (PropertyName = "customer")]
+ public string CustomerID { get; set; }
+
+ [JsonProperty (PropertyName = "period")]
+ public StripePeriod Period { get; set; }
+ }
+}
View
49 XamarinStripe/StripeSubscriptionInfo.cs
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Globalization;
+using System.Text;
+using System.Web;
+
+namespace Xamarin.Payments.Stripe {
+ public class StripeSubscriptionInfo : IUrlEncoderInfo {
+ public string Plan { get; set; }
+
+ public string Coupon { get; set; }
+
+ public bool? Prorate { get; set; }
+
+ public DateTime? TrialEnd { get; set; }
+
+ public StripeCreditCardInfo Card { get; set; }
+
+ public virtual void UrlEncode (StringBuilder sb)
+ {
+ sb.AppendFormat ("plan={0}&", HttpUtility.UrlEncode (Plan));
+ if (!string.IsNullOrEmpty (Coupon))
+ sb.AppendFormat ("coupon={0}&", HttpUtility.UrlEncode (Coupon));
+ if (Prorate != null && Prorate.HasValue)
+ sb.AppendFormat ("prorate={0}&", Prorate.Value.ToString (CultureInfo.InvariantCulture).ToLowerInvariant ());
+ if (TrialEnd != null)
+ sb.AppendFormat ("trial_end={0}&", TrialEnd.Value.ToUnixEpoch ());
+ if (Card != null)
+ Card.UrlEncode(sb);
+ }
+ }
+}
View
30 XamarinStripe/StripeSubscriptionStatus.cs
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2011 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Xamarin.Payments.Stripe {
+ public enum StripeSubscriptionStatus {
+ Unknown,
+ Trialing,
+ Active,
+ PastDue,
+ Canceled,
+ Unpaid
+ }
+}
View
51 XamarinStripe/SubscriptionStatusConverter.cs
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2012 Joe Dluzen
+ *
+ * Author(s):
+ * Joe Dluzen (jdluzen@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
+
+namespace Xamarin.Payments.Stripe {
+ public class SubscriptionStatusConverter : JsonConverter {
+ protected const string PastDue = "past_due";
+
+ public override bool CanConvert (Type objectType)
+ {
+ return objectType == typeof(StripeSubscriptionStatus);
+ }
+
+ public override object ReadJson (JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ {
+ if (reader.TokenType != JsonToken.String)
+ throw new Exception (string.Format ("Unexpected token parsing StripeSubscriptionStatus. Expected String, got {0}.", reader.TokenType));
+
+ string value = reader.Value as string;
+ if (value == PastDue)
+ return StripeSubscriptionStatus.PastDue;
+ return Enum.Parse (typeof(StripeSubscriptionStatus), value);
+ }
+
+ public override void WriteJson (JsonWriter writer, object value, JsonSerializer serializer)
+ {
+ if ((StripeSubscriptionStatus) value == StripeSubscriptionStatus.PastDue)
+ writer.WriteValue (PastDue);
+ else
+ writer.WriteValue (value.ToString ());
+ }
+ }
+}
View
36 XamarinStripe/XamarinStripe.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,7 +10,6 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Xamarin.Payments.Stripe</RootNamespace>
<AssemblyName>XamarinStripe</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -31,10 +30,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Newtonsoft.Json, Version=4.0.2.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\Deps\Newtonsoft.Json.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
@@ -43,6 +38,9 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\Deps\Newtonsoft.Json.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DateTimeExtensions.cs" />
@@ -56,6 +54,32 @@
<Compile Include="StripePayment.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnixDateTimeConverter.cs" />
+ <Compile Include="StripeChargeCollection.cs" />
+ <Compile Include="StripeCvcCheck.cs" />
+ <Compile Include="StripeObject.cs" />
+ <Compile Include="IUrlEncoderInfo.cs" />
+ <Compile Include="StripeCustomerCollection.cs" />
+ <Compile Include="StripeCreditCardToken.cs" />
+ <Compile Include="StripePlan.cs" />
+ <Compile Include="StripePlanInfo.cs" />
+ <Compile Include="StripePlanCollection.cs" />
+ <Compile Include="StripeSubscriptionStatus.cs" />
+ <Compile Include="StripeSubscription.cs" />
+ <Compile Include="StripeSubscriptionInfo.cs" />
+ <Compile Include="StripeInvoiceItem.cs" />
+ <Compile Include="StripeInvoiceItemInfo.cs" />
+ <Compile Include="StripeInvoiceItemCollection.cs" />
+ <Compile Include="StripeInvoice.cs" />
+ <Compile Include="StripeInvoiceCollection.cs" />
+ <Compile Include="StripePeriod.cs" />
+ <Compile Include="StripeInvoiceLineItems.cs" />
+ <Compile Include="StripeInvoiceLineItem.cs" />
+ <Compile Include="StripeCouponInfo.cs" />
+ <Compile Include="StripeCoupon.cs" />
+ <Compile Include="StripeCouponCollection.cs" />
+ <Compile Include="StripeCouponDuration.cs" />
+ <Compile Include="StripePlanInterval.cs" />
+ <Compile Include="SubscriptionStatusConverter.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Please sign in to comment.
Something went wrong with that request. Please try again.