Reputation: 26
i am trying to integrate payment sheet with customer(stripe customer id) and save card option(as shown in image) and the customer was linked with payment but Save this card for future powdur payments option was not showing. i can't understand why that's not showing? if any buddy have idea about this then pls tell..
server-side Code
createCustomer
exports.handler = async (event) => {
console.log(JSON.stringify(event.arguments));
const customer = await stripe.customers.create({
name: event.arguments?.input?.name,
email: event.arguments.input?.email,
payment_method: 'pm_card_visa',
invoice_settings: {
default_payment_method: 'pm_card_visa',
},
});
console.log('Customer Data', JSON.stringify(customer));
return {
id: customer.id ?? 'Default',
};
};
createPaymentIntent
exports.handler = async (event) => {
console.log('Event', JSON.stringify(event.arguments.input));
try {
const paymentIntent = await stripe.paymentIntents.create({ ...event.arguments.input });
console.log(paymentIntent.client_secret);
return {
clientSecret: paymentIntent.client_secret,
};
} catch (error) {
console.log(JSON.stringify(error));
return {
error: error.message,
};
}
};
/** createIntent data
* description: 'Software development services',
customer: customerId,
shipping: {
name: 'Jenny Rosen',
address: {
line1: '510 Townsend St',
postal_code: '98140',
city: 'San Francisco',
state: 'CA',
country: 'US',
},
},
amount: 1099,
currency: 'usd',
payment_method_types: ['card'],
*/
Upvotes: 1
Views: 1590
Reputation: 1133
You need to specify the customerId while initializing the PaymentSheet in your frontend so that the created PaymentMethod will be attached to a customer and it can be used for future payments[1]
const { error } = await initPaymentSheet({
customerId: customer,
customerEphemeralKeySecret: ephemeralKey,
paymentIntentClientSecret: paymentIntent,
});
Upvotes: 0