#kashi3029

1 messages · Page 1 of 1 (latest)

wintry saddleBOT
neat meadow
#

Hi there!

#

Is your goal is to create a new Subscription? Does the user already have a saved payment method or not?

regal bronze
#

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

regal bronze
neat meadow
#

If you have a default payment method, then I recommend settin payment_behavior: allow_incomplete.

regal bronze
#

still invoice invoice.payment_failed called first when I started upgrade process

neat meadow
#

Wait I'm confused. Are you trying to create a new subscription or upgrade an existing subscription?

regal bronze
#

Upgrade plan I am upgrading plan I have monthly plan and I am upgrading to yearly plan

neat meadow
regal bronze
#

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

neat meadow
regal bronze
#

Yes exectly but I don't how it's work I can use

neat meadow
#

What do you mean?

regal bronze
#

No if payment got fail how I can update payment status back to paid with old plan using pending-update?

neat meadow
#

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.

regal bronze
#

Yes I read that link but still payment status has. been changed to open event payment got failed it should be paid

neat meadow
#

Can you share the Subscription ID (sub_xxx) where you tried a pending update?

regal bronze
#

sub_1O0hGeGazzgitazvy2Tk2edy

wintry saddleBOT
shy tundra
regal bronze
#

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?

shy tundra
regal bronze
#

is this change payment status back to paid?

shy tundra
#

Yes it'll undo the pending update and apply the previous state

regal bronze
#

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

shy tundra
#

You'd do nothing in a successful payment, we'd apply the pending update to the subscription in that instance

regal bronze
#

Okay so my condition is right am i right?

shy tundra
#

Your condition seems to just always cancel the pending update?

regal bronze
#
      const customerSubscriptionUpdated = data.object;
      try {
        if (customerSubscriptionUpdated?.pending_update) {
          const invoice = await stripe.invoices.voidInvoice(
            customerSubscriptionUpdated?.latest_invoice
          );
        }
shy tundra
#

No, you'd do that on a invoice.payment_failed event

regal bronze
#

but I am not getting pending_update there in invoice.payment_failed

shy tundra
#

Yes, you'd need to look up the associated Subscription via the API using the subscription field on the event payload

regal bronze
#
      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?

shy tundra
#

Looks fine yeah

regal bronze
#

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

shy tundra
#

Sorry, I'm confused. You asked how you could cancel the update if the payment failed, no?

regal bronze
#

Yes but payment_fail event when I start payment

#

If you check event list here

shy tundra
regal bronze
#

Payment has not been made also payment status not update open to paid

regal bronze
shy tundra
#

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

regal bronze
#

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?

shy tundra
#

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

regal bronze
#

can we call?