From 42365f77390213319ede97f6287dcfff8960170f Mon Sep 17 00:00:00 2001
From: Pritish Budhiraja <1805317@kiit.ac.in>
Date: Tue, 16 Apr 2024 17:12:13 +0530
Subject: [PATCH] fix: comments addressed
---
src/Components/SavedMethods.res | 26 ++++++++++++++------------
src/Hooks/UtilityHooks.res | 13 +++++++++++++
src/Payments/CardPayment.res | 27 ++++++++++++---------------
src/Utilities/PaymentBody.res | 1 +
4 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/src/Components/SavedMethods.res b/src/Components/SavedMethods.res
index 9ca7df087..3f18d0d7c 100644
--- a/src/Components/SavedMethods.res
+++ b/src/Components/SavedMethods.res
@@ -1,5 +1,3 @@
-open CardUtils
-open Utils
@react.component
let make = (
~paymentToken,
@@ -10,6 +8,10 @@ let make = (
~paymentType,
~list: PaymentMethodsRecord.list,
) => {
+ open CardUtils
+ open Utils
+ open UtilityHooks
+
let {themeObj, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let (showFields, setShowFields) = Recoil.useRecoilState(RecoilAtoms.showCardFieldsAtom)
let areRequiredFieldsValid = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsValid)
@@ -21,7 +23,7 @@ let make = (
}
let (isSaveCardsChecked, setIsSaveCardsChecked) = React.useState(_ => false)
let {displaySavedPaymentMethodsCheckbox} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
- let isGuestCustomer = UtilityHooks.useIsGuestCustomer()
+ let isGuestCustomer = useIsGuestCustomer()
let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Card)
let (token, _) = paymentToken
@@ -36,13 +38,12 @@ let make = (
}
}
- let isCustomerAcceptanceRequired = React.useMemo(() => {
- if displaySavedPaymentMethodsCheckbox {
- isSaveCardsChecked || list.payment_type === SETUP_MANDATE
- } else {
- !(isGuestCustomer || list.payment_type === NORMAL)
- }
- }, (isSaveCardsChecked, list.payment_type))
+ let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired(
+ ~displaySavedPaymentMethodsCheckbox,
+ ~isSaveCardsChecked,
+ ~list,
+ ~isGuestCustomer,
+ )
let bottomElement = {
savedMethods
@@ -101,7 +102,7 @@ let make = (
let paymentType = customerMethod.paymentMethodType->Option.getOr(customerMethod.paymentMethod)
- UtilityHooks.useHandlePostMessages(~complete, ~empty, ~paymentType, ~savedMethod=true)
+ useHandlePostMessages(~complete, ~empty, ~paymentType, ~savedMethod=true)
let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
@@ -176,8 +177,9 @@ let make = (
))
useSubmitPaymentData(submitCallback)
- let conditionsForShowingSaveCardCheckbox =
+ let conditionsForShowingSaveCardCheckbox = React.useMemo(() => {
!isGuestCustomer && list.payment_type !== SETUP_MANDATE && displaySavedPaymentMethodsCheckbox
+ }, (isGuestCustomer, list, displaySavedPaymentMethodsCheckbox))
{if savedCardlength === 0 && (loadSavedCards === PaymentType.LoadingSavedCards || !showFields) {
diff --git a/src/Hooks/UtilityHooks.res b/src/Hooks/UtilityHooks.res
index f34078b30..02380e144 100644
--- a/src/Hooks/UtilityHooks.res
+++ b/src/Hooks/UtilityHooks.res
@@ -21,3 +21,16 @@ let useHandlePostMessages = (~complete, ~empty, ~paymentType, ~savedMethod=false
None
}, (complete, empty, paymentType))
}
+
+let useIsCustomerAcceptanceRequired = (
+ ~displaySavedPaymentMethodsCheckbox,
+ ~isSaveCardsChecked,
+ ~list: PaymentMethodsRecord.list,
+ ~isGuestCustomer,
+) => React.useMemo(() => {
+ if displaySavedPaymentMethodsCheckbox {
+ isSaveCardsChecked || list.payment_type === SETUP_MANDATE
+ } else {
+ !(isGuestCustomer || list.payment_type === NORMAL)
+ }
+ }, (isSaveCardsChecked, list.payment_type))
diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res
index 8d3e68520..790ff4e5e 100644
--- a/src/Payments/CardPayment.res
+++ b/src/Payments/CardPayment.res
@@ -1,7 +1,5 @@
type target = {checked: bool}
type event = {target: target}
-open PaymentType
-open PaymentModeType
@react.component
let make = (
@@ -12,7 +10,11 @@ let make = (
~paymentType: CardThemeType.mode,
~list: PaymentMethodsRecord.list,
) => {
+ open PaymentType
+ open PaymentModeType
open Utils
+ open UtilityHooks
+
let {config, themeObj, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let options = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)
@@ -81,13 +83,9 @@ let make = (
None
}, [complete])
- UtilityHooks.useHandlePostMessages(
- ~complete=complete && areRequiredFieldsValid,
- ~empty,
- ~paymentType="card",
- )
+ useHandlePostMessages(~complete=complete && areRequiredFieldsValid, ~empty, ~paymentType="card")
- let isGuestCustomer = UtilityHooks.useIsGuestCustomer()
+ let isGuestCustomer = useIsGuestCustomer()
let isCvcValidValue = CardUtils.getBoolOptionVal(isCVCValid)
let (cardEmpty, cardComplete, cardInvalid) = CardUtils.useCardDetails(
~cvcNumber,
@@ -95,13 +93,12 @@ let make = (
~isCvcValidValue,
)
- let isCustomerAcceptanceRequired = React.useMemo(() => {
- if displaySavedPaymentMethodsCheckbox {
- isSaveCardsChecked || list.payment_type === SETUP_MANDATE
- } else {
- !(isGuestCustomer || list.payment_type === NORMAL)
- }
- }, (isSaveCardsChecked, list.payment_type))
+ let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired(
+ ~displaySavedPaymentMethodsCheckbox,
+ ~isSaveCardsChecked,
+ ~list,
+ ~isGuestCustomer,
+ )
let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res
index cb5faa2e6..9ddae8ef2 100644
--- a/src/Utilities/PaymentBody.res
+++ b/src/Utilities/PaymentBody.res
@@ -98,6 +98,7 @@ let savedPaymentMethodBody = (
savedPaymentMethodBody
}
+
let savedCardBody = (
~paymentToken,
~customerId,