#chooke

1 messages ยท Page 1 of 1 (latest)

carmine yokeBOT
winged light
weary tinsel
#

req_qKJakUrqA7ewWT

winged light
weary tinsel
#

i tried to do that , but it didnt work ,as i have 2 products ,
app.get("/get-subscription", async (req: Request, res: Response) => {
const { customer } = req.query;
try {
const subscription = await stripe.subscriptions.list({
customer: customer?.toString() || "",
expand: ["items.data.price.product"],
});
console.log(subscription.lastResponse.requestId);
res.status(200).send(subscription);
} catch (err) {
res.status(500).send(getErrorMessage(err));
}
});

winged light
#

what does it didn't work mean? are you getting an error?

weary tinsel
#

sorry , so i get [TypeError: Cannot read property 'data' of undefined]

#

so this is the subscription id (sub_1MUQbgC68fMI8JtvRNEZs5y8) i have 2 products in it , when i have only 1 , i was able t expand on the items/plan , but after adding a new product , i get null value for plan field

winged light
#

you shouldn't be referring to the plan field

#

what's the aim here? what specific data are you trying to retrieve? i.e. is it the Price id, or maybe the Product id?

weary tinsel
#

so im trying to get the product from the subscription

winged light
#

i see you return the subscription object in your response

#

how are you accessing the plan in your frontend? can you share the code for that?

weary tinsel
#

if i expand on items , i cant get even the subscription
const subscriptions = await fetchStripeAccount( `${stripeEndpointUrl}/get-subscription?customer=${customerId}`, accountGetRequestOptions, );
this is how i call the endpoint

winged light
#

to expand the Price for a Subscription, this should be what you expand - data.items.data.price

#

you can only expand up to 4 levels deep. So if you want more details about the Product (besides just the id) this probably isn't the best solution

winged light
#

the reason why i don't recommend using Plans is that it's considered as deprecated at this point. If you're attempting to access Subscription.plan -> it will be null if you have more than one item on the Subscription

weary tinsel
#

ohh thats why , so what would be the best approach to handle this , can you recommend me a better way to get to the plan details

winged light
#

that's why i mentioned accessing the Price instead

weary tinsel
#

that means i have to do extra api calls to get the product since we can access 4 levels deep only :/

winged light
#

why do you want to get the product? and what details of the product specifically?

weary tinsel
#

so we have an app , that users can subscribe to a plan , in one of the plans users can add extra staff , so that means adding an extra product to the subscription items , what we are trying to do is to display the current subscription and the product details like the name , price

#

since some subscriptions can have 2 products , and this is why i had that issue with null value, i need a better way to get the subscription and the product details , but only the product that is not for adding extra staff ,

#

this sounds complicated ๐Ÿ˜…

winged light
#

what i would do is to save the relevant details to your own DB, and query it directly from your DB. Otherwise, there's no real alternative here, you just have to make an additional API call