React.useMemo(() => {
+ if displaySavedPaymentMethodsCheckbox {
+ isSaveCardsChecked || list.payment_type === SETUP_MANDATE
+ } else {
+ !(isGuestCustomer || list.payment_type === NORMAL)
+ }
+ }, (isSaveCardsChecked, list.payment_type, isGuestCustomer, displaySavedPaymentMethodsCheckbox))
diff --git a/src/LoaderController.res b/src/LoaderController.res
index 60e1430a5..e0b5a9aba 100644
--- a/src/LoaderController.res
+++ b/src/LoaderController.res
@@ -362,6 +362,15 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}
if dict->getDictIsSome("paymentMethodList") {
let list = dict->getJsonObjectFromDict("paymentMethodList")
+ let listDict = list->getDictFromJson
+ if optionsPayment.business.name === "" {
+ setOptionsPayment(prev => {
+ ...prev,
+ business: {
+ name: listDict->getString("merchant_name", ""),
+ },
+ })
+ }
let finalLoadLatency = if launchTime <= 0.0 {
-1.0
} else {
@@ -370,11 +379,11 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
let updatedState: PaymentType.loadType =
list == Dict.make()->JSON.Encode.object
? LoadError(list)
- : switch list->getDictFromJson->Dict.get("error") {
+ : switch listDict->Dict.get("error") {
| Some(_) => LoadError(list)
| None =>
let isNonEmptyPaymentMethodList =
- list->getDictFromJson->getArray("payment_methods")->Array.length > 0
+ listDict->getArray("payment_methods")->Array.length > 0
isNonEmptyPaymentMethodList ? Loaded(list) : LoadError(list)
}
@@ -474,7 +483,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}
}
handleMessage(handleFun, "Error in parsing sent Data")
- }, (showCardFormByDefault, paymentMethodOrder))
+ }, (showCardFormByDefault, paymentMethodOrder, optionsPayment))
let observer = ResizeObserver.newResizerObserver(entries => {
entries
diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res
index acccb7ea4..14aee6d5b 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
@@ -277,7 +274,9 @@ let make = (
/>
diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res
index 740d8c93f..e98bdacf3 100644
--- a/src/Utilities/PaymentBody.res
+++ b/src/Utilities/PaymentBody.res
@@ -64,7 +64,27 @@ let boletoBody = (~socialSecurityNumber) => [
),
]
-let savedCardBody = (~paymentToken, ~customerId, ~cvcNumber, ~requiresCvv) => {
+let customerAcceptanceBody =
+ [
+ ("acceptance_type", "online"->JSON.Encode.string),
+ ("accepted_at", Date.now()->Js.Date.fromFloat->Date.toISOString->JSON.Encode.string),
+ (
+ "online",
+ [("user_agent", BrowserSpec.navigator.userAgent->JSON.Encode.string)]
+ ->Dict.fromArray
+ ->JSON.Encode.object,
+ ),
+ ]
+ ->Dict.fromArray
+ ->JSON.Encode.object
+
+let savedCardBody = (
+ ~paymentToken,
+ ~customerId,
+ ~cvcNumber,
+ ~requiresCvv,
+ ~isCustomerAcceptanceRequired,
+) => {
let savedCardBody = [
("payment_method", "card"->JSON.Encode.string),
("payment_token", paymentToken->JSON.Encode.string),
@@ -75,29 +95,33 @@ let savedCardBody = (~paymentToken, ~customerId, ~cvcNumber, ~requiresCvv) => {
savedCardBody->Array.push(("card_cvc", cvcNumber->JSON.Encode.string))->ignore
}
+ if isCustomerAcceptanceRequired {
+ savedCardBody->Array.push(("customer_acceptance", customerAcceptanceBody))->ignore
+ }
+
savedCardBody
}
-let customerAcceptanceBody =
- [
- ("acceptance_type", "online"->JSON.Encode.string),
- ("accepted_at", Date.now()->Js.Date.fromFloat->Date.toISOString->JSON.Encode.string),
- (
- "online",
- [("user_agent", BrowserSpec.navigator.userAgent->JSON.Encode.string)]
- ->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),
]
- ->Dict.fromArray
- ->JSON.Encode.object
-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),
-]
+ if isCustomerAcceptanceRequired {
+ savedPaymentMethodBody->Array.push(("customer_acceptance", customerAcceptanceBody))->ignore
+ }
+
+ savedPaymentMethodBody
+}
let mandateBody = paymentType => {
[