Permalink
Browse files

Merge pull request #2 from jdluzen/master

New features
  • Loading branch information...
2 parents 59a0f46 + 381ae89 commit f137e6089566895b0d0ae69334543ba6f38af920 @gonzalop gonzalop committed Feb 22, 2012
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
@@ -0,0 +1,8 @@
+syntax: glob
+PaymentTest/bin/*
+XamarinStripe/bin/*
+*.userprefs
+*.pidb
+PaymentTest/obj/*
+XamarinStripe/obj/*
+*.suo
@@ -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
@@ -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
@@ -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
@@ -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);
+ }
+}
@@ -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; }
}
}
@@ -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; }
}
Oops, something went wrong.

0 comments on commit f137e60

Please sign in to comment.