简体   繁体   中英

List all non-subscription charges in Stripe

I am making an e-commerce web app, users can purchase physical products via stripe and users can subscribe to different plans such as Lite, Premium, Standard, etc.

case-1: For checkout of physical products, I use:

stripe.charges.create()

case-2: For Subscriptions, I use:

stripe.subscriptions.create()

What I want is to retrieve a list of ONLY checkout charges (made via case-1, not case-2), I use

stripe.charges.list()

but It retrieves all charges including subscriptions which is not wanted.

How can I get all charges which are of non-subscription charges, is there any filter available in Stripe or an alternate method is available?

Unfortunately, the List Charges API doesn't have any parameters that you can use to specify that you only want charges associated with invoices:

https://stripe.com/docs/api/charges/list

That being said though, you can list all the Charges within a given window and filter them manually. Any charge that is associated with a subscription will have its invoice field populated:

https://stripe.com/docs/api/charges/object#charge_object-invoice

That is, if the Charge is linked to an invoice then it (most likely) came from a subscription. Otherwise it was a Charge for a physical product. This of course assumes that you aren't creating one-off invoices manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM