#keith-paymentmethod-save

1 messages ยท Page 1 of 1 (latest)

astral vineBOT
versed shore
#

keith-paymentmethod-save

#

@dusky atlas let me know if any of this is unclear

dusky atlas
#

Hmm, I am a bit confused. I am paying an invoice from a past_due subscription. I'm basically doing, if that payment is successful update the subscription with that payment method as default, but I keep getting the error This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.

versed shore
#

Ah sorry you never mentioned Invoices and Subscriptions were involved. Can you give me a concrete example Invoice id for me to look at?

dusky atlas
#

Apologies, sure, here is the subscription

sub_1NB0vjAjtNFaRAYoFsoMx408

#

and the invoice
in_1NB4R9AjtNFaRAYohxTUspSN

versed shore
#

thanks give me a few minutes

dusky atlas
#

Sorry, I was advancing the test clock. This would be the invoice which is paid in_1NB4jKAjtNFaRAYoePx0Jd0l

#

So when I pay that in the front end (payment element) I need to attach it to the customer somehow so I can update the subscriptions default payment method

versed shore
#

that Invoice was never paid right?

dusky atlas
#

No that one is being generated by the renewal payment failing

versed shore
#

so what's the problem?

dusky atlas
#

When I pay that invoice and the sub becomes active again, I want to set whatever payment was used as the default source for the subscription

#

but I cannot do that without attaching it the customer

#

which I cannot figure out how in this flow

#

I am doing this in the webhook

#

But I am getting the error This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again. because it's just been used I think

versed shore
#

you're likely missing this option on your Subscription

dusky atlas
#

Ah okay, so I don't need any of that logic if I have that set?

#

It should just default to whatever was successful

versed shore
#

yes!

dusky atlas
#

Cool thank you

#

I think I'm getting confused because I'm creating subs using the test clock

#

so missing some of the flags my usual flow has, like save_default etc

#

I'm going to update the sub now in the api

#

I do have another question though please, bacs_debit doesn't seem to be showing up as an option on the form even though I've just set it

versed shore
#

what does "even though I've just set it" mean?

dusky atlas
#

I've updated the test clock sub to allow bacs_debit I mean

#

The 'save_default_payment_method' => 'on_subscription', flag doesn't seem to be working either.. sorry I'm getting quite confused with this

versed shore
#

I've updated the test clock sub to allow bacs_debit I mean
what does that mean? What did you do exactly? What do you see in the API?

dusky atlas
#

Just did this

versed shore
#

And all good I can see you're confused, but you only give me a small part of the things I need to help you

#

please no pictures ๐Ÿ™‚

#

did you do this before the Invoice got generated?

#

Like start fresh, do it on a brand new Subscription

astral vineBOT
dusky atlas
#

Sorry, let me try again with a new subscription. Then I'll clarify my issues

#

So the bacs_debit issue is solved, that seems to be working, but the payment method is still not being set as default after payment success

#

This is the sub sub_1NB5AWAjtNFaRAYolKVg8OwN

high stag
#

๐Ÿ‘‹ Taking over this thread, catching up now

dusky atlas
#

Cool let me know if you need anything, I have also set this on the subscription via the api so save_default_payment_method = on_subscription

high stag
dusky atlas
#

So I've just paid the latest invoice with the working card (4242..) so I'd except to see that payment method be that

#

I can tell you how I'm testing it if you'd like, in case I'm doing something wrong

#

I originally tried to set the payment method myself, but kept getting the error it's been used previously without being attached to a customer

high stag
#

Gotcha! Just to clarify, you would like to set the payment method in second invoice as subscription's default payment method?

dusky atlas
#

ye that's correct

#

if its successful of course

high stag
#

Thanks for clarifying. With save_default_payment_method: 'on_subscription', the payment method will only be saved when you create the subscription, not on the future billing cycle. I'm afraid there is no straightforward way to do this.

If you wish to save the payment method as default from the Payment Intent of recurring invoice, the steps will be:

  1. In the failed/unpaid recurring invoice, update its Payment Intent to setup_future_usage: "off_session" to allow payment method to be saved on the customer: https://stripe.com/docs/api/payment_intents/update#update_payment_intent-setup_future_usage
  2. Pass the Payment Intent client secret to Payment Element to collect new payment method
  3. After the Payment Intent is successful, then set the payment method (pm_xxx) created from Step 2 to subscription's default_payment_method: https://stripe.com/docs/api/subscriptions/update#update_subscription-default_payment_method
dusky atlas
#

Thanks so much, I'll try this out thank you

#

So in these steps will I need to add extra steps, or can I still use confirmPayment() ?

#

I don't have to save the card first do I?

high stag
#

Before stripe.confirmPayment(), you'd need to update the Payment Intent to setup_future_usage: "off_session" in the Step 1 which will allow the card to be saved on the customer.

dusky atlas
#

ok thank you I'll try it now

#

It works thanks so much for the help ๐Ÿ‘