#binod-Subscription
1 messages ยท Page 1 of 1 (latest)
Hi there, do you have a chance to read this doc? https://stripe.com/docs/billing/subscriptions/upgrade-downgrade
yes, I have implemented it
But getting an issue
hello?
Let me give you a context. I am using Card and iDeal payment for subscription.
- iDeal payment uses collection method
send_onvoiceto pay for subscription through stripe hosted URL - Card payment uses collection method
automatically_chargeto pay usingpaymentIntent.clientSecret
Both work for creating subscription
Now the problem is, if I have subscribed with iDeal and want to upgrade/downgrade using card I don't get paymentIntent.clientSecret because existing subscription has a collection method of send_invoice which does not create paymentIntent object
how do I tackle this issue?
how about changing the collection method to charge_automatically ?
existing subscription is attached to iDeal so update API rejects charge_automatically
??
can you send me the request ID?
Thanks, give me a sec to take a look
ok
So you have changed the payment_method to card before this request?
no
Can you change the payment_method to card and then change the collection method?
in the same request API or different?
In separate API calls
which one?
- Change the payment_method to card
- Change the collection method to charge_automatically
To change the payment_method, you should first collect a card payment method via SetupIntent, and then update the default_payment_method (https://stripe.com/docs/api/subscriptions/object?lang=curl#subscription_object-default_payment_method) with ID of the collected payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Please read my last message about payment method update.
that's what I did. change payment method and change collection method
await stripe.subscriptions.update(subscription_id, { payment_settings: { payment_method_types: 'card' } }); const updated = await stripe.subscriptions.update(subscription_id, { collection_method: 'charge_automatically', cancel_at_period_end: false, payment_behavior: 'default_incomplete', expand: ['latest_invoice.payment_intent'], proration_behavior: 'always_invoice', payment_settings: { save_default_payment_method: 'on_subscription' }, items: [{ id: existing_subs.items.data[0].id, price: data.plan_id, }] });
Ah, the payment_method_types is expecting an array, so use this instead
await stripe.subscriptions.update(subscription_id, { payment_settings: { payment_method_types: ['card'] } });
still paymentIntent is null
what's the latest invoice's status? is it paid?
its draft
??
Is it wise to use this approach?
- Delete existing subscription (Not update)
- Create new subscription on each upgrade/downgrade
If the invoice status is draft, it's expected to have null payment_intent.
The payment_intent is not null when the invoice is open and the amount > 0.
for amount > 0 status is paid and still paymentIntent is null.
That's because the invoice is already paid.
Why do you still want to get the client_secret for charge_automatically subscriptions? Stripe will automatically use the default_payment_method to pay the invoice.
to enter card details im using PaymentElement in frontend
which requires clientSecret
So you don't want to use charge_automatically and prefer your customer to visit your website and make the payments manually?
yes, while changing subscription plan, they will pay manually
OK, then you don't change the collection method.
You current integration should work fine. The reason that the paymentIntent is null is that the last invoice is either in draft or paid already.
I'd also want to mention that Stripe also provide a customer billing portal where your customer can manage the payment method by themselves https://stripe.com/docs/billing/subscriptions/integrating-customer-portal
does stripe also stores card payment details for future payments?
okay, so if status is paid I don't need to pay manually right?
No need, it's paid already
okay, so my current code should work right?
if im switching from card to iDeal, follow the same approach?
- change payment method
- change collection method
No need to change the collection method if you don't your subscription to be charged automatically, you just need to change the payment method type
ok, how about this approach? any issue with this?
Can you repeat the approach? i only see two question marks
Instead of update, I use
- delete existing subscription
- create new subscription
on each upgrade/downgrade
any cons of this approach?
It's really up to you but I'd prefer subscription update over deletion.
okay, in case of card to iDeal switch, you said I won't need to change collection method
but iDeal payment only supports send_invoice collection method right?
Yes. so you don't need to change it to charge_automatically
No no, I mean if existing is card subscription it will have a collection method charge_automatically
but iDeal will need send_onvoice collection method
did you get my point?
ok
if existing is card subscription it will have a collection method charge_automatically
yes correct, so in that case you will have to change tosend_invoice
sorry I haven't tried this before, so I don't know whether it will work or if there's a limitation
could you please try it out and let me know if it did work for you?
sure
getting this error
e ideal cannot be used with subscriptions that have the collection_method set to charge_automatically.
this is my code
` if (existing_subs.collection_method !== 'send_invoice') await stripe.subscriptions.update(subscription_id, { payment_settings: {
payment_method_types: ['ideal', 'card'] } });
const updated = await stripe.subscriptions.update(subscription_id, {
items: [{
id: existing_subs.items.data[0].id,
price: data.plan_id,
}],
payment_settings: { payment_method_types: ['card', 'ideal'] },
cancel_at_period_end: false,
proration_behavior: 'always_invoice', // use none to charge full_amount but need to wait to send updated invoice
collection_method: 'send_invoice',
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
days_until_due: DAYS_UNTIL_INVOICE_EXPIRE,
});`
payment_method_types: ['ideal', 'card'] } });
in this you're trying to change the payment method types to ideal for a subscription that has a collection method different than send_invoice
you'd need to change the collection_method otherwise it wouldn't work
okay, it's working now.
one more question
if subscription status is canceled or incomplete_expired they can't be updated right?
i.e. upgrade/downgrade is not possible
if subscription status is canceled or incomplete_expired they can't be updated right?
true
is there any other status, I should be careful of?
I don't think so
okay, so canceled and incomplete_expired can be deleted right?
they are in a sense
just curious if we will need this in future
you can't delete a subscription you can just cancel it
no there's only this API https://stripe.com/docs/api/subscriptions/cancel
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
to cancel a subscription
what about this?
stripe.subscriptions.del(subscription_id);
oh okay, so del API set the status to cancel under the hood
yes exactly
okay, so I won't need any action against canceled and incomplete_expired right
yes right