I create a Stripe subscription with a trial period, but at the end of the period, my subscription is canceled because of 3DS.
Frontend:
I am creating a payment method =>
const { error, paymentMethod } = await stripe.createPaymentMethod({
type: "card",
card: cardNumberElement,
});
I make a request to my backend, retrieve the clientSecret, and confirm the card setup =>
const response = await fetch("/api/create-customer", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email,
name: `${firstName} ${lastName}`,
payment_method: paymentMethod.id,
}),
});
const {data} = await response.json();
if (data.clientSecret) {
const { error: setupError, setupIntent } =
await stripe.confirmCardSetup(data.clientSecret, {
payment_method: paymentMethod.id,
});
if (setupError) {
setError("Échec de la configuration de la carte.");
setIsLoading(false);
} else if (setupIntent && setupIntent.status === "succeeded") {
setConfirm(true);
setIsLoading(false);
}
}
Backend:
I create my Stripe customer, attach the payment ID, and then create the subscription =>
await stripe.paymentMethods.attach(paymentMethodId, {
customer: customer.id,
});
await stripe.customers.update(customer.id, {
invoice_settings: {
default_payment_method: paymentMethodId,
},
});
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: price_id }],
trial_period_days: 30,
payment_behavior: 'default_incomplete',
expand: ['pending_setup_intent'],
payment_settings: {
save_default_payment_method: 'on_subscription',
}
});
const setupIntent = subscription.pending_setup_intent;
clientSecret = setupIntent?.client_secret;
return res.status(201).json({
status: 'ok',
data: {
message: 'User created',
clientSecret,
payment_method_id: paymentMethodId,
},
});
The 3DS modal is displayed correctly, I confirm, and everything seems fine. However, when the free trial ends, the subscription is canceled and I receive the following message: ‘The bank required 3D Secure authentication for this payment. Notify your customer to complete 3D Secure authentication for this payment.
Need some help to fix it, thanks for your help
(https://i.sstatic.net/YFLPZgCx.png)](https://i.sstatic.net/FyknWQtV.png)