#shayan-shokat_code
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/1271092593203220582
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello
Can you clarify your flow here? How are you collecting a PaymentMethod currently?
customer: customer.id,
items: [
{
price: priceId,
},
],
coupon: coupon ? coupon.id : null,
payment_behavior: "default_incomplete",
// expand: ["latest_invoice.payment_intent"],
metadata: {
discount: amountOff / 100,
for: "new subscription",
},
});
const invoice = await stripe.invoices.retrieve(
subscription.latest_invoice
);
const paymentIntentId = invoice.payment_intent;
const paymentIntent = await stripe.paymentIntents.retrieve(
paymentIntentId
);
await stripe.paymentIntents.update(paymentIntentId, {
metadata: {
discount: amountOff / 100,
for: "new subscription",
},
});
const clientSecret = paymentIntent.client_secret;
const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: user["stripeCustomerId"] },
{ apiVersion: "2020-03-02" }
);
ok so first we generate clientSecret and ephemeralKey to pass on to mobile app to open 3D secure sheet of stripe
and in that sheet it completes the payment
but that subscription doesn't have default_payment_method attached with it so if we want to change the plan or at changing billing cycle, payment can't be charged
First, you want to use expansion when you create your Subscription instead of making a separate Invoice retrieval request. So you want expand: ['latest_invoice']. See: https://docs.stripe.com/expand for more info on how expansion works
Second, you want to set payment_settings.save_default_payment_method: 'on_subscription' when you create your Subscription: https://docs.stripe.com/api/subscriptions/create#create_subscription-payment_settings-save_default_payment_method
Now once the payment succeeds then the PaymentMethod will be set as the default for that Subscription.
Do both those things, test again, and let me know if you still have any issues!