#sefinek24
1 messages ยท Page 1 of 1 (latest)
You can check the associated invoice with the subscription and look at the billing_reason
This should tell you if the invoice was created for subscription creation or update or something else
https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I dont have billing_reason in the object
https://cdn.sefinek.net/static/01.11.2023/webstorm64_N5A5RQNm9Ta6.png
You're looking at the subscription object
you need to look at the invoice associated with it
it should be under latest_invoice
https://stripe.com/docs/api/subscriptions/object#subscription_object-latest_invoice
still i dont know where it is
latest_invoice is marked as expandable.
So you'd need to retrieve the Subscription when you receive the event while expanding latest_invoice
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i checked other objects and i still can't find this https://cdn.sefinek.net/static/01.11.2023/webstorm64_jf77zgZPSLko.png
Can you share the subscription IDs in text?
sub_1O7fSPGl3RNUcXxRVDoByOQY
and are you making a retrieve subscription API request after you receive the webhook event?
probably not
That's you need (I mentioned that above),
So you'd need to retrieve the Subscription when you receive the event while expanding latest_invoice
https://stripe.com/docs/api/expanding_objects
I have no idea what this code should look like. I've never integrated a payment system on a website before
const subscription = data.object;
const test = await stripe.customers.retrieve(subscription.id, {
expand: ['latest_invoice', 'invoice.subscription'],
});
case 'customer.subscription.updated': {
const subscription = await stripe.subscriptions.retrieve(data.object.id, {
expand: ['latest_invoice'],
});
if (subscription.status === 'canceled') {
await handleCancelledSubscription(verifiedEvent);
} else {
await handleChangedProduct(verifiedEvent);
}
break;
}
can you share the whole subscription object you're getting in the retreive request response?
so latest_invoice: 'in_1O7fm3Gl3RNUcXxRaKFNPBDU', clearly exists
you're not expanding it correctly
and what should i do with this?
'sub_xxxx',{
expand: ['latest_invoice'],
}
);```
can you print out subscription after you call retreive and before it hits
```if (subscription.status === 'canceled') {
await handleCancelledSubscription(verifiedEvent);
} else {
await handleChangedProduct(verifiedEvent);
}```?
i dont completely understand. could you send me the readymade code for how it should look?
I can't write your code for you, I gave you clear instructions above.
I don't understand them because I've never dealt with payment integration before. as for my current code, I had someone else write it, and now I want to improve it to meet my requirements
nevermind, i read what you wrote a second time and I understood ^-^
It isn't related to any payment related code though
It just programming basics
ah good ๐
Awesome!
thanks