#kashi3029
1 messages · Page 1 of 1 (latest)
Hi there!
Is your goal is to create a new Subscription? Does the user already have a saved payment method or not?
So current follow I like user by new subscription I am creating new entry in db with payment status paid
now I am giving user option to upgrade plan now when I start upgrade prosecc first event is callled invoive.payment_failed so this event updateding my current payment statut to open now if i leave current payment process than my payment status is still open hence you lost there old subcription as well I am using stripe element
Yes user has already saved payment method
If you have a default payment method, then I recommend settin payment_behavior: allow_incomplete.
still invoice invoice.payment_failed called first when I started upgrade process
Wait I'm confused. Are you trying to create a new subscription or upgrade an existing subscription?
Upgrade plan I am upgrading plan I have monthly plan and I am upgrading to yearly plan
If you change the billing interval, then Stripe will automatically create a new Invoice when you make the update. And that invoice could fail yes. Then what happens next will depend on your Subscriptions settings here: https://dashboard.stripe.com/settings/billing/automatic
but it's calling first event as invoice.payment_failed and it changing payment status to open now if you leave upgrade process inbetween I want to give user to there old plan back
now if you leave upgrade process inbetween I want to give user to there old plan back
If you don't want to upgrade the Subscription when the payment fails, then you should use Pending Updates: https://stripe.com/docs/billing/subscriptions/pending-updates
Yes exectly but I don't how it's work I can use
What do you mean?
No if payment got fail how I can update payment status back to paid with old plan using pending-update?
No that's not how it works. You update the subscription using a Pending Updates, and only if the payment succeed the update will be applied. If the payment fails, then no update will be applied.
I recommend reading the link I shared above, it explains everything.
Yes I read that link but still payment status has. been changed to open event payment got failed it should be paid
Can you share the Subscription ID (sub_xxx) where you tried a pending update?
sub_1O0hGeGazzgitazvy2Tk2edy
but still payment status has. been changed to open event payment got failed it should be paid
Not sure I understand what you're describing here. Looks like you applied a pending update (https://dashboard.stripe.com/test/logs/req_t9ZCdULDUwMWxc) and payment failed. What is unexpected?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
when I starded upgarde process first event has been called is invoice.payment_failed hence payment status update to open in my db now I leave payment process in between how can I change back to paid with my old plan?
You'd cancel the pending update: https://stripe.com/docs/billing/subscriptions/pending-updates#canceling-changing
is this change payment status back to paid?
Yes it'll undo the pending update and apply the previous state
Okay let me try
but in which case I need to cancel pending update and on which condition because currenly I start payment I am getting pending update in subscription so if add conditon like if(sub.pending_update){
delete pending update
}
than payment will no prosside am i right? so what I need to do in successfull payment
You'd do nothing in a successful payment, we'd apply the pending update to the subscription in that instance
Okay so my condition is right am i right?
Your condition seems to just always cancel the pending update?
const customerSubscriptionUpdated = data.object;
try {
if (customerSubscriptionUpdated?.pending_update) {
const invoice = await stripe.invoices.voidInvoice(
customerSubscriptionUpdated?.latest_invoice
);
}
No, you'd do that on a invoice.payment_failed event
but I am not getting pending_update there in invoice.payment_failed
Yes, you'd need to look up the associated Subscription via the API using the subscription field on the event payload
const invoicePaymentFailed = data.object;
try {
const subscription = await stripe.subscriptions.retrieve(
invoicePaymentFailed?.subscription
);
if (subscription?.pending_update) {
const invoice = await stripe.invoices.voidInvoice(
subscription?.latest_invoice
);
}```
is this correct?
Looks fine yeah
let me test than
It's cancel direct when I stared upgrade process as I told invoice.payment_failed call first and It will cancle invoice there
Sorry, I'm confused. You asked how you could cancel the update if the payment failed, no?
Seems expected given that 3DS/auth was required for the payment: https://dashboard.stripe.com/test/events/evt_3O0htKGazzgitazv1JVe6wr2
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Payment has not been made also payment status not update open to paid
This is also done from my side erliver it was opening pop now it's not opening
It did when you canceled the pending update after voiding the invoice: https://dashboard.stripe.com/test/events/evt_1O0hxtGazzgitazvjcR820M2
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sorry, you need to take a step back to understand how this works and then return with actual questions to help you solve the problem you're facing
If you don't want to cancel after the initial invoice payment attempt fails, then you need to write logic to account for that
If you don't want to cancel after the initial invoice payment attempt fails, then you need to write logic to account for that
Can you provide tha?
No, we don't write code here. My recommendation would be to expand the payment_intent field in your webhook and check the status/failure reason
status: 'requires_action' means 3DS/auth is required so you'd need to handle that flow with your customer
can we call?