From 038a71492de22f1a1a51b6de9f68f010bf872268 Mon Sep 17 00:00:00 2001 From: Riddhiagrawal001 <50551695+Riddhiagrawal001@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:58:09 +0530 Subject: [PATCH] fix: floating point value fix for test payment (#270) --- src/screens/HyperSwitch/SDKPayment/SDKPage.res | 9 +++++---- .../HyperSwitch/SDKPayment/SDKPaymentTypes.res | 6 +++--- .../HyperSwitch/SDKPayment/SDKPaymentUtils.res | 16 ++++++++-------- src/screens/HyperSwitch/SDKPayment/WebSDK.res | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/screens/HyperSwitch/SDKPayment/SDKPage.res b/src/screens/HyperSwitch/SDKPayment/SDKPage.res index 7d87fe11f..6542b3032 100644 --- a/src/screens/HyperSwitch/SDKPayment/SDKPage.res +++ b/src/screens/HyperSwitch/SDKPayment/SDKPage.res @@ -49,13 +49,13 @@ module SDKConfiguarationFields = { InputFields.numericTextInput( ~input={ ...input, - value: (initialValues.amount / 100)->string_of_int->Js.Json.string, + value: (initialValues.amount /. 100.00)->Js.Float.toString->Js.Json.string, onChange: { ev => { - let eventValueToInt = - ev->Identity.formReactEventToString->LogicUtils.getIntFromString(0) + let eventValueToFloat = + ev->Identity.formReactEventToString->LogicUtils.getFloatFromString(0.00) let valInCents = - (eventValueToInt * 100)->string_of_int->Identity.stringToFormReactEvent + (eventValueToFloat *. 100.00)->Js.Float.toString->Identity.stringToFormReactEvent input.onChange(valInCents) } }, @@ -63,6 +63,7 @@ module SDKConfiguarationFields = { ~isDisabled=false, ~customStyle="w-full", ~placeholder="Enter amount", + ~precision=2, (), ), (), diff --git a/src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res b/src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res index 631956251..2b1b8e2f2 100644 --- a/src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res +++ b/src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res @@ -27,7 +27,7 @@ type billing = { type orderDetails = { product_name: string, quantity: int, - amount: int, + amount: float, } type metadata = {order_details: orderDetails} @@ -55,13 +55,13 @@ type mandateData = { } type paymentType = { - amount: int, + amount: float, mutable currency: string, profile_id: string, customer_id: string, description: string, capture_method: string, - amount_to_capture: Js.Nullable.t, + amount_to_capture: Js.Nullable.t, email: string, name: string, phone: string, diff --git a/src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res b/src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res index 31e35445a..39bcc56f0 100644 --- a/src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res +++ b/src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res @@ -1,6 +1,6 @@ let initialValueForForm: HSwitchSettingTypes.profileEntity => SDKPaymentTypes.paymentType = defaultBusinessProfile => { { - amount: 10000, + amount: 10000.00, currency: "United States-USD", profile_id: defaultBusinessProfile.profile_id, description: "Default value", @@ -48,11 +48,11 @@ let initialValueForForm: HSwitchSettingTypes.profileEntity => SDKPaymentTypes.pa order_details: { product_name: "Apple iphone 15", quantity: 1, - amount: 100, + amount: 100.00, }, }, capture_method: "automatic", - amount_to_capture: Js.Nullable.return(100), + amount_to_capture: Js.Nullable.return(100.00), return_url: `${Window.Location.origin}${Window.Location.pathName}`, } } @@ -95,7 +95,7 @@ let getTypedValueForPayment: Js.Json.t => SDKPaymentTypes.paymentType = values = }, }, } - let amount = dictOfValues->getInt("amount", 100) + let amount = dictOfValues->getFloat("amount", 100.00) { amount, @@ -150,10 +150,10 @@ let getTypedValueForPayment: Js.Json.t => SDKPaymentTypes.paymentType = values = }, }, capture_method: "automatic", - amount_to_capture: amount === 0 ? Js.Nullable.null : Js.Nullable.return(amount), + amount_to_capture: amount === 0.00 ? Js.Nullable.null : Js.Nullable.return(amount), return_url: dictOfValues->getString("return_url", ""), - payment_type: amount === 0 ? Js.Nullable.return("setup_mandate") : Js.Nullable.null, - setup_future_usage: amount === 0 ? Js.Nullable.return("off_session") : Js.Nullable.null, - mandate_data: amount === 0 ? Js.Nullable.return(mandateData) : Js.Nullable.null, + payment_type: amount === 0.00 ? Js.Nullable.return("setup_mandate") : Js.Nullable.null, + setup_future_usage: amount === 0.00 ? Js.Nullable.return("off_session") : Js.Nullable.null, + mandate_data: amount === 0.00 ? Js.Nullable.return(mandateData) : Js.Nullable.null, } } diff --git a/src/screens/HyperSwitch/SDKPayment/WebSDK.res b/src/screens/HyperSwitch/SDKPayment/WebSDK.res index 170873f83..505a32eaf 100644 --- a/src/screens/HyperSwitch/SDKPayment/WebSDK.res +++ b/src/screens/HyperSwitch/SDKPayment/WebSDK.res @@ -232,7 +232,7 @@ module CheckoutForm = { | WIDGET => }}