From 1c46f92565bcc831b06a248d40d98394a4921dcb Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 14 Feb 2024 14:59:46 +0100 Subject: [PATCH] fix: only use client secrets if there's no providerMethodId set --- src/lib/stores/stripe.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/stores/stripe.ts b/src/lib/stores/stripe.ts index 5730a4c866..fd89db0047 100644 --- a/src/lib/stores/stripe.ts +++ b/src/lib/stores/stripe.ts @@ -19,7 +19,12 @@ export async function initializeStripe() { isStripeInitialized.set(true); const methods = await sdk.forConsole.billing.listPaymentMethods(); - clientSecret = methods.paymentMethods[0]?.clientSecret; + + // Get the client secret from empty payment method if available + clientSecret = methods.paymentMethods?.filter( + (method) => !!method?.clientSecret && !method?.providerMethodId + )[0]?.clientSecret; + // If there is no payment method, create an empty one and get the client secret if (!clientSecret) { paymentMethod = await sdk.forConsole.billing.createPaymentMethod();