Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Stripe;
- using Xamarin.Forms;
- namespace BankPayment.SubscriptionModelPayment
- {
- public partial class SubscriptionPayment : ContentPage
- {
- public SubscriptionPayment()
- {
- InitializeComponent();
- }
- public void ProductAClicked(object sender,EventArgs e)
- {
- StripeConfiguration.ApiKey = "sk_test_3lcS4wFQ32q0qVWaOabxtux700mQEP1sYq";
- //It's your selling Item
- var service = new ProductService();
- Product product = service.Create(new ProductCreateOptions
- {
- Name = "20 $ Monthly USD",
- Type = "service",
- });
- //It's how much you will be charged per product.
- var planoptions = new PlanCreateOptions
- {
- Currency = "usd",
- Interval = "month",
- Nickname = "Pro Plan",
- Amount = 20,
- Product = product.Id,
- };
- var productservice = new PlanService();
- Plan plan = productservice.Create(planoptions);
- //create subscription to the plan :
- var items = new List<SubscriptionItemOption> {
- new SubscriptionItemOption {
- PlanId = planoptions.Id
- } };
- //Create a customer so that it is going to subscribed to that subscription request
- // 1 . At first create card
- Stripe.CreditCardOptions stripcard = new Stripe.CreditCardOptions();
- stripcard.Number = "4000000000003055";
- stripcard.ExpYear = 2020;
- stripcard.ExpMonth = 08;
- stripcard.Cvc = "199";
- //2. Assign Card to Token Object and create Token
- Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions();
- token.Card = stripcard;
- Stripe.TokenService serviceToken = new Stripe.TokenService();
- Stripe.Token newToken = serviceToken.Create(token);
- //3. Create a new customer and you can do what ever with customer ID that you got
- Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions()
- {
- Description = "Customer for jenny.rosen@example.com",
- Source = "tok_amex"
- };
- var customerService = new Stripe.CustomerService();
- Stripe.Customer stripeCustomer = customerService.Create(myCustomer);
- //Now we have our customer generated. Our last option is to get teh custome id to the subscription module.
- var subscriptionoptions = new SubscriptionCreateOptions
- {
- CustomerId = stripeCustomer.Id,
- Items = items
- };
- var subscriptionservice = new SubscriptionService();
- Subscription subscription = subscriptionservice.Create(subscriptionoptions);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement