Skip to content

Commit

Permalink
fix: Handling error cases for payment methods list (#164)
Browse files Browse the repository at this point in the history
Co-authored-by: Praful Koppalkar <[email protected]>
Co-authored-by: Akash Kamble <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2024
1 parent 6b197c9 commit 8df24df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
logger.setLogInitiated()
switch paymentlist {
| Loaded(_)
| LoadError(_) => ()
| LoadError => ()
| _ =>
setList(._ =>
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? SemiLoaded : Loading
Expand Down Expand Up @@ -340,10 +340,16 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
if dict->getDictIsSome("paymentMethodList") {
let list = dict->getJsonObjectFromDict("paymentMethodList")
list == Js.Dict.empty()->Js.Json.object_
? setList(._ => LoadError(Js.Dict.empty()->Js.Json.object_))
? setList(._ => LoadError)
: switch list->Utils.getDictFromJson->Js.Dict.get("error") {
| Some(err) => setList(._ => LoadError(err))
| None => setList(._ => Loaded(list))
| Some(_) => setList(._ => LoadError)
| None =>
let isNonEmptyPaymentMethodList =
list
->Utils.getDictFromJson
->Utils.getArray("payment_methods")
->Js.Array2.length > 0
setList(._ => isNonEmptyPaymentMethodList ? Loaded(list) : LoadError)
}
}
if dict->getDictIsSome("customerPaymentMethods") {
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ let make = (
)
}
: ()
| LoadError
| SemiLoaded =>
setPaymentOptions(_ =>
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? ["card"] : []
Expand Down Expand Up @@ -142,7 +143,7 @@ let make = (
? ""
: switch methodslist {
| SemiLoaded
| LoadError(_) =>
| LoadError =>
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? "card" : ""
| Loaded(_) =>
paymentOptions->Js.Array2.includes(selectedOption) && showCardFormByDefault
Expand Down Expand Up @@ -319,7 +320,7 @@ let make = (
<PoweredBy />
</RenderIf>
{switch methodslist {
| LoadError(_) => React.null
| LoadError => React.null
| _ =>
<RenderIf
condition={paymentOptions->Js.Array2.length == 0 && walletOptions->Js.Array2.length == 0}>
Expand Down
4 changes: 2 additions & 2 deletions src/Types/PaymentType.res
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ let getAddress = (dict, str, logger) => {
line2: getWarningString(json, "line2", "", ~logger),
city: getWarningString(json, "city", "", ~logger),
state: getWarningString(json, "state", "", ~logger),
country: country,
country,
postal_code: getWarningString(json, "postal_code", "", ~logger),
}
})
Expand Down Expand Up @@ -893,7 +893,7 @@ let itemToObjMapper = (dict, logger) => {
}
}

type loadType = Loading | Loaded(Js.Json.t) | SemiLoaded | LoadError(Js.Json.t)
type loadType = Loading | Loaded(Js.Json.t) | SemiLoaded | LoadError

let getIsAllStoredCardsHaveName = (savedCards: array<customerMethods>) => {
savedCards
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ let usePaymentSync = (optLogger: option<OrcaLogger.loggerMake>, paymentType: pay
| Loaded(_) => paymentSync()
| SemiLoaded
| Loading
| LoadError(_) => ()
| LoadError => ()
}
| None =>
postFailedSubmitResponse(
Expand Down Expand Up @@ -629,7 +629,7 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, paymentType: p
}
| SemiLoaded => intentWithoutMandate()
| Loading
| LoadError(_) => ()
| LoadError => ()
}
| None =>
postFailedSubmitResponse(
Expand Down

0 comments on commit 8df24df

Please sign in to comment.