#ares_api
1 messages ยท Page 1 of 1 (latest)
๐ 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.
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;
...
});
what does that mean?
each major SDK version is bound to an API version
you can look here https://github.com/stripe/stripe-node/releases/tag/v18.1.0
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
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
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?
?
You'd just the payments property on the Invoice object now instead: https://docs.stripe.com/api/invoices/object#invoice_object-payments
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Please be patient, we're helping other users too
sure
await stripe.invoices.list({
subscription: subscriptionId,
expand: ['payments.data.payment.charge'],
limit,
}, {
stripeAccount: gatewayAccountId
});
Should work
so this returns a charges array?
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
What do you need help understanding? The expand concept, or something else?
the expand concept
the reason I asked is when I am testing this using postman this doesn't work,
for example:
https://api.stripe.com/v1/invoices?subscription='sub_id'&expand[]=payments.data.payment.charge
returns
{
"error": {
"message": "This property cannot be expanded (payments). You may want to try expanding 'data.payments' instead.",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_hyMw1osfApwSJq?t=1747052128",
"type": "invalid_request_error"
}
}
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)
so the above suggesstion won't work then
subscription: subscriptionId,
expand: ['payments.data.payment.charge'],
limit,
}, {
stripeAccount: gatewayAccountId
});
I don't believe so, you'd need to make an additional API request using the charge property to retrieve the full Charge object
that call will be based on which param?
"message": "You cannot expand more than 4 levels of a property. Property: data.payments.data.payment.charge",
Yep, as I said above
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.
This property
so this expansion is allowed using the sdk?
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
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
What's the in_xxx ID?
in_1RNGlCS96f9fdn2r6ltzWURu
What's the payments property JSON look like in the response?
I bet that paymentRecord.payment.type is payment_intent: https://docs.stripe.com/api/invoices/object#invoice_object-payments-data-payment-type
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
In which case you'd retrieve the Payment Intent using that field and expand latest_charge
[{"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
OK, then use the pi_xxx ID from the payment.payment_intent field with this API: https://docs.stripe.com/api/payment_intents/retrieve
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
And there you can expand: ['latest_charge']
Sorry this is so convoluted now ๐ฆ