From 1c532e286f3d1d3529769331f428c041e98d13ba Mon Sep 17 00:00:00 2001 From: Saksham Sharma Date: Thu, 7 Nov 2024 18:24:04 +0530 Subject: [PATCH] chore: added dynamic fields support for bacs bank transfer --- src/Payments/BacsBankTransfer.res | 19 +++++++++-------- src/Utilities/DynamicFieldsUtils.res | 1 + src/Utilities/PaymentBody.res | 31 +--------------------------- src/Utilities/Utils.res | 9 ++------ 4 files changed, 14 insertions(+), 46 deletions(-) diff --git a/src/Payments/BacsBankTransfer.res b/src/Payments/BacsBankTransfer.res index 69ebea1bb..90c3d7bfa 100644 --- a/src/Payments/BacsBankTransfer.res +++ b/src/Payments/BacsBankTransfer.res @@ -11,7 +11,8 @@ let default = (~paymentType: CardThemeType.mode) => { let (email, _) = Recoil.useLoggedRecoilState(userEmailAddress, "email", loggerState) let (fullName, _) = Recoil.useLoggedRecoilState(userFullName, "fullName", loggerState) let setComplete = Recoil.useSetRecoilState(fieldsComplete) - let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue) + + let (requiredFieldsBody, setRequiredFieldsBody) = React.useState(_ => Dict.make()) let complete = email.value != "" && fullName.value != "" && email.isValid->Option.getOr(false) let empty = email.value == "" || fullName.value == "" @@ -28,13 +29,12 @@ let default = (~paymentType: CardThemeType.mode) => { let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if complete { - let (connectors, _) = paymentMethodListValue->PaymentUtils.getConnectors(BankTransfer(Bacs)) + let bodyArr = + PaymentBody.dynamicPaymentBody("bank_transfer", "bacs")->mergeAndFlattenToTuples( + requiredFieldsBody, + ) intent( - ~bodyArr=PaymentBody.bacsBankTransferBody( - ~email=email.value, - ~name=fullName.value, - ~connectors, - ), + ~bodyArr, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ~iframeId, @@ -48,8 +48,9 @@ let default = (~paymentType: CardThemeType.mode) => { useSubmitPaymentData(submitCallback)
- - +
diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index 4861d6f45..20fac87b8 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -21,6 +21,7 @@ let dynamicFieldsEnabledPaymentMethods = [ "sepa", "affirm", "ach", + "bacs", ] let getName = (item: PaymentMethodsRecord.required_fields, field: RecoilAtomTypes.field) => { diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res index eaa5c76bb..2d3d30a48 100644 --- a/src/Utilities/PaymentBody.res +++ b/src/Utilities/PaymentBody.res @@ -654,35 +654,6 @@ let epsBody = (~name, ~bankName) => [ ), ] -let bacsBankTransferBody = (~email, ~name, ~connectors) => { - let (firstName, lastName) = name->Utils.getFirstAndLastNameFromFullName - - [ - ("payment_method", "bank_transfer"->JSON.Encode.string), - ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), - ("payment_method_type", "bacs"->JSON.Encode.string), - ( - "payment_method_data", - [ - ( - "billing", - [ - ("email", email->JSON.Encode.string), - ( - "address", - [("first_name", firstName), ("last_name", lastName)]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), - ( - "bank_transfer", - [("bacs_bank_transfer", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), - ] -} - let blikBody = (~blikCode) => [ ("payment_method", "bank_redirect"->JSON.Encode.string), ("payment_method_type", "blik"->JSON.Encode.string), @@ -930,7 +901,7 @@ let appendRedirectPaymentMethods = [ ] let appendBankeDebitMethods = ["sepa"] -let appendBankTransferMethods = ["sepa", "ach"] +let appendBankTransferMethods = ["sepa", "ach", "bacs"] let getPaymentMethodSuffix = (~paymentMethodType, ~paymentMethod, ~isQrPaymentMethod) => { if isQrPaymentMethod { diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index 45c43cc0d..68dd28128 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1020,13 +1020,8 @@ let unflattenObject = obj => { newDict } -let mergeTwoFlattenedJsonDicts = (dict1, dict2) => { - dict1 - ->Dict.toArray - ->Array.concat(dict2->Dict.toArray) - ->getJsonFromArrayOfJson - ->unflattenObject -} +let mergeTwoFlattenedJsonDicts = (dict1, dict2) => + [...dict1->Dict.toArray, ...dict2->Dict.toArray]->getJsonFromArrayOfJson->unflattenObject open Identity