Skip to content

Commit

Permalink
fix: confirm call integration
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja committed Oct 22, 2024
1 parent 703aa18 commit 705fea2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/Payments/PazeButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down
4 changes: 3 additions & 1 deletion src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -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"
| "" =>
Expand Down

0 comments on commit 705fea2

Please sign in to comment.