#rsdotscot
1 messages ยท Page 1 of 1 (latest)
hello! can you share more on what you're trying to do?
(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!
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?
stripe.elements()
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
i think you should be using the Card Element : elements.create('card'); - using the same PaymentIntent in your frontend, you should be able to confirm with the details in the card element that the customer has filled up : https://stripe.com/docs/payments/accept-card-payments?platform=web&ui=elements#web-submit-payment
Yep, that's in there
try it out and let me know if you're still having trouble
It's been in there the whole time ๐
Give me a moment and I'll send a snippet URL
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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
what's your question?
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
if i look at that PaymentIntent, you're trying to "reset" the PaymentMethod : https://dashboard.stripe.com/test/logs/req_TzgBrEhJeS6lG7
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
which fails
Yep, it threw an error at me when I tried it
you don't need to "reset" it
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?
That's what I'm trying to do, but what I have doesn't save the new card at this point
This one? https://pastebin.com/9R40BSbc
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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
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
cardwhich confirmCardPayment is supposed to be passing intopayment_methodin confirmCardPayment
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
what's the PaymentIntent id?
pi_3MnY1WD3yZL5Nmof1e8TrmzD
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
That's correct
https://stripe.com/docs/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-data-setup_future_usage - include this parameter if you're saving a new PaymentMethod
That's interesting, if that isn't in there just now why was it saving it previously?
(On the first purchase)
what's the first purchase?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
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?
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
you could create the PaymentIntent without setup_future_usage, then decide whether to pass setup_future_usage in confirmCardPayment client-side
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