diff --git a/src/Payments/PazeButton.res b/src/Payments/PazeButton.res index 8f495578..4d4a18ee 100644 --- a/src/Payments/PazeButton.res +++ b/src/Payments/PazeButton.res @@ -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) @@ -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) diff --git a/src/Payments/PazeWallet.res b/src/Payments/PazeWallet.res index 2be0cb33..5fe6134d 100644 --- a/src/Payments/PazeWallet.res +++ b/src/Payments/PazeWallet.res @@ -46,7 +46,8 @@ let make = () => { name: clientName, profileId: clientProfileId, }, - })->then(val => { + }) + ->then(val => { Console.log2("PAZE --- init completed", val) digitalWalletSdk.canCheckout({ emailAddress: "returninguser@paze.com", @@ -71,8 +72,7 @@ let make = () => { actionCode: "START_FLOW", transactionValue, shippingPreference: "ALL", - }) - ->then( + })->then( checkoutResponse => { Console.log2("PAZE --- Checkout Response Object: ", checkoutResponse) let completeObj = { @@ -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")