Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirming how to use Stripe.net Customer on a plan

I am new to stripe and have decided to use stripe.net (https://github.com/jaymedavis/stripe.net).

What I want to do is put the customer on a plan that will charge them monthly. I also want to give them the option to cancel their subscription to the plan. Here is the code that the stripe.net project shows to use.

StripeConfiguration.SetApiKey("[your api key here]");

var myCustomer = new StripeCustomerCreateOptions();

// set these properties if it makes you happy
myCustomer.Email = "[email protected]";
myCustomer.Description = "Johnny Tenderloin ([email protected])";

// set these properties if using a card
myCustomer.CardNumber = "4242424242424242";
myCustomer.CardExpirationYear = "2012";
myCustomer.CardExpirationMonth = "10";
myCustomer.CardAddressCountry = "US";            

myCustomer.PlanId = *planId*;                         

var customerService = new StripeCustomerService();
StripeCustomer stripeCustomer = customerService.Create(myCustomer);

Is this all I have to do to put the customer on a plan that charges them monthly? and to cancel the plan...

var customerService = new StripeCustomerService();
StripeSubscription subscription = customerService.CancelSubscription(*customerId*);

Is this all I have to do? There is also a section on the stripe.net page for creating a charge and I'm not sure if I have to do anything with that.

like image 340
Clay Smith Avatar asked Sep 13 '13 20:09

Clay Smith


People also ask

How do I confirm payment intent on Stripe?

Use stripe. confirmPaymentIntent(clientSecret, data) to confirm the PaymentIntent when you are not gathering payment information from an Element . Call this variation when you have already attached a payment method to this PaymentIntent , or if you want to attach an existing card, token, or PaymentMethod to it.


2 Answers

Yep, that's it. Were you expecting something more painful based on past experience? ;)

The Stripe API is designed to be really easy to use, and most of the available libraries (including Stripe.net) strive to maintain that.

You don't have to do anything with charges. If you need to bill a customer for some one-off thing, like a hat maybe, that's what a charge is for. Plans take care of themselves.

like image 118
colinm Avatar answered Sep 27 '22 18:09

colinm


With the latest Stripe API, StripeCustomerService does no longer support the CancelSubscription method. Here is one way to cancel a subscription for a customer:

        var subscriptionService = new StripeSubscriptionService();
        var subscriptions = subscriptionService.List(account.StripeCustomerId);

        foreach (var subscription in subscriptions)
        {
            if (subscription.CanceledAt == null)
                subscriptionService.Cancel(account.StripeCustomerId, subscription.Id);
        }
like image 27
Thomas Jaeger Avatar answered Sep 27 '22 18:09

Thomas Jaeger