पाठ 11 / 25
Saving Cards and Off-Session Payments
SetupIntents and charging later.
SetupIntents and off_session
To save a payment method for later without charging now, create a SetupIntent for a Customer and confirm it on the client with stripe.confirmSetup; this performs any needed authentication up front and attaches the PaymentMethod to the Customer. To save a card while taking a first payment, pass setup_future_usage: 'off_session' on the PaymentIntent. Later, when the customer is not present (a usage bill, a reorder), create a PaymentIntent with customer, payment_method, off_session: true and confirm: true. The issuer may still demand authentication; then the request fails with error code authentication_required, and you must bring the customer back on-session to complete it.
Save now, charge later
Server-side Node.js.
// 1. Save a card for future use (confirm on the client with stripe.confirmSetup)
const setupIntent = await stripe.setupIntents.create({
customer: 'cus_...',
automatic_payment_methods: { enabled: true },
usage: 'off_session',
});
// send setupIntent.client_secret to the browser
// 2. Later, charge the saved payment method while the customer is away
try {
await stripe.paymentIntents.create({
amount: 2500,
currency: 'usd',
customer: 'cus_...',
payment_method: 'pm_...',
off_session: true,
confirm: true,
});
} catch (err) {
if (err.code === 'authentication_required') {
await emailCustomerToAuthenticate(err.raw.payment_intent.id);
} else {
throw err;
}
}
A signed standing order
A SetupIntent is like signing a mandate at the bank counter while you are there, so later payments can go through without you, though the bank may still occasionally call you to check.
त्वरित जाँच: Which object saves a payment method for later without charging it now?
- Price
- Refund
- Payout
- SetupIntent
Answer
SetupIntent — SetupIntents collect and authenticate payment details for future use.