#theahmadzai-setup-future-usage
1 messages · Page 1 of 1 (latest)
Hey! A Setup Intent will facilitate any necessary 3DS/auth requirements by the bank in order for the payment method to be reused off-session
Otherwise you're likely to see declines on recurring payments without that 'setup' process
but the payment intent api just takes the payment method to charge the customer
So how will setup intent be useful for me with payment intents
What exactly are you trying to achieve?
I want to charge on recurring bases using method method it's working fine
If you want to save a payment method for future usage without s Setup Intent, then you can during an initial payment: https://stripe.com/docs/payments/save-during-payment
Which payment method have you created?
That's outlined here: https://stripe.com/docs/payments/save-and-reuse
const paymentIntent = await this.stripe.paymentIntents.create(
{
amount: amountInCents,
application_fee_amount: Math.ceil((this.storeApplicationFee / 100) * amountInCents),
currency: 'usd',
setup_future_usage: 'off_session',
payment_method: paymentMethod,
customer: stripeCustomerId,
statement_descriptor: descriptor ?? '',
confirm: true,
},
stripe_id,
);
I use stripe.paymentIntents.create to charge but it takes customer and paymentMethod
You wouldn't pass the payment_method in this instance. You'd use Elements to capture the payment details and pass them to confirmPayment which would created the authenticated Payment Method object to reuse
The setup_future_usage parameter essentially emulates a Setup Intent
ah I see If I store payment method I cannot charge account unless I create setupitnent in stripe right
so setup intents are just permession for offsession charges
currently I do stripe checkouts where I set their cards for future usage of offsession and in the future I get list of payments from stripe and use the paymentIntent
const { data: cards } = await this.stripe.customers.listPaymentMethods(
stripeCustomerId,
{ type: 'card' },
stripe_id,
);
like this and sort by latest one
now I want to add functionality for customer to add their cards
So I would use stripe element to get setup_intent and just store the paymentMethod in my database and use that for future charges in paymentIntents right
Sure, that can work: https://stripe.com/docs/payments/save-and-reuse
Very similar integration to Payment Intents, you're just using a different API and confirmSetup in Stripe.js
Yes exactly. See https://stripe.com/docs/payments/save-and-reuse?platform=web#charge-saved-payment-method
You'd pass payment_method and customer parameters when creating a PI with a previously saved payment method
Thank you so much
Now I just want to confirm that Do I need t ostore payment method in my sode
or can stripe give me default payment method
I see that laravel cashier and other libs store last_4 digits and some other info
do I need to store payment method as well or use customer id to get his default method and list payment methods
You don't need to store the Payment Method IDs no. You can retrieve them from the API: https://stripe.com/docs/api/payment_methods/customer_list
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Or you can set one as a default on the Customer object: https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
but API gives me list of ids but how do I know which one is default and which one to use
But that doesn't really work for one-time payments its more for subscriptions. So you'll still need to provide the payment_method parameter when creating the PI
Well you could prevent a list in a UI of the saved cards for your customer to choose from
so
const cus = stripe.customers.retrieve('id', {
})
cus.invoice_settings.default_payment_method
I can use this to charge
and no need to store payment method
You could yes
But that might have unintended side effects if you ever started using Billing (subscriptions)
We do some recurring payments but not using stripe
subscription feature
we have our own recurring scheduled infrastructure
Got it
If customer adds 3 payment methods can I set one of them as default by myself
I don't see the property on paymentMethods.update
And each time I show dashboard to customer I don't see it useful to goto stripe and list payment methods so I can store last_4 card brand etc.. in db right but what's the better way to mark one of them as default
thanks!
you'd update the customer object: https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I'd just store all the pm_xxx IDs as fields on them may change (if the card gets updated by the bank for example)