From 705fea2ae34e251c059f027187311b9be3519792 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Tue, 22 Oct 2024 15:31:26 +0530 Subject: [PATCH] fix: confirm call integration --- src/Payments/PazeButton.res | 22 ++++++++++++++++------ src/Utilities/PaymentBody.res | 16 ++++++++++++++++ src/Utilities/PaymentHelpers.res | 4 +++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/Payments/PazeButton.res b/src/Payments/PazeButton.res index 4d4a18eec..609711f87 100644 --- a/src/Payments/PazeButton.res +++ b/src/Payments/PazeButton.res @@ -7,6 +7,10 @@ let make = (~token: SessionsType.token) => { let (showLoader, setShowLoader) = React.useState(() => false) let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue) let setIsShowOrPayUsing = Recoil.useSetRecoilState(RecoilAtoms.isShowOrPayUsing) + let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom) + let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Paze) + let isManualRetryEnabled = Recoil.useRecoilValueFromAtom(isManualRetryEnabled) + let options = Recoil.useRecoilValueFromAtom(optionAtom) React.useEffect0(() => { setIsShowOrPayUsing(_ => true) @@ -35,18 +39,24 @@ 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 - // } + if dict->getOptionString("completeResponse")->Option.isSome { + let completeResponse = dict->getString("completeResponse", "") + intent( + ~bodyArr=PaymentBody.pazeBody(~completeResponse), + ~confirmParam={ + return_url: options.wallets.walletReturnUrl, + publishableKey, + }, + ~handleUserError=false, + ~manualRetry=isManualRetryEnabled, + ) + } } } Window.addEventListener("message", onPazeCallback) diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res index ba6e8f922..100828d48 100644 --- a/src/Utilities/PaymentBody.res +++ b/src/Utilities/PaymentBody.res @@ -976,6 +976,22 @@ let multibancoBody = (~email) => [ ), ] +let pazeBody = (~completeResponse) => { + open Utils + let pazeCompleteResponse = + [("complete_response", completeResponse->JSON.Encode.string)]->getJsonFromArrayOfJson + + let pazeWalletData = [("paze", pazeCompleteResponse)]->getJsonFromArrayOfJson + + let paymentMethodData = [("wallet", pazeWalletData)]->getJsonFromArrayOfJson + + [ + ("payment_method", "wallet"->JSON.Encode.string), + ("payment_method_type", "paze"->JSON.Encode.string), + ("payment_method_data", paymentMethodData), + ] +} + let getPaymentMethodType = (paymentMethod, paymentMethodType) => switch paymentMethod { | "bank_debit" => paymentMethodType->String.replace("_debit", "") diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 08179118e..668db6157 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -8,12 +8,14 @@ type url = {searchParams: searchParams, href: string} @new external urlSearch: string => url = "URL" open LoggerUtils -type payment = Card | BankTransfer | BankDebits | KlarnaRedirect | Gpay | Applepay | Paypal | Other +type payment = + Card | BankTransfer | BankDebits | KlarnaRedirect | Gpay | Applepay | Paypal | Paze | Other let getPaymentType = paymentMethodType => switch paymentMethodType { | "apple_pay" => Applepay | "google_pay" => Gpay + | "paze" => Gpay | "debit" | "credit" | "" =>