From b1921908934e02cb65671ef3efa737a137ff8652 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Mon, 28 Oct 2024 13:47:46 +0530 Subject: [PATCH] fix: session token response destructuring added --- src/Payments/PazeButton.res | 12 +++++++----- src/Payments/PazeWallet.res | 26 +++++++++++++++----------- src/Types/SessionsType.res | 9 +++++++++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/Payments/PazeButton.res b/src/Payments/PazeButton.res index 609711f8..411beee9 100644 --- a/src/Payments/PazeButton.res +++ b/src/Payments/PazeButton.res @@ -2,15 +2,15 @@ let make = (~token: SessionsType.token) => { open Utils open RecoilAtoms - let {iframeId, publishableKey} = Recoil.useRecoilValueFromAtom(keys) + let {iframeId, publishableKey, clientSecret} = Recoil.useRecoilValueFromAtom(keys) let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) + let options = Recoil.useRecoilValueFromAtom(optionAtom) 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) + let paymentIntentID = clientSecret->Option.getOr("")->getPaymentId React.useEffect0(() => { setIsShowOrPayUsing(_ => true) @@ -30,9 +30,11 @@ let make = (~token: SessionsType.token) => { ("clientId", token.clientId->JSON.Encode.string), ("clientName", token.clientName->JSON.Encode.string), ("clientProfileId", token.clientProfileId->JSON.Encode.string), - ("sessionId", token.sessionId->JSON.Encode.string), - ("currency", paymentMethodListValue.currency->JSON.Encode.string), + ("sessionId", paymentIntentID->JSON.Encode.string), ("publishableKey", publishableKey->JSON.Encode.string), + ("emailAddress", token.email_address->JSON.Encode.string), + ("transactionAmount", token.transaction_amount->JSON.Encode.string), + ("transactionCurrencyCode", token.transaction_currency_code->JSON.Encode.string), ]->getJsonFromArrayOfJson, ), ]) diff --git a/src/Payments/PazeWallet.res b/src/Payments/PazeWallet.res index 5fe6134d..74c03543 100644 --- a/src/Payments/PazeWallet.res +++ b/src/Payments/PazeWallet.res @@ -12,8 +12,10 @@ let make = () => { let (clientName, setClientName) = React.useState(() => "") let (clientProfileId, setClientProfileId) = React.useState(() => "") let (sessionId, setSessionId) = React.useState(() => "") - let (currency, setCurrency) = React.useState(() => "") let (publishableKey, setPublishableKey) = React.useState(() => "") + let (emailAddress, setEmailAddress) = React.useState(() => "") + let (transactionAmount, setTransactionAmount) = React.useState(() => "") + let (transactionCurrencyCode, setTransactionCurrencyCode) = React.useState(() => "") React.useEffect0(() => { let handle = (ev: Window.event) => { @@ -24,8 +26,10 @@ let make = () => { setClientName(_ => metaData->getString("clientName", "")) setClientProfileId(_ => metaData->getString("clientProfileId", "")) setSessionId(_ => metaData->getString("sessionId", "")) - setCurrency(_ => metaData->getString("currency", "")) setPublishableKey(_ => metaData->getString("publishableKey", "")) + setEmailAddress(_ => metaData->getString("emailAddress", "")) + setTransactionAmount(_ => metaData->getString("transactionAmount", "")) + setTransactionCurrencyCode(_ => metaData->getString("transactionCurrencyCode", "")) } } Window.addEventListener("message", handle) @@ -50,13 +54,13 @@ let make = () => { ->then(val => { Console.log2("PAZE --- init completed", val) digitalWalletSdk.canCheckout({ - emailAddress: "returninguser@paze.com", + emailAddress: emailAddress, })->then(consumerPresent => { Console.log("PAZE --- canCheckout completed") Console.log2("PAZE --- consumerPresent: ", consumerPresent) let transactionValue = { - transactionAmount: "50.21", - transactionCurrencyCode: currency, + transactionAmount, + transactionCurrencyCode, } let transactionOptions = { @@ -67,8 +71,8 @@ let make = () => { digitalWalletSdk.checkout({ acceptedPaymentCardNetworks: ["VISA", "MASTERCARD"], - emailAddress: "returninguser@paze.com", - sessionId: "m2cxrizr6scgriug1pg", + emailAddress, + sessionId, actionCode: "START_FLOW", transactionValue, shippingPreference: "ALL", @@ -78,7 +82,7 @@ let make = () => { let completeObj = { transactionOptions, transactionId: "", - sessionId: "m2cxrizr6scgriug1pg", + sessionId, transactionType: "PURCHASE", transactionValue, } @@ -128,13 +132,13 @@ let make = () => { clientId != "" && clientName != "" && clientProfileId != "" && - // sessionId != "" && - currency != "" + sessionId != "" && + transactionCurrencyCode != "" ) { mountPazeSDK() } None - }, [clientId, clientName, clientProfileId, sessionId, currency]) + }, [clientId, clientName, clientProfileId, sessionId, transactionCurrencyCode])
} diff --git a/src/Types/SessionsType.res b/src/Types/SessionsType.res index 59c722ff..07d0396c 100644 --- a/src/Types/SessionsType.res +++ b/src/Types/SessionsType.res @@ -21,6 +21,9 @@ type token = { clientId: string, clientName: string, clientProfileId: string, + email_address: string, + transaction_amount: string, + transaction_currency_code: string, } type tokenType = @@ -55,6 +58,9 @@ let defaultToken = { clientId: "", clientName: "", clientProfileId: "", + email_address: "", + transaction_amount: "", + transaction_currency_code: "", } let getWallet = str => { switch str { @@ -89,6 +95,9 @@ let getSessionsToken = (dict, str) => clientId: getString(dict, "client_id", ""), clientName: getString(dict, "client_name", ""), clientProfileId: getString(dict, "client_profile_id", ""), + email_address: getString(dict, "email_address", ""), + transaction_amount: getString(dict, "transaction_amount", ""), + transaction_currency_code: getString(dict, "transaction_currency_code", ""), } }) })