#brettski-node-expansion

1 messages · Page 1 of 1 (latest)

kindred cradle
#

@silk kraken mostly no you're misunderstanding expansion right now

silk kraken
#

Basing it off of what I did for expanding lineitems from a checkout, so that is completely possible

kindred cradle
#

The goal of expansion is to take a specific object, say an Invoice, and when you retrieve that Invoice, instead of seeing subscription: 'sub_123' and then have to separately call https://stripe.com/docs/api/subscriptions/retrieve you can explicitly expand the whole Subscription object in the same call

So if you retrieve an Invoice, your code should be callin stripe.invoices.retrieve(...) but for some reason you already have the Subscription id, explicitly call the Retrieve Subscription API (https://stripe.com/docs/api/subscriptions/retrieve) and in that case there's no reason to try to expand

silk kraken
#

The invoice comes to me in a invoice.paid webhook event

#

So I need to request the invoice again, with the subscription section expanded

kindred cradle
#

Okay so you have 2 options
1/ You look at the invoice id in_123 and you call https://stripe.com/docs/api/invoices/retrieve to retrieve the whole invoice again and also you expand the Subscription
2/ You already have the Invoice object, all you want is the information about the Subscription so you look at the subscription id in subscription on that Invoice and then you call https://stripe.com/docs/api/subscriptions/retrieve to retrieve the Subscription (no reason to expand)

silk kraken
#

okay.

kindred cradle
#

Does that make sense? I know expansion can be a bit confusing until it clicks

silk kraken
#

So something like this to get re-fetch the invoice with the subscription expanded:

  return stripe.invoice.retrieve(invoiceId, {
    expand: ['invoice.subscription'],
  });
kindred cradle
#

not exactluy

#

what you put in expand is the exact path to the property. The property is subscription

#

though since you already have the Invoice object (it's in the event payload) there's usually no reason to re-retrieve the whole invoice

silk kraken
#

okay, that tracks

#

Suggestions on test data? I don't have any current test subscriptions.

Do I create a few subscriptions then generate invoices for them to pay?

kindred cradle
#

yep that's the best option

silk kraken
#

Okay. Thank you again for your time and assistance

kindred cradle
#

Of course! Please don't hesitate if you have more questions, we're happy to help 🙂