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 790ff4e5e..528aaee35 100644
--- a/src/Payments/CardPayment.res
+++ b/src/Payments/CardPayment.res
@@ -1,5 +1,7 @@
type target = {checked: bool}
type event = {target: target}
+open PaymentType
+open PaymentModeType
@react.component
let make = (
@@ -10,11 +12,7 @@ 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)
@@ -83,9 +81,13 @@ let make = (
None
}, [complete])
- useHandlePostMessages(~complete=complete && areRequiredFieldsValid, ~empty, ~paymentType="card")
+ UtilityHooks.useHandlePostMessages(
+ ~complete=complete && areRequiredFieldsValid,
+ ~empty,
+ ~paymentType="card",
+ )
- let isGuestCustomer = useIsGuestCustomer()
+ let isGuestCustomer = UtilityHooks.useIsGuestCustomer()
let isCvcValidValue = CardUtils.getBoolOptionVal(isCVCValid)
let (cardEmpty, cardComplete, cardInvalid) = CardUtils.useCardDetails(
~cvcNumber,
@@ -93,12 +95,13 @@ let make = (
~isCvcValidValue,
)
- let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired(
- ~displaySavedPaymentMethodsCheckbox,
- ~isSaveCardsChecked,
- ~list,
- ~isGuestCustomer,
- )
+ let isCustomerAcceptanceRequired = React.useMemo(() => {
+ if displaySavedPaymentMethodsCheckbox {
+ isSaveCardsChecked || list.payment_type === SETUP_MANDATE
+ } else {
+ !(isGuestCustomer || list.payment_type === NORMAL)
+ }
+ }, (isSaveCardsChecked, list.payment_type))
let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
@@ -273,9 +276,7 @@ let make = (
/>
diff --git a/src/Payments/PaymentMethodsRecord.res b/src/Payments/PaymentMethodsRecord.res
index 636541c8b..19b8774a2 100644
--- a/src/Payments/PaymentMethodsRecord.res
+++ b/src/Payments/PaymentMethodsRecord.res
@@ -724,7 +724,6 @@ type list = {
payment_methods: array,
mandate_payment: option,
payment_type: payment_type,
- merchant_name: string,
}
open Utils
@@ -746,7 +745,6 @@ let defaultList = {
payment_methods: [],
mandate_payment: None,
payment_type: NONE,
- merchant_name: "",
}
let getMethod = str => {
switch str {
@@ -965,7 +963,6 @@ let itemToObjMapper = dict => {
payment_methods: getMethodsArr(dict, "payment_methods"),
mandate_payment: getMandate(dict, "mandate_payment"),
payment_type: getString(dict, "payment_type", "")->paymentTypeMapper,
- merchant_name: getString(dict, "merchant_name", ""),
}
}
diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res
index 9ddae8ef2..740d8c93f 100644
--- a/src/Utilities/PaymentBody.res
+++ b/src/Utilities/PaymentBody.res
@@ -64,6 +64,20 @@ let boletoBody = (~socialSecurityNumber) => [
),
]
+let savedCardBody = (~paymentToken, ~customerId, ~cvcNumber, ~requiresCvv) => {
+ let savedCardBody = [
+ ("payment_method", "card"->JSON.Encode.string),
+ ("payment_token", paymentToken->JSON.Encode.string),
+ ("customer_id", customerId->JSON.Encode.string),
+ ]
+
+ if requiresCvv {
+ savedCardBody->Array.push(("card_cvc", cvcNumber->JSON.Encode.string))->ignore
+ }
+
+ savedCardBody
+}
+
let customerAcceptanceBody =
[
("acceptance_type", "online"->JSON.Encode.string),
@@ -78,51 +92,12 @@ let customerAcceptanceBody =
->Dict.fromArray
->JSON.Encode.object
-let savedPaymentMethodBody = (
- ~paymentToken,
- ~customerId,
- ~paymentMethod,
- ~paymentMethodType,
- ~isCustomerAcceptanceRequired,
-) => {
- let savedPaymentMethodBody = [
- ("payment_method", paymentMethod->JSON.Encode.string),
- ("payment_token", paymentToken->JSON.Encode.string),
- ("customer_id", customerId->JSON.Encode.string),
- ("payment_method_type", paymentMethodType),
- ]
-
- if isCustomerAcceptanceRequired {
- savedPaymentMethodBody->Array.push(("customer_acceptance", customerAcceptanceBody))->ignore
- }
-
- savedPaymentMethodBody
-}
-
-let savedCardBody = (
- ~paymentToken,
- ~customerId,
- ~cvcNumber,
- ~requiresCvv,
- ~isCustomerAcceptanceRequired,
-) => {
- let savedCardBody = [
- ("payment_method", "card"->JSON.Encode.string),
- ("payment_token", paymentToken->JSON.Encode.string),
- ("customer_id", customerId->JSON.Encode.string),
- ("customer_acceptance", customerAcceptanceBody),
- ]
-
- if requiresCvv {
- savedCardBody->Array.push(("card_cvc", cvcNumber->JSON.Encode.string))->ignore
- }
-
- if isCustomerAcceptanceRequired {
- savedCardBody->Array.push(("customer_acceptance", customerAcceptanceBody))->ignore
- }
-
- savedCardBody
-}
+let savedPaymentMethodBody = (~paymentToken, ~customerId, ~paymentMethod, ~paymentMethodType) => [
+ ("payment_method", paymentMethod->JSON.Encode.string),
+ ("payment_token", paymentToken->JSON.Encode.string),
+ ("customer_id", customerId->JSON.Encode.string),
+ ("payment_method_type", paymentMethodType),
+]
let mandateBody = paymentType => {
[
diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res
index 1a8a955b8..36dc9ae10 100644
--- a/src/orca-loader/Hyper.res
+++ b/src/orca-loader/Hyper.res
@@ -318,7 +318,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionJSON.Decode.bool->Option.getOr(false) && redirect === "always" {
Window.replace(returnUrl)
} else if !(val->JSON.Decode.bool->Option.getOr(false)) {
From 6643d6955f4fc7fb94c1a6a1c890821cad44f85d Mon Sep 17 00:00:00 2001
From: Pritish Budhiraja <1805317@kiit.ac.in>
Date: Wed, 17 Apr 2024 12:23:03 +0530
Subject: [PATCH 2/2] fix: mandate changes
---
src/Payments/CardPayment.res | 14 +++++++++-----
src/Payments/PaymentMethodsRecord.res | 3 +++
src/orca-loader/Hyper.res | 2 +-
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res
index 528aaee35..5757038dd 100644
--- a/src/Payments/CardPayment.res
+++ b/src/Payments/CardPayment.res
@@ -190,6 +190,8 @@ let make = (
let nicknameFieldClassName = conditionsForShowingSaveCardCheckbox ? "pt-2" : "pt-5"
+ Js.log2("sdvjnsddsjd", (list.mandate_payment, options.terms.card))
+
- {switch (list.mandate_payment, options.terms.card) {
- | (Some(_), Auto)
- | (_, Always) =>
+ {switch (list.mandate_payment, options.terms.card, list.payment_type) {
+ | (Some(_), Auto, _)
+ | (_, Always, _)
+ | (_, _, NEW_MANDATE)
+ | (_, _, SETUP_MANDATE) =>
addSize(10.0, Pixel),
+ ~marginTop=themeObj.spacingGridColumn,
(),
)}>
- | (_, _) => React.null
+ | (_, _, _) => React.null
}}
diff --git a/src/Payments/PaymentMethodsRecord.res b/src/Payments/PaymentMethodsRecord.res
index 19b8774a2..636541c8b 100644
--- a/src/Payments/PaymentMethodsRecord.res
+++ b/src/Payments/PaymentMethodsRecord.res
@@ -724,6 +724,7 @@ type list = {
payment_methods: array,
mandate_payment: option,
payment_type: payment_type,
+ merchant_name: string,
}
open Utils
@@ -745,6 +746,7 @@ let defaultList = {
payment_methods: [],
mandate_payment: None,
payment_type: NONE,
+ merchant_name: "",
}
let getMethod = str => {
switch str {
@@ -963,6 +965,7 @@ let itemToObjMapper = dict => {
payment_methods: getMethodsArr(dict, "payment_methods"),
mandate_payment: getMandate(dict, "mandate_payment"),
payment_type: getString(dict, "payment_type", "")->paymentTypeMapper,
+ merchant_name: getString(dict, "merchant_name", ""),
}
}
diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res
index 36dc9ae10..1a8a955b8 100644
--- a/src/orca-loader/Hyper.res
+++ b/src/orca-loader/Hyper.res
@@ -318,7 +318,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionJSON.Decode.bool->Option.getOr(false) && redirect === "always" {
Window.replace(returnUrl)
} else if !(val->JSON.Decode.bool->Option.getOr(false)) {