#idhruv-payment-method-error

1 messages · Page 1 of 1 (latest)

frozen siren
#

Hi there

#

The thing to do if you know you are going to want to attach a PaymentMethod is to use setup_future_usage when you create the PaymentIntent.

#

Otherwise the PaymentMethod will be consumed on use

#

And you can't attach

tame meteor
#

okay

#

so is it okay if i set setup_future_usage to off session?

#

in my case, the view looks like this. So if i point setup_future_usage to off_session then won't the card details will be saved for future payment? despite having un-checked the box that says "save this card for future payment"

frozen siren
#

Yep, you would want to fetch your server if that box is checked and update the PaymentIntent to set setup_future_usage: 'off_session'

tame meteor
#

okay i just verified, your solution works but cards are getting saved even if i uncheck the box

#

any idea how to avoid saving cards if that little box is UNCHECKED

frozen siren
#

You would fetch your server before confirming the PaymentIntent and based on the value of the box you would dictate whether to update the PaymentIntent. You wouldn't update every single time it is checked/unchecked.

#

Does that make sense?

tame meteor
#

okay it does make sense, however in my case i am using two different cards

#

so even if i fetch from server it doesnt list another new card that i will use

#

and as a user if i decide to use new card while keeping the checkbox unchecked, it still saves the card. wait i show you snapshot

#

so here the card marked with crossed is still present in saved card list that is fetched from server, but i never checked the box for this card. "save this card for future" checkbox was unchecked for this card when i made payment previously with it and still it appears here. I hope my question is clear.

vocal herald
#

Hello! I'm taking over and catching up...

tame meteor
#

sure thanks

vocal herald
#

It sounds like you're creating all of your Payment Intents with setup_future_usage and then collecting the card details, correct?

tame meteor
#

yes as per the answer otherwise i get This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.

#

you can view this problem here req_aOFoFXJN4MjLER

vocal herald
#

There are two approaches you can take:

  1. When the box to save the card is not checked don't use the setup_future_usage parameter on the Intent and avoid using an associated Customer object with it
  2. After the payment detach the Payment Method from the Customer: https://stripe.com/docs/api/payment_methods/detach
tame meteor
#

2nd sounds good, 1st one might again throw the above error so it seems risky