#jcnguyen-subscription-upgrade
1 messages · Page 1 of 1 (latest)
jcnguyen-subscription-upgrade
👋 @pastel drum I'm sorry I don't really get what you are trying to achieve exactly. But if you are trying to simulate what a change would look like in terms of proration you can use the Retrieve Upcoming Invoice API https://stripe.com/docs/api/invoices/upcoming to simulate/preview a change and look at proration.
But there isn't a way to change the Subscription now and email the details to get someone to pay. The closest we have is https://stripe.com/docs/billing/subscriptions/pending-updates but that only lasts 24 hours so it's more while someone is on your app upgrading
right i did use the upcoming invoice but how do I provide the payment to the user via the payment element (which takes in clientsecrete) to to pay
That's really not possible/not how it works at all
Is your customer on your page ready to pay, or are you trying to email them?
my customer is on the page ready to pay after they select which subscription product they would like to upgrade to
the workflow is user select an upgrade product -> our service will generate a payment intent which we will render on the front end so user can pay as a next step
and if i use existing subscription it automatic charge the user without giving them an option to see if they want to use another card
Okay so in that case the flow I mentioned above is exactly what you want: https://stripe.com/docs/billing/subscriptions/pending-updates
hmm i think i tried that as well, but it automatically charges the user with the card that they use from the previous checkout
try payment_behavior: 'default_incomplete' on update
i did that as well but it automatic use previous card
gotcha then yeah it's just impossible to do what you are after today unfortunately
You could work around it by temporarily unsetting their default payment method so that there's nothing to pay that Invoice but that feels really hacky
on the subscription?
and will it set back to use automatic charge for renewal workflow?
wherever you set the default, that's your own code controlling this
and you'd set it back yourself after based on the state
it can
and if the user backout from the payment will the subscription get reverted to previous subscription
yes
I.E. I already paid for subscription A, then upgraded to subscription B but decided not to pay after the invoice was already generated. It will revert to the status Active on the subscription, and auto renewal still applies like the upgrade subscription action never takes place?
yes
got it thanks for your help. Let me experiment with it and let you know
sounds good!
i just tried DefaultPaymentMethod = null still automatic charge with previous card
I mean did you unset the default payment method? You just said "I tried null" without any info
Like did your Subscription have a default first? Or not? Was it on the Customer? Did you try unsetting the right one first?
so when i update the subscription, i included defaultpaymethod = null
I'm sorry the first step is for you to look at how you set the default payment method. There are many different ways, so that's step 1
so when i create a subscription : I set this SaveDefaultPaymentMethod = "on_subscription",
i assume once the customer paid it will use that card going forward
but if i want to remove the default like what you suggested, should i set defaultpaymentmethod = null which will not automatic charge customer credit card?
defaultpaymentmethod = null isn't real code
Sorry for being nitpicky but I don't really follow what you're saying at all right now and I'm guessing a bit. Can you provide real code so that I understand what you are doing?
sure
var upgradeOptions = new SubscriptionUpdateOptions
{
Items = new List<SubscriptionItemOptions>
{
new SubscriptionItemOptions
{
Id = old price,
Price = new priceid,
},
},
ProrationBehavior = "always_invoice",
PaymentBehavior = "pending_if_incomplete",
DefaultPaymentMethod = null
};
okay so remove everything else, just try to set DefaultPaymentMethod = null and update the Subscription and confirm if it worked (it won't)
just tried. here's the payload
"payment_settings": {
"payment_method_options": null,
"payment_method_types": [
"card"
],
"save_default_payment_method": "on_subscription"
},
from stripe event
that payload is ~irrelevant right?
there's a default_payment_method property on a Subscription, you're trying to unset it, so you want to look at that property in the response right?
it's indeed null
Can you give me a concrete example Subscription id sub_123 + request id req_123 to look at?
sub_1Ns97OCixCJn4IR4eiUjnNwl
I just looked at it, it has default_payment_method set as expected
I don't see you ever running the code to unset the default payment method
i just execute again is it because everything is null in updateoption it just ignore?
and when you say default_payment_method is set as expected meaning?
You are writing some code. That code doesn't work. I'm trying to show you it doesn't work because you are doing multiple things at once to get to your other result and not understanding the problem
When you are writing code to update the default_payment_method property, you need to make sure that code works. That's what I am focusing on right now.
My point is that code doesn't work and I'm trying to show you that so that you debug this and figure it out
So right after you update that Subscription, look at the response and check the value of DefaultPaymentMethod and confirm if it's unset like you expected or not
okay, so just set the default payment method via api. isn't just like this
var upgradeOptions = new SubscriptionUpdateOptions
{
DefaultPaymentMethod = null
};
It's not, that does nothing basically. Which is what I am nudging you to test so that you can see it quickly to learn how to debug this further
got it. so if that didn't do any and is the subscription that i provided above is defaultpaymenmethod is not null?
hence it auto paid?
correct
so now try DefaultPaymentMethod = "" (empty string) which is a quirky way to unset parameters in our API
if you try that and look at the response you should see default_payment_method: null in the response
somehow when i get subscription details, it already shown null
You've lost me again I'm sorry
ok i see what you mean there's defaultpaymentmethodid which is set back to null once the defaultpaymenmethod = ""
okay so now if you try that back with your earlier flow for pending payments, does it work?
did you use the pending update approach though?
this looks like a real failure instead
yes
PaymentBehavior = "pending_if_incomplete"
eventhough we set it to null which resulted of payment failure and the previous subscription remain unchanged which is good
Do you have a Subscription id? That screenshot doesn't make sense if you use pending updates
same subscription id
sub_1Ns97OCixCJn4IR4eiUjnNwl
so during the failure state i can post payment intent to the user to complete the transaction
hum I don't really get it, that Subscription is paid. Sorry I'm struggling to follow all your tests
i manually paid
to see if the upgrade works eventhough the payment shown failure
i will generate again let see if it show failed
here's the new subscription: sub_1NsDcyCixCJn4IR4hqihRAac
looking at the log for an upgrade after removing payment default from subscription and customer. The good thing is that it not auto charge customer anymore
"payment_behavior": "pending_if_incomplete",
"proration_behavior": "always_invoice",
"items": {
"0": {
"id": "si_OfU5uAceTo1Aqc",
"price": "price_1NkUflCixCJn4IR4ypLuaLz2"
}
}
}
however, still see it attempt auto payment but failed
my understanding is that it shouldn't trigger/attempt complete the payment
try setting auto_advance=false for the invoice once it's been created, but keep in mind that if you do so, you'll have to manually finalize the invoice : https://stripe.com/docs/invoicing/integration/automatic-advancement-collection#update-auto