#WhySoAsync-subscription-creation
1 messages ยท Page 1 of 1 (latest)
Hello ๐
Can you provide more information about your integration? How are you fetching clientSecret, Example code etc
Hi, sure
i create the subscription with
`` const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{
price: priceId,
}],
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
});
res.send({
subscriptionId: subscription.id,
clientSecret: subscription.latest_invoice.payment_intent.client_secret,
});``
on POST 200 i have client secret and i can pay
but if i refresh page i loose that clientSecret from POST 200
and i wanna get it with
`` const subscription = await stripe.subscriptions.retrieve(
subscriptionId
);
console.log('subscription', subscription);``
retry-subscription POST route that gets clientSecret gets it back and uses on frontend
stripe.confirmCardPayment(clientSecret).then(({ paymentIntent }) => { if (paymentIntent?.status === 'succeed') { refresh(); } });
ah I see so you'd want to expand expand: ['latest_invoice.payment_intent'] when you retrieve the subscription again
Yeah !!
const subscription = await stripe.subscriptions.retrieve(
subscriptionId,
expand: ['latest_invoice.payment_intent']
);
Oh nice !! But this is the way to retry payment right? is the flow okay?
Yup it I'm reading the code correctly, it won't create any additional/unnecessary objects
.retrieve(
subscriptionId,
expand: ['latest_invoice.payment_intent']
);
should be an object there?
yup a subscription object
const subscription = await stripe.subscriptions.retrieve({
subscriptionId,
expand: ['latest_invoice.payment_intent']
});
if i use it like this
Stripe: Argument "subscriptionExposedId" must be a string, but got: [object Object] (on API request to GET /subscriptions/{subscriptionExposedId}
i get this
the 2nd param of retrieve function cannot be a key value that's why i used object
Try
const subscription = await stripe.subscriptions.retrieve(
subscriptionId, {
expand: ['latest_invoice.payment_intent']
});
I get the client secret now! Thanks
Awesome! Glad that worked ๐
A payment method of type card was expected to be present, but this PaymentIntent does not have a payment method and none was provided. Try again providing either the payment_method or payment_method_data parameters.
I get this on stripe.confirmCardPayment