Retrieving charges by subscription

420 views
Skip to first unread message

Tom Dibaja

unread,
Nov 14, 2017, 7:48:40 AM11/14/17
to api-d...@lists.stripe.com
Hello,

Is there any way to retrieve all past charges under a given subscription, or to have a Charge object contain a reference to the parent subscription, if it exists?

I'm able to get all Charges by customer_id but this is a raw list of charges that I'm unable to relate to subscriptions. In my case, customers often have multiple subscriptions over time. 

Thanks,
Tom

Olivier Bellone

unread,
Nov 14, 2017, 7:53:58 AM11/14/17
to api-d...@lists.stripe.com
Hey Tom,

Charges are not directly linked to subscriptions, however they do have an `invoice` attribute[1], and invoices have a `subscription` attribute[2].

When retrieving a charge[3], you can use the expanding feature[4] to directly expand the `invoice` attribute into a full invoice object so you don't have to retrieve it separately.

If you want to retrieve all charges for a given subscription, you can do so by listing all invoices[5] with the `subscription` parameter[6]. Each invoice has a `charge` attribute[7] that you can use to retrieve the charge for that invoice.

You can use the expanding feature there too, by including `data.charge` in the expand list so that the charge objects are directly expanded in the list of invoice objects that is returned by the API.

Hope this helps!

Best,
Olivier



--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Tom Dibaja

unread,
Nov 14, 2017, 10:30:24 AM11/14/17
to api-d...@lists.stripe.com
Hi Olivier,

Thanks for the quick response.

Yes, that helps. Retrieving all invoices for a given subscription ID and then getting the charges through those works perfectly.

Best,
Tom

To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.

To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.
Reply all
Reply to author
Forward
0 new messages