@@ -6,6 +6,7 @@ import z from "zod";
66import { sendAwaitingPaymentEmailAndSMS } from "@calcom/emails" ;
77import { ErrorCode } from "@calcom/lib/errorCodes" ;
88import { getErrorFromUnknown } from "@calcom/lib/errors" ;
9+ import { ErrorWithCode } from "@calcom/lib/errors" ;
910import logger from "@calcom/lib/logger" ;
1011import { safeStringify } from "@calcom/lib/safeStringify" ;
1112import prisma from "@calcom/prisma" ;
@@ -296,7 +297,28 @@ export class PaymentService implements IAbstractPaymentService {
296297 return paymentData ;
297298 } catch ( error ) {
298299 log . error ( "Stripe: Could not charge card for payment" , _bookingId , safeStringify ( error ) ) ;
299- throw new Error ( ErrorCode . ChargeCardFailure ) ;
300+
301+ const errorMappings = {
302+ "your card was declined" : "your_card_was_declined" ,
303+ "your card does not support this type of purchase" :
304+ "your_card_does_not_support_this_type_of_purchase" ,
305+ "amount must convert to at least" : "amount_must_convert_to_at_least" ,
306+ } ;
307+
308+ let userMessage = "could_not_charge_card" ;
309+
310+ if ( error instanceof Error ) {
311+ const errorMessage = error . message . toLowerCase ( ) ;
312+
313+ for ( const [ key , message ] of Object . entries ( errorMappings ) ) {
314+ if ( errorMessage . includes ( key ) ) {
315+ userMessage = message ;
316+ break ;
317+ }
318+ }
319+ }
320+
321+ throw new ErrorWithCode ( ErrorCode . ChargeCardFailure , userMessage ) ;
300322 }
301323 }
302324
0 commit comments