Skip to content

Commit

Permalink
fix: (paymenthelpers, paymentelement) promise being unresolved (#297)
Browse files Browse the repository at this point in the history
Co-authored-by: Pritish Budhiraja <[email protected]>
  • Loading branch information
prafulkoppalkar and Pritish Budhiraja authored Apr 17, 2024
1 parent a112832 commit 6494f51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 26 additions & 13 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -976,26 +976,39 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, 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(
Expand Down

0 comments on commit 6494f51

Please sign in to comment.