#nshah97

1 messages ยท Page 1 of 1 (latest)

blazing sundialBOT
lofty horizon
#

Hi ๐Ÿ‘‹

What do you mean by a specific product?

digital void
#

I'd like to use the stripe api to get balance transactions that relate to a certain product e.g. all the balance transactions that resulted from the purchase of a certain product

lofty horizon
#

You would need to list all balance transactions, probably filter by type="charge" and expand the source parameter to get the Charge related to the Balance Transaction. Since you are using Products you must be using Checkout Sessions/Payment Links, Invoices, or Subscriptions. So you will need to work backwards to get to the object that has the relationship to the Product.

digital void
#

Would the filtering by product then have to be done on my end? Or is it possible for me to use the stripe api to return the charge-type balance transactions for a given product

lofty horizon
#

What Stripe API are you using to sell Products?

digital void
#

2019-09-09 i believe

#

and the python sdk

lofty horizon
#

No sorry

#

Are you using Checkout? Invoices?

digital void
#

oh lol, subs

lofty horizon
#

Okay so there is a way to get there but it's a little long

digital void
#

im all for it ๐Ÿ’ช

lofty horizon
#

So you can filter a list of Subscriptions by Price (which is related to Product) : https://stripe.com/docs/api/subscriptions/list#list_subscriptions-price
You then list Invoices for those subscriptions: https://stripe.com/docs/api/invoices/list#list_invoices-subscription
When you list the Invoice you expand the related Charge: https://stripe.com/docs/api/invoices/object#invoice_object-charge
and the Balance transaction for the Charge: https://stripe.com/docs/api/charges/object#charge_object-balance_transaction

So your List API call would be stripe.Invoices.list(subscription="sub_xxxxxx", expand=['charge.balance_transaction'])

digital void
#

Right hm, so i basically want to calculate the total revenue generated for each product over a specified period of time.

Using your suggested solution, and for a given product, would the number of requests id be making to stripe be equal to the number of subscriptions that that product has?

lofty horizon
#

Hmmm...wait. No I don't see anything related to either Price or Product IDs there either

digital void
#

Essentially i wanna avoid putting stripe.X.list in a loop ๐Ÿคช

lofty horizon
#

Yeah I understand that

digital void
#

Is it possible via searching Charges?

lofty horizon
#

Charges have no relation to the Product or Price IDs

digital void
#

charge -> invoice -> lines -> price ?

lofty horizon
#

Yup

digital void
#

so that could be viable option?

lofty horizon
#

It would but it may result in as many API calls

digital void
#

i see

#

not ideal then ๐Ÿ˜ฆ

lofty horizon
#

You can always give it a try with a small batch or a single product and review the actual number of API calls and the time it takes

digital void
#

is the stripe api rate limited?

#

but yeah fair, will give it go

lofty horizon
#

100 requests per second in Live mode, 25 requests per second in Test mode

#

But if you retrieve 100 charges per request (limit=100) and process them on a single CPU thread that should slow down your requests enough to not hit the limit

digital void
#

aite cool

#

ill try it out

#

thanks a bunch for your help!!