#kashi3029
1 messages · Page 1 of 1 (latest)
Hello
Hello! Just to make sure I have this right - you have an existing subscription and you want to update it and you're wondering how to handle when the saved card needs 3DS to complete payment?
Yes right
const subscription = await stripe.subscriptions.update(subscriptionId, {
items: [
{
id: currentSubscription.items.data[0]?.id,
deleted: true,
},
{
price: priceId,
},
],
proration_behavior: "always_invoice",
});
I am calling this funtion on click of upgrade button
Hello! I'm taking over and catching up...
After you run that you can check the status of the Payment Intent on the Invoice that's generated. If the status is requires_action you can then handle that action client-side by passing the Payment Intent's client secret to your frontend and handling it with our client-side library.
Let me check
Can you share doucment which code I need to impliment frontend side?
@shut cipher
Yes, but it depends on what you're using. Is this on the web? In a mobile app?
You can use stripe.handleNextAction: https://stripe.com/docs/js/payment_intents/handle_next_action
You need to expand the invoice and then expand the payment_intent on the Invoice.
Err, latest_invoice.
So you need to expand latest_invoice.payment_intent and then check the status of the Payment Intent.
Do I need to call one more API call am I right?
No, you can add the expansion to your stripe.subscriptions.update request.
Okay
Do I need to call frontend side or backend side?
You call that client-side, on your website, so your customer can complete the next action.
const data = await stripe.handleNextAction({
clientSecret:
"pi_3O0SfSGXQ7blAdt60RgLrEGn_secret_jSntdTlTiI3o7PUl7nn8CLQC9",
});
this is my code
Can you share the code you used to initialize Stripe.js?
<Elements stripe={stripePromise}>
<Passes isHomePage={false} />
</Elements>
const stripePromise = loadStripe(stripeKey);
Hm, odd. For some reason stripe seems to be null instead of the instance of stripe you're initializing there.
Any luck?
Yes It working now I have only open quetion is if in some case if user payment status is open how can I give option users to do payment again
Not sure what you mean, can you provide more details?
Leave it all working fine for now
If some case my plan upgrade got not successfull how I can give my user to old subscription back in stripe becasue currenlly when I upgrading my subscripton and it got failed than my current subscription showing payment pending with new subscriotion
@shut cipher
Can you send me the ID of the subscription that you are seeing this on?
And when you say the upgrade was not successful, do you mean that the update subscription call got an error? Or did the payment for the upgrade get a decline? Or something else?
sub_1O0U87GXQ7blAdt68ufGvDOg
I have upgrade payment and I opened 3d secure authrntication but I have not complate that but on stripe my plan has been added with payment incomplate status also now my current plan is that now how can I move back to old plan
@quick fable
I am not seeing 3DS or the other things that you mentioned on that subscription. In future it may be helpful to use our pending updates functionality, it reverts an update if the payment on the prorations fails
Can you share that code?
Apologies, meant to link to the doc https://stripe.com/docs/billing/subscriptions/pending-updates
So logic will be like if I got pending_update I will not need to update my payment details on my db am right or stripe itselft will not trigger subscription update event also pending_update hash will come when autopayment will be made? or it will come only when I upgrading plans?
@quick fable
If you specify proration_behavior="always_invoice" Stripe will try to charge the saved payment on file immediately. You shouldn't need to update any payment method details
stripe itselft will not trigger subscription update event also pending_update hash will come when autopayment will be made? or it will come only when I upgrading plans?
I am not clear on what this part means. Can you try explaining it again?
So pending_update how can I use this hash how can that helpfull for me that I am asking
Currently when upgrade my plan and update subscription event has been trigger and payment status has been updated paid to open I don't want to change payment status untill whole payment process has been complated if in between error comes in so my current plan has not been affected
@quick fable
Checking in to this, I don't think that the status will change immediately. It should remain active even though there are pending updates
const customerSubscriptionUpdated = data.object;
try {
if (customerSubscriptionUpdated?.pending_update) {
console.log(
"Subscription update is pending. Payment may have failed."
);
} else {
var result = await Model.Payment.update(
{
PlanID: customerSubscriptionUpdated.plan.id,
StripeEndDate: customerSubscriptionUpdated.current_period_end,
StripeStartDate: customerSubscriptionUpdated.current_period_start,
StripeCancelDate: customerSubscriptionUpdated.canceled_at || null,
StartDate: moment
.unix(customerSubscriptionUpdated.current_period_start)
.format("yyyy-MM-DD hh:mm:ss A"),
EndDate: moment
.unix(customerSubscriptionUpdated.current_period_end)
.format("yyyy-MM-DD hh:mm:ss A"),
CancelDate: customerSubscriptionUpdated?.canceled_at
? moment
.unix(customerSubscriptionUpdated.canceled_at)
.format("yyyy-MM-DD hh:mm:ss A")
: null,
IsRecurring: customerSubscriptionUpdated.cancel_at_period_end
? false
: true,
},
{
where: {
CostomerID: customerSubscriptionUpdated.customer,
SubscriptionID: customerSubscriptionUpdated.id,
},
}
);
var filterResult = await Model.Payment.findOne({
where: { CostomerID: customerSubscriptionUpdated.customer },
});
}
} catch (error) {}
break; ```
is this right?
Looks like it could work. Have you tried running it in test mode?
I just have quetion is that pending_update when subcrion update during auto renew ? or I will come only during upgrade plan?
The pending update will happen as soon as the user makes the payment on it