diff --git a/src/PaymentElement.res b/src/PaymentElement.res index 756b3e19a..4f5048b99 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -398,7 +398,8 @@ let make = ( React.useEffect(() => { let evalMethodsList = () => switch methodslist { - | SemiLoaded | Loaded(_) => handlePostMessage([("ready", true->JSON.Encode.bool)]) + | SemiLoaded | LoadError(_) | Loaded(_) => + handlePostMessage([("ready", true->JSON.Encode.bool)]) | _ => () } if !displaySavedPaymentMethods { diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 83937b42d..3042deedd 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -976,26 +976,39 @@ let usePaymentIntent = (optLogger: option, paymentType: p } switch list { + | LoadError(data) | Loaded(data) => let paymentList = data->getDictFromJson->PaymentMethodsRecord.itemToObjMapper let mandatePaymentType = paymentList.payment_type->PaymentMethodsRecord.paymentTypeToStringMapper - switch paymentList.mandate_payment { - | Some(_) => - switch paymentType { - | Card - | Gpay - | Applepay - | KlarnaRedirect - | Paypal - | BankDebits => - intentWithMandate(mandatePaymentType) - | _ => intentWithoutMandate(mandatePaymentType) + if paymentList.payment_methods->Array.length > 0 { + switch paymentList.mandate_payment { + | Some(_) => + switch paymentType { + | Card + | Gpay + | Applepay + | KlarnaRedirect + | Paypal + | BankDebits => + intentWithMandate(mandatePaymentType) + | _ => intentWithoutMandate(mandatePaymentType) + } + | None => intentWithoutMandate(mandatePaymentType) } - | None => intentWithoutMandate(mandatePaymentType) + } else { + postFailedSubmitResponse( + ~errortype="payment_methods_empty", + ~message="Payment Failed. Try again!", + ) + Console.warn("Please enable atleast one Payment method.") } | SemiLoaded => intentWithoutMandate("") - | _ => () + | _ => + postFailedSubmitResponse( + ~errortype="payment_methods_loading", + ~message="Please wait. Try again!", + ) } | None => postFailedSubmitResponse(