From 10bc54c0b3309b972c3853427f2edd3e26483bee Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa <136090360+vsrivatsa-juspay@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:36:03 +0530 Subject: [PATCH] feat: demo fixes customer id and retrieve request by client secret (#29) Co-authored-by: Jeeva Ramachandran <120017870+JeevaRamu0104@users.noreply.github.com> --- .../HyperSwitch/SDKPayment/SDKPaymentTypes.res | 1 + .../HyperSwitch/SDKPayment/SDKPaymentUtils.res | 2 ++ .../HyperSwitch/SDKPayment/TestPayment.res | 1 + src/screens/HyperSwitch/SDKPayment/WebSDK.res | 15 +++++---------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res b/src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res index 6ab6149af..546b37b09 100644 --- a/src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res +++ b/src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res @@ -2,4 +2,5 @@ type paymentType = { amount: int, currency: string, profile_id: string, + customer_id: string, } diff --git a/src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res b/src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res index ef663a6c5..14184cbdc 100644 --- a/src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res +++ b/src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res @@ -2,6 +2,7 @@ let initialValueForForm: string => SDKPaymentTypes.paymentType = profileId => { amount: 100, currency: "United States-USD", profile_id: profileId, + customer_id: "hyperswitch_sdk_demo_id", } let getTypedValueForPayment: Js.Json.t => SDKPaymentTypes.paymentType = values => { @@ -11,6 +12,7 @@ let getTypedValueForPayment: Js.Json.t => SDKPaymentTypes.paymentType = values = amount: dictOfValues->getInt("amount", 100), currency: dictOfValues->getString("currency", "United States-USD"), profile_id: dictOfValues->getString("profile_id", ""), + customer_id: dictOfValues->getString("customer_id", ""), } } diff --git a/src/screens/HyperSwitch/SDKPayment/TestPayment.res b/src/screens/HyperSwitch/SDKPayment/TestPayment.res index 6426605ed..b10d705ca 100644 --- a/src/screens/HyperSwitch/SDKPayment/TestPayment.res +++ b/src/screens/HyperSwitch/SDKPayment/TestPayment.res @@ -45,6 +45,7 @@ let make = ( ->Js.Json.number, ), ("profile_id", initialValues.profile_id->Js.Json.string), + ("customer_id", "hyperswitch_sdk_demo_id"->Js.Json.string), ])->Js.Json.object_ let response = await updateDetails(url, body, Post) let clientSecret = response->getDictFromJsonObject->getOptionString("client_secret") diff --git a/src/screens/HyperSwitch/SDKPayment/WebSDK.res b/src/screens/HyperSwitch/SDKPayment/WebSDK.res index bb2be9d4f..a9a0785c6 100644 --- a/src/screens/HyperSwitch/SDKPayment/WebSDK.res +++ b/src/screens/HyperSwitch/SDKPayment/WebSDK.res @@ -215,16 +215,11 @@ module CheckoutForm = { ->ignore } React.useEffect1(() => { - let id = Js.String2.split(clientSecret, "_secret_")[0]->Belt.Option.getWithDefault("") - switch Some(id) { - | None | Some("") => () - | Some(id) => - hyper.retrievePaymentIntent(id) - ->then(_ => { - resolve() - }) - ->ignore - } + hyper.retrievePaymentIntent(clientSecret) + ->then(_ => { + resolve() + }) + ->ignore None }, [hyper])