#WhySoAsync-subscription-creation

1 messages ยท Page 1 of 1 (latest)

outer seal
#

Hello ๐Ÿ‘‹
Can you provide more information about your integration? How are you fetching clientSecret, Example code etc

restive wedge
#

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(); } });

outer seal
#

ah I see so you'd want to expand expand: ['latest_invoice.payment_intent'] when you retrieve the subscription again

restive wedge
#

Yeah !!

outer seal
#

const subscription = await stripe.subscriptions.retrieve(
subscriptionId,
expand: ['latest_invoice.payment_intent']
);

restive wedge
#

Oh nice !! But this is the way to retry payment right? is the flow okay?

outer seal
#

Yup it I'm reading the code correctly, it won't create any additional/unnecessary objects

restive wedge
#

.retrieve(
subscriptionId,
expand: ['latest_invoice.payment_intent']
);

#

should be an object there?

outer seal
#

yup a subscription object

restive wedge
#

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

outer seal
#

Try

const subscription = await stripe.subscriptions.retrieve(
subscriptionId, {
expand: ['latest_invoice.payment_intent']
});

restive wedge
#

I get the client secret now! Thanks

outer seal
#

Awesome! Glad that worked ๐Ÿ™‚

restive wedge
#

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