#ares_api

1 messages ยท Page 1 of 1 (latest)

wanton lotusBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1371453468648276089

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

tiny cipher
#

Hi

#

I have upgraded to the stripe node sdk to v18 and I am no longer able to get charges related to a subscription id this way:

const { data: invoices } = await stripe.invoices.list(
{
subscription: subscriptionId,
expand: ['data.charge'],
limit,
},
{ stripeAccount: gatewayAccountId }
);

const charges = [];
invoices.slice(offset, offset + limit).forEach((invoice) => {
const { charge } = invoice;
...
});

knotty fractal
#

๐Ÿ‘‹ happy to help

#

yes this is normal

tiny cipher
#

what does that mean?

knotty fractal
#

each major SDK version is bound to an API version

tiny cipher
#

right i am using that version actually. I am trying to see if there is a way now to get the related charges from a subscription ID

knotty fractal
#

and we introduced a breaking change in the basil API version

#

where invoices are now capable of being paid into several payments

#

for more info

tiny cipher
#

i have gone through this I am not able to understand this particular use case I have, get all charge related to a subscripiton. If you can help me with how this can be done?

wanton lotusBOT
tiny cipher
#

?

lilac cedar
lilac cedar
tiny cipher
#

sure

lilac cedar
#
await stripe.invoices.list({
  subscription: subscriptionId,
  expand: ['payments.data.payment.charge'],
  limit,
}, {
  stripeAccount: gatewayAccountId
});
#

Should work

wanton lotusBOT
tiny cipher
#

so this returns a charges array?

lilac cedar
#

It'll return a list/array of payments

#

Each of which will only have one charge

tiny cipher
#

okay that is helpful

#

thanks a lot man

#

just last thing, can you point me to the api doc url where this is expplained mostly the expand part

lilac cedar
#

What do you need help understanding? The expand concept, or something else?

tiny cipher
#

the expand concept

lilac cedar
tiny cipher
lilac cedar
#

Ah yeah. It's because you're using a list endpoint. So it'd be: data.payments.data.payment

#

I don't think you can add charge there as it'll exceed depth limit (4)

tiny cipher
#

so the above suggesstion won't work then

  subscription: subscriptionId,
  expand: ['payments.data.payment.charge'],
  limit,
}, {
  stripeAccount: gatewayAccountId
});

lilac cedar
#

I don't believe so, you'd need to make an additional API request using the charge property to retrieve the full Charge object

tiny cipher
#

that call will be based on which param?

lilac cedar
#

data.payments.data.payment.charge

#

That'll be the ch_xxx ID

tiny cipher
#

"message": "You cannot expand more than 4 levels of a property. Property: data.payments.data.payment.charge",

tiny cipher
#

you said to make an additional charge request after i list the invoices. I don't see any helpful data param i can use to fetch the charges.

lilac cedar
tiny cipher
#

so this expansion is allowed using the sdk?

lilac cedar
#

Make this API call:

await stripe.invoices.list({
  subscription: subscriptionId,
  expand: ['data.payments.data.payment'],
  limit,
}, {
  stripeAccount: gatewayAccountId
});

And then data.payments.data.payment.charge will be a ch_xxx ID

tiny cipher
#

okay let me try this and see how it works for me.

#

thank you for you support, really appreciate it.

#

tried it this way

async function fetchData() {
  const response = await stripe.invoices.list({
    subscription: subscriptionId,
    expand: ['data.payments.data.payment'],
    limit,
  });

  // Loop through the returned invoices
  for (const invoice of response.data) {
    console.log(`Invoice ID: ${invoice.id}`);

    const payments = invoice.payments?.data || [];

    for (const paymentRecord of payments) {
      const chargeId = paymentRecord?.payment?.charge;

      if (chargeId) {
        console.log(`Charge ID: ${chargeId}`);
      } else {
        console.log('No charge found in payment record.');
      }
    }
  }
}

so for this subscriptionId, even though I have charges for this subscription, I am seeing

No charge found in payment record

lilac cedar
#

What's the in_xxx ID?

tiny cipher
lilac cedar
#

What's the payments property JSON look like in the response?

#

In which case you'd retrieve the Payment Intent using that field and expand latest_charge

tiny cipher
# lilac cedar What's the `payments` property JSON look like in the response?
[{"id":"inpay_1RNHhRS96f9fdn2rCEQtpNDk","object":"invoice_payment","amount_paid":2000,"amount_requested":2000,"created":1746900037,"currency":"eur","invoice":"in_1RNGlCS96f9fdn2r6ltzWURu","is_default":true,"livemode":false,"payment":{"payment_intent":"pi_3RNHhRS96f9fdn2r1JJgF2AT","type":"payment_intent"},"status":"paid","status_transitions":{"canceled_at":null,"paid_at":1746900038}}]
#

yeah it is a payment_intent

lilac cedar
#

And there you can expand: ['latest_charge']

#

Sorry this is so convoluted now ๐Ÿ˜ฆ

wanton lotusBOT
tiny cipher
#

got it

#

tested and this is working now

#

lots of go around needed in new api version

#

thank you!