From 49e3eaeb9bd14a3c788649b81cf561386a5ce006 Mon Sep 17 00:00:00 2001
From: Pritish Budhiraja <1805317@kiit.ac.in>
Date: Thu, 18 Jan 2024 14:57:47 +0530
Subject: [PATCH 1/6] chore: Added Access Type & Remove the Read & ReadWrite
Type (#267)
---
src/components/EntityScaffold.res | 75 +++----------------
src/components/UnauthorizedPage.res | 19 +++++
src/components/form/BoolInput.res | 11 +--
src/context/FormAuthContext.res | 2 +-
.../hyperswitch/HyperSwitchApp.res | 12 +--
src/entryPoints/hyperswitch/SidebarValues.res | 44 +++++------
.../UserManagement/PermissionUtils.res | 2 +-
src/screens/login/AuthTypes.res | 2 +-
8 files changed, 63 insertions(+), 104 deletions(-)
create mode 100644 src/components/UnauthorizedPage.res
diff --git a/src/components/EntityScaffold.res b/src/components/EntityScaffold.res
index d9d048b33..68afbe809 100644
--- a/src/components/EntityScaffold.res
+++ b/src/components/EntityScaffold.res
@@ -1,85 +1,32 @@
-module ComingSoon = {
- @react.component
- let make = (~title) => {
-
-
{React.string(title)}
-
{React.string("Coming soon...")}
-
- }
-}
-
-module ShowPage = {
- @react.component
- let make = (~entityName, ~id) => {
-
-
- {React.string(`Show ${entityName} `)}
- {React.string(`#${id}`)}
-
-
{React.string("Coming soon...")}
-
- }
-}
-
-module UnauthorizedPage = {
- @react.component
- let make = (~entityName) => {
-
-
{React.string(entityName)}
-
{React.string("You don't have access to this module. Contact admin for access")}
-
- }
-}
-
@react.component
let make = (
~entityName="",
~remainingPath,
~isAdminAccount=false,
- ~access: AuthTypes.authorization=ReadWrite,
- ~renderList=() => ,
- ~renderNewForm=() => ,
+ ~access: AuthTypes.authorization=Access,
+ ~renderList,
+ ~renderNewForm=?,
~renderShow=?,
- ~renderOrder=?,
- ~renderEdit=_id => ,
- ~renderEditWithMultiId=(_id1, _id2) => ,
- ~renderClone=_id => ,
) => {
if access === NoAccess {
-
+
} else {
switch remainingPath {
| list{"new"} =>
switch access {
- | ReadWrite => renderNewForm()
- | _ =>
- }
- | list{id, "clone"} =>
- switch access {
- | ReadWrite => renderClone(id)
- | _ =>
+ | Access =>
+ switch renderNewForm {
+ | Some(element) => element()
+ | None => React.null
+ }
+ | NoAccess =>
}
| list{id} =>
let page = switch renderShow {
| Some(fn) => fn(id)
- | None =>
+ | None => React.null
}
page
- | list{id, "edit"} =>
- switch access {
- | ReadWrite => renderEdit(id)
- | _ =>
- }
- | list{id1, id2, "edit"} =>
- switch access {
- | ReadWrite => renderEditWithMultiId(id1, id2)
- | _ =>
- }
- | list{"order", id} =>
- switch renderOrder {
- | Some(fn) => fn(id)
- | None =>
- }
| list{} => renderList()
| _ =>
}
diff --git a/src/components/UnauthorizedPage.res b/src/components/UnauthorizedPage.res
new file mode 100644
index 000000000..55bddadc9
--- /dev/null
+++ b/src/components/UnauthorizedPage.res
@@ -0,0 +1,19 @@
+@react.component
+let make = (~message="You don't have access to this module. Contact admin for access") => {
+ let {setDashboardPageState} = React.useContext(GlobalProvider.defaultContext)
+ React.useEffect0(() => {
+ RescriptReactRouter.replace("/unauthorized")
+ None
+ })
+
+
+}
diff --git a/src/components/form/BoolInput.res b/src/components/form/BoolInput.res
index 64ec789f0..8ada7a9aa 100644
--- a/src/components/form/BoolInput.res
+++ b/src/components/form/BoolInput.res
@@ -114,7 +114,6 @@ let make = (
~boolCustomClass="",
~addAttributeId="",
) => {
- let accessLevel = React.useContext(FormAuthContext.formAuthContext)
let boolInput = baseInput->ffInputToBoolInput
let boolValue: Js.Json.t = boolInput.value
@@ -126,14 +125,8 @@ let make = (
let setIsSelected = boolInput.onChange
isCheckBox
- ?
+ ?
:
}
diff --git a/src/context/FormAuthContext.res b/src/context/FormAuthContext.res
index e59430a3d..6d87a6061 100644
--- a/src/context/FormAuthContext.res
+++ b/src/context/FormAuthContext.res
@@ -1,3 +1,3 @@
-let formAuthContext = React.createContext(AuthTypes.ReadWrite)
+let formAuthContext = React.createContext(AuthTypes.Access)
let make = React.Context.provider(formAuthContext)
diff --git a/src/entryPoints/hyperswitch/HyperSwitchApp.res b/src/entryPoints/hyperswitch/HyperSwitchApp.res
index 210af2a7c..f8d8e2979 100644
--- a/src/entryPoints/hyperswitch/HyperSwitchApp.res
+++ b/src/entryPoints/hyperswitch/HyperSwitchApp.res
@@ -240,7 +240,7 @@ let make = () => {
}
renderShow={id => }
/>
@@ -250,7 +250,7 @@ let make = () => {
}
renderShow={id => }
/>
@@ -259,7 +259,7 @@ let make = () => {
}
renderShow={id => }
/>
@@ -268,7 +268,7 @@ let make = () => {
}
renderShow={id => }
/>
@@ -285,7 +285,7 @@ let make = () => {
}
renderShow={_ => }
/>
@@ -350,7 +350,7 @@ let make = () => {
| list{"quick-start"} => determineQuickStartPageState()
| list{"woocommerce"} => determineWooCommerce()
| list{"stripe-plus-paypal"} => determineStripePlusPayPal()
-
+ | list{"unauthorized"} =>
| _ =>
RescriptReactRouter.replace(`${hyperSwitchFEPrefix}/home`)
diff --git a/src/entryPoints/hyperswitch/SidebarValues.res b/src/entryPoints/hyperswitch/SidebarValues.res
index 3717fc222..648d74cde 100644
--- a/src/entryPoints/hyperswitch/SidebarValues.res
+++ b/src/entryPoints/hyperswitch/SidebarValues.res
@@ -54,35 +54,35 @@ let home = isHomeEnabled =>
name: "Home",
icon: "hswitch-home",
link: "/home",
- access: ReadWrite,
+ access: Access,
})
: emptyComponent
let payments = SubLevelLink({
name: "Payments",
link: `/payments`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View payment operations", "")],
})
let refunds = SubLevelLink({
name: "Refunds",
link: `/refunds`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View refund operations", "")],
})
let disputes = SubLevelLink({
name: "Disputes",
link: `/disputes`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View dispute operations", "")],
})
let customers = SubLevelLink({
name: "Customers",
link: `/customers`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View customers", "")],
})
@@ -105,7 +105,7 @@ let connectors = (isConnectorsEnabled, isLiveMode) => {
name: "Processors",
link: `/connectors`,
icon: "connectors",
- access: ReadWrite,
+ access: Access,
searchOptions: HSwitchUtils.getSearchOptionsForProcessors(
~processorList=isLiveMode
? ConnectorUtils.connectorListForLive
@@ -119,21 +119,21 @@ let connectors = (isConnectorsEnabled, isLiveMode) => {
let paymentAnalytcis = SubLevelLink({
name: "Payments",
link: `/analytics-payments`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View analytics", "")],
})
let refundAnalytics = SubLevelLink({
name: "Refunds",
link: `/analytics-refunds`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View analytics", "")],
})
let userJourneyAnalytics = SubLevelLink({
name: "User Journey",
link: `/analytics-user-journey`,
- access: ReadWrite,
+ access: Access,
iconTag: "betaTag",
searchOptions: [("View analytics", "")],
})
@@ -153,7 +153,7 @@ let analytics = (isAnalyticsEnabled, userJourneyAnalyticsFlag) =>
let routing = SubLevelLink({
name: "Routing",
link: `/routing`,
- access: ReadWrite,
+ access: Access,
searchOptions: [
("Manage default routing configuration", "/default"),
("Create new volume based routing", "/volume"),
@@ -165,14 +165,14 @@ let routing = SubLevelLink({
let threeDs = SubLevelLink({
name: "3DS Decision Manager",
link: `/3ds`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("Configure 3ds", "")],
})
let surcharge = SubLevelLink({
name: "Surcharge",
link: `/surcharge`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("Add Surcharge", "")],
})
@@ -189,14 +189,14 @@ let workflow = (isWorkflowEnabled, isSurchargeEnabled) =>
let userManagement = SubLevelLink({
name: "Team",
link: `/users`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View team management", "")],
})
let accountSettings = SubLevelLink({
name: "Account Settings",
link: `/account-settings`,
- access: ReadWrite,
+ access: Access,
searchOptions: [
("View profile", "/profile"),
("Change password", "/profile"),
@@ -207,14 +207,14 @@ let accountSettings = SubLevelLink({
let businessDetails = SubLevelLink({
name: "Business Details",
link: `/business-details`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("Configure business details", "")],
})
let businessProfiles = SubLevelLink({
name: "Business Profiles",
link: `/business-profiles`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("Configure business profiles", "")],
})
@@ -242,14 +242,14 @@ let settings = (~isSampleDataEnabled, ~isUserManagementEnabled, ~isBusinessProfi
let apiKeys = SubLevelLink({
name: "API Keys",
link: `/developer-api-keys`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View API Keys", "")],
})
let systemMetric = SubLevelLink({
name: "System Metrics",
link: `/developer-system-metrics`,
- access: ReadWrite,
+ access: Access,
iconTag: "betaTag",
searchOptions: [("View System Metrics", "")],
})
@@ -257,7 +257,7 @@ let systemMetric = SubLevelLink({
let paymentSettings = SubLevelLink({
name: "Payment Settings",
link: `/payment-settings`,
- access: ReadWrite,
+ access: Access,
searchOptions: [("View payment settings", ""), ("View webhooks", ""), ("View return url", "")],
})
@@ -282,7 +282,7 @@ let fraudAndRisk = isfraudAndRiskEnabled =>
name: "Fraud & Risk",
icon: "shield-alt",
link: `/fraud-risk-management`,
- access: isfraudAndRiskEnabled ? ReadWrite : NoAccess,
+ access: isfraudAndRiskEnabled ? Access : NoAccess,
searchOptions: [],
})
: emptyComponent
@@ -293,7 +293,7 @@ let payoutConnectors = isPayoutConnectorsEnabled =>
name: "Payout Processors",
link: `/payoutconnectors`,
icon: "connectors",
- access: ReadWrite,
+ access: Access,
searchOptions: HSwitchUtils.getSearchOptionsForProcessors(
~processorList=ConnectorUtils.payoutConnectorList,
~getNameFromString=ConnectorUtils.getConnectorNameString,
@@ -307,7 +307,7 @@ let reconTag = (recon, isReconEnabled) =>
name: "Reconcilation",
icon: isReconEnabled ? "recon" : "recon-lock",
link: `/recon`,
- access: ReadWrite,
+ access: Access,
})
: emptyComponent
diff --git a/src/screens/HyperSwitch/UserManagement/PermissionUtils.res b/src/screens/HyperSwitch/UserManagement/PermissionUtils.res
index d75e19b33..bf529ff77 100644
--- a/src/screens/HyperSwitch/UserManagement/PermissionUtils.res
+++ b/src/screens/HyperSwitch/UserManagement/PermissionUtils.res
@@ -103,5 +103,5 @@ let getAccessValue = (~permissionValue: permissionType, permissionList) => {
ele === permissionValue
})
- isPermissionFound->Option.isSome ? Read : NoAccess
+ isPermissionFound->Option.isSome ? Access : NoAccess
}
diff --git a/src/screens/login/AuthTypes.res b/src/screens/login/AuthTypes.res
index a28e0757d..1bb419c39 100644
--- a/src/screens/login/AuthTypes.res
+++ b/src/screens/login/AuthTypes.res
@@ -1 +1 @@
-type authorization = NoAccess | Read | ReadWrite
+type authorization = NoAccess | Access
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 2/6] 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 =>
}}