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

后端 未结 6 2307
忘掉有多难
忘掉有多难 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 21:54

    I just ran into the same issue myself. I'm using the python library but the answer is more about Stripe's API than what language the client is in.

    Ultimately, since I'm creating a new customer with each subscription, I was able to look up the invoice against the customer_id and grab its charge id. Here's what the python code for that looks like:

    stripe_api.Invoice.all(customer=subscribe_result['customer'])['data'][0]['charge']
    

    Again, note that this method would not work if you re-use customers, only if creating new customers with each subscription create.

    It's certainly not ideal. It would be far better if the charge id were included in the return. Even knowing the Invoice ID would at least solve the issue of re-using customers though it would still require an unnecessary API call to fetch the invoice.

提交回复
热议问题