Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix: report Stripe.js failures as a payment error instead of hanging

Gilad Resisice7fccb7dddc
diff --git a/apps/frontend/src/components/billing/use.payment.action.tsx b/apps/frontend/src/components/billing/use.payment.action.tsx
index 431d10e2f..9f651ed82 100644
--- a/apps/frontend/src/components/billing/use.payment.action.tsx
+++ b/apps/frontend/src/components/billing/use.payment.action.tsx
@@ -9,9 +9,15 @@ export const usePaymentAction = () => {
// Consuming the PaymentIntent client_secret with the publishable key is
// Stripe's intended flow: https://docs.stripe.com/api/payment_intents/object#payment_intent_object-client_secret
async (clientSecret: string) => {
- const stripe = await loadStripe(stripeClient);
- const { error } = await stripe!.handleNextAction({ clientSecret });
- return { error: error?.message };
+ try {
+ const stripe = await loadStripe(stripeClient);
+ const { error } = await stripe!.handleNextAction({ clientSecret });
+ return { error: error?.message };
+ } catch (err: any) {
+ // Stripe.js rejects when it fails to load or when the intent is no
+ // longer in requires_action, the caller only reads `error`
+ return { error: err?.message || 'Payment failed' };
+ }
},
[stripeClient]
);