4
votes

I just updated my code to Stripe Payment Intents API and I want to make a subscription to a plan just after the payment.

  • When the customer installs the app, a subscription to it is created with a trial period
  • When he wants to pay for a longer period, he goes on a page in which he first select the plan he wants, then fill his customer informations (name, mail etc.).

  • Then I make a post request to /payment_intents with these four informations:

    • amount (Amount of the plan)

    • currency

    • payment_method_type[]

    • customer

  • I then send the client_secret returned by the request to my js script in order to process the payment.

If the payment succeeds I update the subscription on POST /subscription/id and set trial_end=now

But on the Dashboard, I see on my customer page there was two payments: Customer Payments

I (think I) know the second charge is made by the subscription, but how can I make a subscription without creating a new charge ?

Thanks for any help!

1

1 Answers

10
votes

If the payment succeeds I update the subscription on POST /subscription/id and set trial_end=now

That immediately ends the trial period on the subscription and causes it to immediately try to charge the customer. So that's why you have two charges — one from the payment intent, and one from ending the trial period.

I don't quite understand your flow here though. Usually you would do this in the opposite way :

  1. Create the payment intent and process the payment.
  2. When that succeeds, then create the subscription and set trial_end=now+30days (for example, if you are using a 30-day billing period), because the customer has already paid for that upcoming period via the payment intent.

EDIT : to anyone reading this more recently, Billing supports PaymentIntents natively now(each invoice uses a PaymentIntent), so you don't need to use this trial period approach. https://stripe.com/docs/billing/subscriptions/payment has the current approach to use!