#binod-Subscription

1 messages ยท Page 1 of 1 (latest)

hollow ermine
hollow mural
#

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.

  1. iDeal payment uses collection method send_onvoice to pay for subscription through stripe hosted URL
  2. Card payment uses collection method automatically_charge to pay using paymentIntent.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?

hollow ermine
#

how about changing the collection method to charge_automatically ?

hollow mural
#

existing subscription is attached to iDeal so update API rejects charge_automatically

#

??

hollow ermine
#

can you send me the request ID?

hollow mural
#

sure

#

req_MafShRume06fer

hollow ermine
#

Thanks, give me a sec to take a look

hollow mural
#

ok

hollow ermine
#

So you have changed the payment_method to card before this request?

hollow mural
#

no

hollow ermine
#

Can you change the payment_method to card and then change the collection method?

hollow mural
#

in the same request API or different?

hollow ermine
#

In separate API calls

hollow mural
#

which one?

hollow ermine
#
  1. Change the payment_method to card
  2. 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

hollow mural
#

it says invalid array

#

req ID: req_YdyaGOfgSHeo03

hollow ermine
#

Please read my last message about payment method update.

hollow mural
#

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, }] });

hollow ermine
#

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'] } });

hollow mural
#

still paymentIntent is null

hollow ermine
#

what's the latest invoice's status? is it paid?

hollow mural
#

its draft

#

??

#

Is it wise to use this approach?

  1. Delete existing subscription (Not update)
  2. Create new subscription on each upgrade/downgrade
hollow ermine
#

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.

hollow mural
#

for amount > 0 status is paid and still paymentIntent is null.

hollow ermine
#

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.

hollow mural
#

to enter card details im using PaymentElement in frontend

#

which requires clientSecret

hollow ermine
#

So you don't want to use charge_automatically and prefer your customer to visit your website and make the payments manually?

hollow mural
#

yes, while changing subscription plan, they will pay manually

hollow ermine
#

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.

hollow mural
#

does stripe also stores card payment details for future payments?

hollow ermine
#

Yes

hollow mural
#

okay, so if status is paid I don't need to pay manually right?

hollow ermine
#

No need, it's paid already

hollow mural
#

okay, so my current code should work right?

#

if im switching from card to iDeal, follow the same approach?

  1. change payment method
  2. change collection method
hollow ermine
#

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

hollow mural
hollow ermine
#

Can you repeat the approach? i only see two question marks

hollow mural
#

Instead of update, I use

  1. delete existing subscription
  2. create new subscription
#

on each upgrade/downgrade

#

any cons of this approach?

hollow ermine
#

It's really up to you but I'd prefer subscription update over deletion.

hollow mural
#

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?

hollow ermine
#

Yes. so you don't need to change it to charge_automatically

hollow mural
#

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?

flint marsh
#

๐Ÿ‘‹ I'm stepping in for my colleague

#

please give me a moment to catch up

hollow mural
#

ok

flint marsh
#

if existing is card subscription it will have a collection method charge_automatically
yes correct, so in that case you will have to change to send_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?

hollow mural
#

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,
});`

flint marsh
#
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

hollow mural
#

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

flint marsh
#

if subscription status is canceled or incomplete_expired they can't be updated right?
true

hollow mural
#

is there any other status, I should be careful of?

flint marsh
#

I don't think so

hollow mural
#

okay, so canceled and incomplete_expired can be deleted right?

flint marsh
#

they are in a sense

hollow mural
#

just curious if we will need this in future

flint marsh
#

you can't delete a subscription you can just cancel it

hollow mural
#

there is a API to delete subscriptions

#

what does it do?

flint marsh
#

to cancel a subscription

hollow mural
#

what about this?

#

stripe.subscriptions.del(subscription_id);

#

oh okay, so del API set the status to cancel under the hood

flint marsh
#

yes exactly

hollow mural
#

okay, so I won't need any action against canceled and incomplete_expired right

flint marsh
#

yes right