#kashi3029

1 messages · Page 1 of 1 (latest)

jade cradleBOT
mortal flax
#

Hello

jade cradleBOT
cursive scroll
#

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?

mortal flax
#

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

shut cipher
#

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.

mortal flax
#

Let me check

#

Can you share doucment which code I need to impliment frontend side?

#

@shut cipher

shut cipher
#

Yes, but it depends on what you're using. Is this on the web? In a mobile app?

mortal flax
#

web

#

react js

#

I am using stripe element custom code

shut cipher
mortal flax
#

Thanks

#

not getting requires_action thi ststus

#

Here it's showing need 3d auth

shut cipher
#

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.

mortal flax
#

Do I need to call one more API call am I right?

shut cipher
#

No, you can add the expansion to your stripe.subscriptions.update request.

mortal flax
#

Okay

mortal flax
shut cipher
#

You call that client-side, on your website, so your customer can complete the next action.

mortal flax
#

const data = await stripe.handleNextAction({
clientSecret:
"pi_3O0SfSGXQ7blAdt60RgLrEGn_secret_jSntdTlTiI3o7PUl7nn8CLQC9",
});

#

this is my code

shut cipher
#

Can you share the code you used to initialize Stripe.js?

mortal flax
#

<Elements stripe={stripePromise}>
<Passes isHomePage={false} />
</Elements>

#

const stripePromise = loadStripe(stripeKey);

shut cipher
#

Hm, odd. For some reason stripe seems to be null instead of the instance of stripe you're initializing there.

#

Any luck?

mortal flax
#

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

shut cipher
#

Not sure what you mean, can you provide more details?

mortal flax
#

Leave it all working fine for now

jade cradleBOT
mortal flax
#

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

quick fable
#

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?

mortal flax
#

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

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

mortal flax
#

Can you share that code?

quick fable
mortal flax
#

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

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?

mortal flax
#

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

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

mortal flax
#
      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?

quick fable
#

Looks like it could work. Have you tried running it in test mode?

mortal flax
#

I just have quetion is that pending_update when subcrion update during auto renew ? or I will come only during upgrade plan?

quick fable
#

The pending update will happen as soon as the user makes the payment on it