Skip to content

Commit

Permalink
fix: fixes the catch handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja committed Oct 21, 2024
1 parent 0fd4849 commit 703aa18
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/Payments/PazeButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ let make = (~token: SessionsType.token) => {
let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom)
let (showLoader, setShowLoader) = React.useState(() => false)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
let setIsShowOrPayUsing = Recoil.useSetRecoilState(RecoilAtoms.isShowOrPayUsing)

React.useEffect0(() => {
setIsShowOrPayUsing(_ => true)
None
})

let onClick = _ => {
setShowLoader(_ => true)
Expand All @@ -29,12 +35,18 @@ let make = (~token: SessionsType.token) => {
}

React.useEffect0(() => {
// open Promise
let onPazeCallback = (ev: Window.event) => {
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson->getDictFromDict("data")
let isPaze = dict->getBool("isPaze", false)
if isPaze {
setShowLoader(_ => false)
Js.log2("PAZE --- onPazeCallback", dict)

// if dict->getOptionString("completeResponse")->Option.isSome {
// confirm call need to be done over here
// }
}
}
Window.addEventListener("message", onPazeCallback)
Expand Down
33 changes: 22 additions & 11 deletions src/Payments/PazeWallet.res
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ let make = () => {
name: clientName,
profileId: clientProfileId,
},
})->then(val => {
})
->then(val => {
Console.log2("PAZE --- init completed", val)
digitalWalletSdk.canCheckout({
emailAddress: "[email protected]",
Expand All @@ -71,8 +72,7 @@ let make = () => {
actionCode: "START_FLOW",
transactionValue,
shippingPreference: "ALL",
})
->then(
})->then(
checkoutResponse => {
Console.log2("PAZE --- Checkout Response Object: ", checkoutResponse)
let completeObj = {
Expand All @@ -85,21 +85,32 @@ let make = () => {
digitalWalletSdk.complete(completeObj)->then(
completeResponse => {
Console.log2("PAZE --- Complete Response Object: ", completeResponse)
messageParentWindow([
("fullscreen", false->JSON.Encode.bool),
("isPaze", true->JSON.Encode.bool),
(
"completeResponse",
completeResponse
->getDictFromJson
->getString("completeResponse", "")
->JSON.Encode.string,
),
])
resolve()
},
)
},
)
->finally(
_ =>
messageParentWindow([
("fullscreen", false->JSON.Encode.bool),
("isPaze", true->JSON.Encode.bool),
("publicToken", "shdchdbdc"->JSON.Encode.string),
]),
)
})
})
->catch(_ => {
messageParentWindow([
("fullscreen", false->JSON.Encode.bool),
("isPaze", true->JSON.Encode.bool),
("flowExited", "stop"->JSON.Encode.string),
])
resolve()
})
}

let pazeScript = Window.createElement("script")
Expand Down

0 comments on commit 703aa18

Please sign in to comment.