#manuel_api

1 messages · Page 1 of 1 (latest)

plain spadeBOT
#

👋 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/1422591845384458240

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

slender coral
#

How can I prevent that item from being saved? Or could you tell me what solution to implement for these cases, since the masterminds of my project do the upgrade before the checkout.session is completed?

subtle axle
#

in your case you could set it to "cancel the subscription"

slender coral
#

ah yes, I was talking about that with my team, and the manager said we shouldn't change anything in that configuration... :c

subtle axle
#

gotcha, in that case you could listen for the invoice.payment_failed webhook event, then check the parent in the event data to find the subscription that created that invoice, then manually cancel the subscription with the API

slender coral
#

cancel the subscription? But wouldn't that cause problems with customers? And if I create a new subscription for them later, wouldn't I charge them again? D:

subtle axle
#

yes, sorry I thought that's what you said you want. what do you want to have occur after a failed payment?

slender coral
#

dont worry let me explain it well for you

#

what happens is that when a payment is rejected, the idea is to cancel that payment so that it is not attempted again. Since my team does not allow me to modify the Stripe account settings, what I do is cancel the invoice using the void_invoice() method. So far, so good, but when that invoice is canceled, the item that the customer was trying to purchase on that invoice remains assigned to the subscription as if I had paid for it, and that's not the idea. Ideally, it should keep what the customre had before attempting that failed payment.

subtle axle
#

Ideally, it should keep what the customre had before
so is this after the customer has upgraded their subscription? as in, chosen a higher-priced item?

slender coral
#

yes

#

Yes, after canceling the invoice with void

subtle axle
#

this would be done when you update the subscription with the new price. you can then listen to the customer.subscription.updated event and check for the presence of the pending_updateattribute in the data

#

if it exists, you know the payment failed on the upgrade, and you can decide what to do with the subscription from there

#

or if you don't take any action, the invoice voids automatically and discards the update at the expiration time

slender coral
#

ok understood, let me try it

#

how can i find that pending_update attribute in the customer object?

subtle axle
slender coral
#

you're telling me that

you can decide what to do with the subscription from there
what actions can I take? Is there any documentation or configuration via API? I don't know how to choose which action to take from the ones you mention. The idea is that the subscription should not be renewed if it has not been paid for.

subtle axle
#

in that case you don't need to take any action, if you use pending_if_incomplete the subscription will revert to the old price after the expiration time given in the pending_update hash

slender coral
#

ok so let me see if i understand. I have to listen the event customer.subscription.updated and then if the pending_update attribute exist i have to modify the payment_behavior in the subscription for pending_if_incomplete? right?

#

But I see that there are two pending_update attributes:

customer.subscription.pending_update_applied
customer.subscription.pending_update_expired

I guess I should use the expired one since the invoice is canceled, right?

subtle axle
#

you can listen for those two events you mentioned if you want to take action for that, for example if you want to send the user an email informing them that their upgrade was cancelled due to payment failure

slender coral
#

If I do that, then when I cancel the invoice with void, the subscription will not be modified and will remain as it was before the upgrade, correct?

subtle axle
#

yes, but you shouldn't have to manually cancel the invoice, it'll happen automatically at the expiration time

slender coral
#

I'm sorry, but I think I'm a little confused about the order of the steps I need to take to achieve what I want 😅

#

When upgrading, do I need to change the payment_behavior?

subtle axle
#

yes

slender coral
#

But what happens when the payment is successful? Since I always use ‘proration_behavior’ in ‘always_invoice’

if the customer makes the payment and it is rejected, what happens to the subscription?

If the customer makes the payment and it is successful, should I change the payment_behavior?

#

im sorry but im confused and im trying to understand

subtle axle
#
  1. update the subscription with the new price and change payment_behavior to pending_if_incomplete
  2. if payment retries fail, customer.subscription.updated event will be emitted (because the status will change to past_due)
  3. listen for that event and take whatever action you deem necessary (like comms with the customer, updating your backend, etc)
#

| if the customer makes the payment and it is rejected, what happens to the subscription?
see above

| If the customer makes the payment and it is successful, should I change the payment_behavior?
nope, the updates in the pending_update hash will be applied automatically

slender coral
#

ok ok

#

so in the third step i should void the invoice

#

That way, it won't be retried and the invoice will remain as it was before, right?

subtle axle
#

you probably could if you want to do it before the expiration in pending_update, but you don't need to

#

I would say try it out in test and see if it gives you the results you want

slender coral
#

ok ill try it