#negative10xprogrammer
1 messages ยท Page 1 of 1 (latest)
Hi ๐
There are multiple ways to add or attach a Payment Method to a customer. How are you creating the payment methods?
Hmm, havent thought of that. At first i created customers with paymentmethods (so just the paymentmethod token)
What is the preferred way of creating payment methods?
I think it happens at checkout, and since I use stripe elements and my flow assumes the client has fetched a paymentmethod token from stripe, I think I will be passing this token into the backend as usual
so... payment method token
Okay well Tokens have been deprecated for a while now. How are you processing payments? Do you use Payment Intents?
Ah ok... yes. So what is the alternative then? I'm, not sure if token is what i mean
paymentmethod is what i mean
a string object
The simple answer to your question is to use the Payment Method attach API: https://stripe.com/docs/api/payment_methods/attach
But it is much more simple and effective to use Setup Intents to create & attach the payment method to a customer.
https://stripe.com/docs/payments/save-and-reuse
OR
I do that in another flow
Save the payment method when your customer makes a payment
https://stripe.com/docs/payments/save-during-payment
the setup intent thing
Okay well that will create and attach payment methods to customers.
If you have already created payment methods you can use the attach API I linked above, as long as the payment method has not been charged
yeah alright, the customer alraedy exists
the customer alraedy exists
That doesn't change anything
Gotcha thanks!
Sure thing, happy to help ๐
@novel scarabjust to be sure, this means I could simply attach customerId when I create paymentintents and that's that?
What will happen next time a paymentintent is created with that customerId and the same paymentmethod?
will stripe dedupe it?
The save during payment means you both create & save the payment method at the same time as collecting payment.
If the customer comes back you can re-use the existing payment method.
What is it you are actually trying to do?
my current flow is like this:
stripe customer is created upon user registration. So all users in our system is a stripe customer. No paymnet methods at this point tho.
Upon purchase/checkout -> client, stripe elements. They input their card details, a paymentmethod is returned from stripe?
this paymentmethod retrieved from stripe is sent to our backend, and we use this to create a paymentintent
Now, obviously I want this to be saved to that customer. And then I ask stripe for that customers payment methods whenever they're in the custom checkout so they dont have to input that info again
this is a viable approach, no?
No I don't think so. If you didn't attach the payment method to the customer before the purchase then it's a one-time payment method and is consumed.
But I think you can simplify your approach
alright, because paymentintent takes customerid
If you use the "Save during payment" flow for your initial Checkout it will create the Payment Method and attach it to the customer when you confirm the Payment Intent
var options = new PaymentIntentCreateOptions
{
Amount = (long)amount * 100,
Currency = currency.ToString(), // Listing's currency
PaymentMethodTypes = new List<string> { StripePaymentMethods.Klarna },
TransferGroup = reservationId.ToString(),
Customer = customerId
};
Hmm ok
But I can still retrieve and use the paymentmethod in the way I outlined above? And your suggestion here means i need to move more logiuc to the client?
Okay now there appears to be Connect involved and I don't know what you trying to do. Also you cannot use Klarna payment methods for additonal charges
No in this case klarna is not for additional charges. I ahve a flag for payment method
so it's not relevant i think. What I'm trying to do is what I outlined above: get paymentmethod from client stripe elements, pass it to our backend, create paymentintent
but i want to "remember" that paymentmethod
Yup, It will get saved to the Customer object so you can retrieve it from the API but you can also save it to your DB.
Yes ok so this will work? Because you said above
"No I don't think so. If you didn't attach the payment method to the customer before the purchase then it's a one-time payment method and is consumed."
Correct, but if you use the flow I linked above it will attach the PM and it is designed specifically to be reused
so both flows work but the one you suggest is more correct?
and last question, what happens if every time I create a payment intent its the same customer and paymentmethod? will stripe ignore the duplicate?
so both flows work but the one you suggest is more correct?
This flow is more correct <https://stripe.com/docs/payments/save-during-payment >
Even if the same customer provides the same card info, it will create a new Payment Method