#binod-sub
1 messages · Page 1 of 1 (latest)
im facing issue in updating subscription
const updated = await stripe.subscriptions.update(subscription_id, { payment_behavior: 'default_incomplete', expand: ['latest_invoice.payment_intent'], items: [{ id: existing_subs.items.data[0].id, price: data.plan_id, }] });
this is my code, the problem is it sets subscription as actvive even though im just creating payment intent with above code
Can you share a Sub ID that I can look at?
So you aren't changing the billing period so there is no immediate invoice which is why the Sub stays active. If you want to force an invoice then you would pass proration_behavior: 'always_invoice'
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
It does not work
still subscription is directly update to active
Im using PaymentElement to pay
the idea is, create clientSecret with subscription API (create/update), => Pass clientSecret to PaymentElement (I want subs. status incomplete here => Pay using PaymentElement(i.e. Credit Card), Activate subscription
Ah okay I see the confusion
status: incomplete is only applicable to the first invoice for a Subscription
After that, the status will never be incomplete
So incomplete can never happen on an update
Why do you want it incomplete exactly? What is the goal of that?
You don't want it active if payment fails?
Because when I submit credit card details, it throws error saying payment already done
Ah okay so you want to trigger payment yourself and not have it automatically charge the paymentmethod associated with the customer or Sub?
yeah, but how do I know if customer has associated paymentMethod?
Well you would track that on your end in your database or you would retrieve the Sub or Customer ahead of time
payment_settings: { payment_method_options: null, payment_method_types: null, save_default_payment_method: 'off' },
I have this details on Sub retrieve.
Does the Sub have a default_payment_method set?
no
Okay and does the Customer have an invoice_settings.defualt_payment_method set?
nope
Ah okay so looking at the Sub above it seems that it used credits from previous prorations to pay the new invoice
Can you create a new test and ensure the new price is for a larger amount than the previous price?
Well the sub you have been testing with has like 20 proration items on it
So I would recommend creating a fresh one
But up to you
what is proration items?
They are the invoice items that are generated when you update a Subscription and cause proration to occur.
okay, let me create fresh one
this is the sub I just created sub_1LDtDLHsW9ET26Jg92duKTlv
Now, I want to switch plan by using credit card payment, how do I do that?
So now if you update the Subscription and use proration_behavior: 'always_invoice'
Then a new invoice will be generated
And then you can grab the client secret from the new invoice and use that to pay it
should I put anything in payment_behavior ?
It will default to allow_incomplete
So depends on what behavior you want
Which it does sound like you want to control payment here
So you likely want default_incomplete
It throws an error This customer has no attached payment source or default payment method
Did you pass default_incomplete?
yeah, default_incomplete worked
Now, everytime subscription expires, customer have to pay manually to activate the subscription?
or stripe will automatically charge to connected card
If there is a default_payment_method set then it will be automatically charged on renewal
The manual payment would only be relevant for the update itself.
is it possible to add default_payment_method with API?
Do you want to set the payment method that just paid the invoice as the default?
yes
If you set save_default_payment_method: on_subscription on your update then the payment method that was used to pay the invoice will be set as the default
it can be set on subscription creation as well right?
Yep
But it won't carry over to your update if you update
You would need to pass it again
On update
The default payment method?
yes
Would only be charged on renewal if you are passing default_incomplete on update
okay, also on renewal, webhook will be triggered right? i.e. invoice.paid
okay, thanks!
im also implementing iDeal payment for subscription
it only works with collection_method: 'send_invoice' right?
Correct
and other process is same?
like, it will also trigger webhook on successful payment?
what about auto renew?
You can send the invoice to yourself if you use the owner email on your account
On auto renew the invoice will be sent to the customer each time
oh okay, thank you for the help!
Sure!
hey you there?
It's not creating updated invoice for iDeal payment return stripe.subscriptions.update(subscription_id, { items: [{ id: existing_subs.items.data[0].id, price: data.plan_id, }], payment_settings: { payment_method_types: ['ideal'] }, proration_behavior: 'always_invoice', collection_method: 'send_invoice', payment_behavior: 'default_incomplete', expand: ['latest_invoice.payment_intent'], days_until_due: DAYS_UNTIL_INVOICE_EXPIRE, });
what am I missing?
creating invoice working fine.
Hi 👋 I stepped in for @errant silo . Do you have the request ID for this API request?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Okay so you are updating the Subscription? Did the invoice already exist?
I created invoice => Paid invoice => Created subscription.
Now I want to update that subscription with the same flow
Okay but I'm asking if the latest_invoice already existed because in that case the payment method associated with the invoice won't update until the next invoice is generated.
yes, I created first invoice and paid. I don't know if paid invoices exist or deleted
and then created new invoice to switch the plan
did you get it?
I'm looking at the Update request to the Sub.
It has payment_settings.payment_method_types set to ideal.
What is the outcome you expected?
I should have a invoice to pay 2 EURO.
because im switching plan from 1 EURO to 2 EURO
But, invoice with 1 ERUO is being created with status draft which doesnt have payment URL
??
looking into the Subscription
Okay the new invoice (in_1LDu2sHsW9ET26JglkCqPaMT) is using the correct new Price. But the update triggered a proration for -1 EUR so the final price is 1 EUR
how do I fix it? Becasue I need to pay 2 EUR to upgrade Sub
When you make the Update call be sure to set proration_behavior parameter to none
https://stripe.com/docs/api/subscriptions/update?lang=python#update_subscription-proration_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.
I want to pay it right now, not as an upcoming payment
Well the current invoice is in a draft state, correct?
I am but I'm thinking you'll need to void this invoice to progress to the next one
I don't get it
I want to switch to 2 euro plan from 1 euro plan using iDeal payment. That's it
Yes but the way you did the switch credits the user (as if they already paid) for the 1 EUR.
But, it works fine with Credit card payment
why credit 1 EUR?
??
new invoice is being created as incoming invoice
thats the issue
Right, because the assumption is that you will collect on the outstanding one
But, If I want to switch plan right now, why do I have upcoming invoice?
how can I switch plan right now?
The invoice was created when you created the subscription. Stripe assumes you will collect on that invoice.
you mean I will have to wait for recurring period end to switch subscription plans?
Not if you handle the prorations properly.
https://stripe.com/docs/api/subscriptions/update#update_subscription-proration_behavior
Doc says to use proration_behavior: 'always_invoice'
but using that only creates invoice in draft
I need to step away but my colleague @pastel hatch will be able to answer additional questions.
Hey @fluid otter, I'm back for a bit.
You are having issues with ideal and send_invoice?
yes
I am able to create subscription using iDeal
but having having issues to update subscription
What issue in particular?
when I try to update subscription, update invoice is created as draft instead of open status
Yep that is how send_invoice works. You can finalize it immediately after update or it will finalize automatically after an hour
How do I finalize it immedialty?
If you want to send it immediately
That will finalize and send it
Or you can just call https://stripe.com/docs/api/invoices/finalize to just finalize and it will be sent automatically in an hour
If you want to trigger an invoice immediately upon update then you use always_invoice
Recommend giving a read through https://stripe.com/docs/billing/subscriptions/upgrade-downgrade if you haven't
yeah I need to trigger immed. but invoice amount not correct
like I have existing plan of 1 euro, If I want to switch to 3 euro plan, invoice is sent with amount 3-1=2 euro instead of 3 euro.
??
Patience, helping multiple people at once.
So yes what you stated is expected for always_invoiec
If you want to charge the full amount then you would use none
However, this means that if the billing period doesn't change then an invoice won't be cut immediately
yeah, but invoice is created as draft if I use none
Sure, then you finalize it as I stated above
is it possible to charge full amount immediatly?
Not if the billing period doesn't change. So you could manipulate this by updating the Sub to a trial momentarily and then back to the price you want.
okay, it's only on iDeal payment right?
on credit card, I could charge full amount immediately.
No.
It works the same regardless
The amount is based on the billing period and the proration behavior
https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#immediate-payment talks specifically about immediate payment
oh okay, thanks for the help