Skip to content

Commit

Permalink
fix: floating point value fix for test payment (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 authored Jan 18, 2024
1 parent 49e3eae commit 038a714
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/screens/HyperSwitch/SDKPayment/SDKPage.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ 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)
}
},
},
~isDisabled=false,
~customStyle="w-full",
~placeholder="Enter amount",
~precision=2,
(),
),
(),
Expand Down
6 changes: 3 additions & 3 deletions src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type billing = {
type orderDetails = {
product_name: string,
quantity: int,
amount: int,
amount: float,
}
type metadata = {order_details: orderDetails}

Expand Down Expand Up @@ -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<int>,
amount_to_capture: Js.Nullable.t<float>,
email: string,
name: string,
phone: string,
Expand Down
16 changes: 8 additions & 8 deletions src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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}`,
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/SDKPayment/WebSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ module CheckoutForm = {
| WIDGET => <CardWidget id="card-widget" options={paymentElementOptions} />
}}
<Button
text={`Pay ${currency} ${(amount / 100)->Belt.Int.toString}`}
text={`Pay ${currency} ${(amount /. 100.00)->Belt.Float.toString}`}
loadingText="Please wait..."
buttonState=btnState
buttonType={Primary}
Expand Down Expand Up @@ -282,7 +282,7 @@ let make = (
~methodsOrder=[],
~saveViewToSdk=false,
~isSpaceAccordion=false,
~amount=65400,
~amount=65400.00,
~setClientSecret,
) => {
let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading)
Expand Down

0 comments on commit 038a714

Please sign in to comment.