#rsdotscot

1 messages ยท Page 1 of 1 (latest)

cosmic sigilBOT
simple thistle
#

hello! can you share more on what you're trying to do?

fierce forum
#

(I wish I'd copied the content of the email I just sent in to support via stripe.com)

I have a scenario where a new card isn't being saved against the client because our system recognises they have an existing card saved and so it creates a PI with that existing PM, but they've decided they'd like to use a new card, the details of which should be available for them to use with a future purchase, and I'm suspecting that it's the pre-existing PM that's the issue

#

I hope that wasn't too much of a ramble!

simple thistle
#

you don't need to detach the PaymentMethod from a PaymentIntent, you should be able to just collect a new payment method for it. How are you collect the customer's card details currently - are you using the Payment Element or Card Element?

fierce forum
#

stripe.elements()

simple thistle
#

maybe share your Stripe account id and i'll be able to check. That line doesn't give any indication of what you're using

fierce forum
#

Apologies, just a moment

#

acct_1CBkCLD3yZL5Nmof

simple thistle
fierce forum
#

Yep, that's in there

simple thistle
#

try it out and let me know if you're still having trouble

fierce forum
#

It's been in there the whole time ๐Ÿ˜›

#

Give me a moment and I'll send a snippet URL

#

Lines 40-80 are only for clients with brand new accounts and no previous card info saved, so you can ignore that part

#

piData is defined on-page and contains the data generated when the PI is created on the page with the existing card option

#

I've confirmed that piData is passed correctly

simple thistle
#

what's your question?

fierce forum
#

Do you see anything wrong with the payWithNewCard function that might be causing the new PM to fail in attaching to the client for future use?

#

It attaches just fine if there's no pre-existing PM and there's no PM in the PI

#

pi_3MnWrPD3yZL5Nmof29UZ3ZNj is a PI which was created with a PM already attached to the client

simple thistle
#

which fails

fierce forum
#

Yep, it threw an error at me when I tried it

simple thistle
#

you don't need to "reset" it

fierce forum
#

This was done prior to sending my original message

#

Just trying things out

simple thistle
#

i'm pretty confused here - you would want to confirmCardPayment with the same PaymentIntent, pulling the new payment_method details from the card element.

#

is there any link to the current code snippet you shared?

fierce forum
#

That's what I'm trying to do, but what I have doesn't save the new card at this point

#

If I run my code adding the new card details, can you track what's going on at the Stripe end using the PI ID I gave you?

#

That may highlight where I'm going wrong but can't see

simple thistle
#

the problem here is likely with your logic and it won't be something which I can track on the Stripe end. You'll need to step through your own code to figure out what's wrong . For example

  • log the PaymentIntent
  • log if you're calling confirmCardPayment when you submit button is pressed with that existing PaymentIntent
  • log and check card which confirmCardPayment is supposed to be passing into payment_method in confirmCardPayment
fierce forum
#

The first two are confirmed, I'll see what card puts in the console

#

I removed the PM from the client and at my system's end and processed a new purchase, everything has gone through fine, PM attached to the client and ready for future use

#

Now performing a second purchase, using the existing PM

#

So far so good

#

Second payment successful

#

Now trying it with a change in PM, and seeing what comes through card in the console

#

I missed what it said as it navigated to the success page ๐Ÿคฆโ€โ™‚๏ธ
The original PM attached to the client is now gone and no new PM has been saved, checking the Stripe logs

simple thistle
#

what's the PaymentIntent id?

fierce forum
#

pi_3MnY1WD3yZL5Nmof1e8TrmzD

simple thistle
#

okay, i think i understand what's the problem you were facing now - that new PaymentMethod isn't saved for future use on the customer

fierce forum
#

That's correct

simple thistle
fierce forum
#

That's interesting, if that isn't in there just now why was it saving it previously?

#

(On the first purchase)

simple thistle
#

what's the first purchase?

fierce forum
#

Just a sec

#

pi_3MnXrLD3yZL5Nmof1NA1O2H3

simple thistle
#

you created the PaymentIntent with setup_future_usage

#

do you ever intend to charge the customer off_session?

#

or it'll always be on_session?

fierce forum
#

That's weird, that wasn't passed in my code

#

The client will always been the one initiating the payment via our site, no recurring payments without their input, so on_session

simple thistle
#

you could create the PaymentIntent without setup_future_usage, then decide whether to pass setup_future_usage in confirmCardPayment client-side

fierce forum
#

I like to keep things as simple as possible for our clients (fewer clicks meaning more sales etc), so I think I'll pass it in .confirmCardPayment

#

Now that's added, time to run through it all again and see if we're good to go

#

Aaaaaaand everything now works as expected ๐Ÿ˜

#

I appreciate your patience Alex, thanks again