#cheqo-charge-offsession
1 messages · Page 1 of 1 (latest)
cheqo-charge-offsession
@heady notch you should use the PaymentIntents API instead. See https://stripe.com/docs/payments/save-during-payment?platform=web#charge-saved-payment-method
So before creating payment intent:
-
check if customer has any payment methods saved
-
Conditionally pass payment method id to the paymentIntent creation if customer has one
And if I am using PaymentElement from react-stripe-js , there won't be any card inputs, but just a button to confirm payment?
There's no PaymentElement at all in this flow
PaymentElement is here to collect new payment method details. If you're using a previously saved card, you wouldn't render that UI/element at all in this case
more like building your own list of saved card(s) with a radio button like what Amazon does during checkout if that makes sense?
but that's only if your customer is "on session" like they are on your website/app ready to pay again
so I get the payment methods here:
const paymentMethods = await stripe.paymentMethods.list({
customer: '{{CUSTOMER_ID}}',
type: 'card',
});
and then simply create a charge in the same api call?
const charge = await stripe.charges.create({
amount: 2000,
currency: 'usd',
source: 'tok_mastercard',
description: 'My First Test Charge...'
where source is the paymentMethod.id?
well no, that will never work with the Charges API
use the PaymentIntents API which is what is compatible with PaymentMethod and PaymentElement and all of this. Basically exactly waht is in the doc I just linked you to
ok, so this code will automatically confirm payment intent then?
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'usd',
automatic_payment_methods: {enabled: true},
customer: '{{CUSTOMER_ID}}',
payment_method: '{{PAYMENT_METHOD_ID}}',
off_session: true,
confirm: true,
});
yes. I'd recommend trying it carefully in Test mode, will be as fast!
thanks so much, will try it out!