#manuel_api
1 messages · Page 1 of 1 (latest)
👋 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.
- manuel_api, 3 days ago, 11 messages
- manuel_api, 3 days ago, 14 messages
- manuel_api, 5 days ago, 11 messages
- manuel_api, 6 days ago, 36 messages
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?
hi there, you can control the behavior of what happens to subscriptions with failed payments with your dashboard settings. look here under "Manage failed payments for subscriptions" https://dashboard.stripe.com/settings/billing/automatic
in your case you could set it to "cancel the subscription"
ah yes, I was talking about that with my team, and the manager said we shouldn't change anything in that configuration... :c
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
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:
yes, sorry I thought that's what you said you want. what do you want to have occur after a failed payment?
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.
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?
got it, in that case I think the pending_if_incomplete payment behavior may be what you're looking for https://docs.stripe.com/billing/subscriptions/pending-updates
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
ok understood, let me try it
how can i find that pending_update attribute in the customer object?
you shouldn't be looking for it in the customer object, it'll be in the customer.subscription.update webhook event, which will be a Subscription object https://docs.stripe.com/api/events/types#event_types-customer.subscription.updated
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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.
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
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?
not quite, you would modify the payment_behavior of the subscription when the customer upgrades, as part of your call to update the subscription https://docs.stripe.com/api/subscriptions/update#update_subscription-payment_behavior
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
ok gotcha
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?
yes, but you shouldn't have to manually cancel the invoice, it'll happen automatically at the expiration time
to be sure it's doing what you want I'd also recommend trying this out in a sandbox. you can use test clocks to check exactly what happens when the expiration time is reached https://docs.stripe.com/billing/testing/test-clocks
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?
yes
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
- update the subscription with the new price and change
payment_behaviortopending_if_incomplete - if payment retries fail,
customer.subscription.updatedevent will be emitted (because the status will change topast_due) - 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
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?
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
ok ill try it