Saturday, 30 November 2019

stripe: Create a 30-day trial subscription charge on a saved card but allow user to upgrade and start charging immediately?

So before a user can create an account I want to save their credit card to charge a subscription with 30 day trial AND the ability to immediately charge the card for a subscription if the user demands it.

so my logic is to

1) create a customer

2) add payment details for customer

3) create subscription with 30 day trial

4) activate subscription upon user upgrade action

I'm not clear on how 4) is possible. I get that on 3), after 30 days, they are on a subscription. but what if the customer wants to start using the full version immediately before the trial is over, how would I create a charge for the subscription?

const stripe = require('stripe')('sk_test_asdfasdf');
(async () => {
  // Create a Customer:
stripe.customers.create({
  email: 'jenny.rosen@example.com',
  payment_method: 'pm_1FWS6ZClCIKljWvsVCvkdyWg',
  invoice_settings: {
    default_payment_method: 'pm_1FWS6ZClCIKljWvsVCvkdyWg',
  },
}, function(err, customer) {
  // asynchronously called
});

//create subscription
stripe.subscriptions.create({
  customer: 'cus_4fdAW5ftNQow1a',
  items: [
    {
      plan: 'plan_CBXbz9i7AIOTzr',
    },
  ],
  expand: ['latest_invoice.payment_intent'],
}, function(err, subscription) {
    // asynchronously called
  }
);

})();


from stripe: Create a 30-day trial subscription charge on a saved card but allow user to upgrade and start charging immediately?

No comments:

Post a Comment