How to get charge id after creating a subscription using Stripe?

后端 未结 6 2312
忘掉有多难
忘掉有多难 2021-02-13 21:36

I am using Stripe as a payment gateway. Now there\'s a big problem bothers me.

I used code below to create a subscription:



        
6条回答
  •  别那么骄傲
    2021-02-13 22:07

    This is exactly what Stripe's webhooks are for. After creating a customer with an initial subscription, you'll get six webhook notifications:

    1. customer.created, with the customer data (which you already have if you're saving what the API returns)
    2. charge.succeeded (or charge.failed), which contains the initial charge data you're looking for
    3. invoice.created, which is the associated invoice
    4. invoice.payment_succeeded (or invoice.payment_failed), also telling you the status of the charge
    5. customer.card.created, with the details of the new card
    6. customer.subscription.created, with the details of the customer's subscription.

    Stripe's API, like many APIs and many payment solutions, is built to be used with webhooks. If you're not taking advantage of webhooks, you're going to be missing functionality, and you're probably working too hard for what can be done without webhooks.

    Stripe works to deliver the data to you. If you're writing code to poll Stripe, you're working way, way too hard.

提交回复
热议问题