#jcnguyen-subscription-upgrade

1 messages · Page 1 of 1 (latest)

turbid anchorBOT
mental compass
#

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

pastel drum
#

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

mental compass
#

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?

pastel drum
#

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

mental compass
pastel drum
#

hmm i think i tried that as well, but it automatically charges the user with the card that they use from the previous checkout

mental compass
#

try payment_behavior: 'default_incomplete' on update

pastel drum
#

i did that as well but it automatic use previous card

mental compass
#

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

pastel drum
#

on the subscription?

#

and will it set back to use automatic charge for renewal workflow?

mental compass
#

wherever you set the default, that's your own code controlling this

#

and you'd set it back yourself after based on the state

pastel drum
#

got it

#

but default payment method can't be to null can you?

mental compass
#

it can

pastel drum
#

and if the user backout from the payment will the subscription get reverted to previous subscription

mental compass
#

yes

pastel drum
#

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?

mental compass
#

yes

pastel drum
#

got it thanks for your help. Let me experiment with it and let you know

mental compass
#

sounds good!

pastel drum
#

i just tried DefaultPaymentMethod = null still automatic charge with previous card

mental compass
#

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?

pastel drum
#

so when i update the subscription, i included defaultpaymethod = null

mental compass
#

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

pastel drum
#

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?

mental compass
#

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?

pastel drum
#

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
        };
mental compass
#

okay so remove everything else, just try to set DefaultPaymentMethod = null and update the Subscription and confirm if it worked (it won't)

pastel drum
#

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

mental compass
#

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?

pastel drum
#

it's indeed null

mental compass
#

Can you give me a concrete example Subscription id sub_123 + request id req_123 to look at?

pastel drum
#

sub_1Ns97OCixCJn4IR4eiUjnNwl

mental compass
#

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

pastel drum
#

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?

mental compass
#

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

pastel drum
#

okay, so just set the default payment method via api. isn't just like this
var upgradeOptions = new SubscriptionUpdateOptions
{

            DefaultPaymentMethod = null
        };
mental compass
#

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

pastel drum
#

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?

mental compass
#

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

pastel drum
#

somehow when i get subscription details, it already shown null

mental compass
#

You've lost me again I'm sorry

pastel drum
#

ok i see what you mean there's defaultpaymentmethodid which is set back to null once the defaultpaymenmethod = ""

mental compass
#

okay so now if you try that back with your earlier flow for pending payments, does it work?

pastel drum
#

one second just submitted the request

#

verifying

#

it not completed anymore

mental compass
#

did you use the pending update approach though?

#

this looks like a real failure instead

pastel drum
#

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

mental compass
#

Do you have a Subscription id? That screenshot doesn't make sense if you use pending updates

pastel drum
#

same subscription id

#

sub_1Ns97OCixCJn4IR4eiUjnNwl

#

so during the failure state i can post payment intent to the user to complete the transaction

mental compass
#

hum I don't really get it, that Subscription is paid. Sorry I'm struggling to follow all your tests

pastel drum
#

i manually paid

#

to see if the upgrade works eventhough the payment shown failure

#

i will generate again let see if it show failed

turbid anchorBOT
pastel drum
#

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

cyan elbow