Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Stripe;
  4. using Xamarin.Forms;
  5.  
  6. namespace BankPayment.SubscriptionModelPayment
  7. {
  8. public partial class SubscriptionPayment : ContentPage
  9. {
  10. public SubscriptionPayment()
  11. {
  12. InitializeComponent();
  13. }
  14.  
  15.  
  16. public void ProductAClicked(object sender,EventArgs e)
  17. {
  18. StripeConfiguration.ApiKey = "sk_test_3lcS4wFQ32q0qVWaOabxtux700mQEP1sYq";
  19.  
  20.  
  21. //It's your selling Item
  22. var service = new ProductService();
  23. Product product = service.Create(new ProductCreateOptions
  24. {
  25. Name = "20 $ Monthly USD",
  26. Type = "service",
  27. });
  28.  
  29.  
  30. //It's how much you will be charged per product.
  31.  
  32. var planoptions = new PlanCreateOptions
  33. {
  34. Currency = "usd",
  35. Interval = "month",
  36. Nickname = "Pro Plan",
  37. Amount = 20,
  38. Product = product.Id,
  39. };
  40.  
  41. var productservice = new PlanService();
  42. Plan plan = productservice.Create(planoptions);
  43.  
  44. //create subscription to the plan :
  45.  
  46. var items = new List<SubscriptionItemOption> {
  47. new SubscriptionItemOption {
  48. PlanId = planoptions.Id
  49. } };
  50.  
  51. //Create a customer so that it is going to subscribed to that subscription request
  52.  
  53. // 1 . At first create card
  54.  
  55. Stripe.CreditCardOptions stripcard = new Stripe.CreditCardOptions();
  56. stripcard.Number = "4000000000003055";
  57. stripcard.ExpYear = 2020;
  58. stripcard.ExpMonth = 08;
  59. stripcard.Cvc = "199";
  60.  
  61. //2. Assign Card to Token Object and create Token
  62.  
  63. Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions();
  64. token.Card = stripcard;
  65. Stripe.TokenService serviceToken = new Stripe.TokenService();
  66. Stripe.Token newToken = serviceToken.Create(token);
  67.  
  68.  
  69. //3. Create a new customer and you can do what ever with customer ID that you got
  70.  
  71. Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions()
  72. {
  73. Description = "Customer for jenny.rosen@example.com",
  74. Source = "tok_amex"
  75. };
  76. var customerService = new Stripe.CustomerService();
  77. Stripe.Customer stripeCustomer = customerService.Create(myCustomer);
  78.  
  79.  
  80. //Now we have our customer generated. Our last option is to get teh custome id to the subscription module.
  81.  
  82.  
  83. var subscriptionoptions = new SubscriptionCreateOptions
  84. {
  85. CustomerId = stripeCustomer.Id,
  86. Items = items
  87. };
  88.  
  89. var subscriptionservice = new SubscriptionService();
  90. Subscription subscription = subscriptionservice.Create(subscriptionoptions);
  91.  
  92. }
  93.  
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement