From bb98ae66e17baad2638c6b261b293df982de66eb Mon Sep 17 00:00:00 2001 From: sakksham7 <130480324+sakksham7@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:05:46 +0530 Subject: [PATCH] chore: added dynamic fields for ach (#777) --- src/Payments/ACHBankTransfer.res | 16 ++++++++++++---- src/Payments/PaymentMethodsRecord.res | 1 + src/Utilities/PaymentBody.res | 17 +---------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Payments/ACHBankTransfer.res b/src/Payments/ACHBankTransfer.res index c4665addb..98a91da37 100644 --- a/src/Payments/ACHBankTransfer.res +++ b/src/Payments/ACHBankTransfer.res @@ -10,7 +10,8 @@ let make = (~paymentType: CardThemeType.mode) => { let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), BankTransfer) let (email, _) = Recoil.useLoggedRecoilState(userEmailAddress, "email", loggerState) let setComplete = Recoil.useSetRecoilState(fieldsComplete) - let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue) + + let (requiredFieldsBody, setRequiredFieldsBody) = React.useState(_ => Dict.make()) let complete = email.value != "" && email.isValid->Option.getOr(false) let empty = email.value == "" @@ -27,9 +28,14 @@ let make = (~paymentType: CardThemeType.mode) => { let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if complete { - let (connectors, _) = paymentMethodListValue->PaymentUtils.getConnectors(BankTransfer(ACH)) + let bodyArr = + PaymentBody.dynamicPaymentBody("bank_transfer", "ach") + ->getJsonFromArrayOfJson + ->flattenObject(true) + ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) + ->getArrayOfTupleFromDict intent( - ~bodyArr=PaymentBody.achBankTransferBody(~email=email.value, ~connectors), + ~bodyArr, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ~iframeId, @@ -43,7 +49,9 @@ let make = (~paymentType: CardThemeType.mode) => { useSubmitPaymentData(submitCallback)
- +
diff --git a/src/Payments/PaymentMethodsRecord.res b/src/Payments/PaymentMethodsRecord.res index 68dea2a52..939697eaf 100644 --- a/src/Payments/PaymentMethodsRecord.res +++ b/src/Payments/PaymentMethodsRecord.res @@ -681,6 +681,7 @@ let dynamicFieldsEnabledPaymentMethods = [ "upi_collect", "sepa", "affirm", + "ach", ] let getIsBillingField = requiredFieldType => { diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res index c7c8d2356..eaa5c76bb 100644 --- a/src/Utilities/PaymentBody.res +++ b/src/Utilities/PaymentBody.res @@ -654,21 +654,6 @@ let epsBody = (~name, ~bankName) => [ ), ] -let achBankTransferBody = (~email, ~connectors) => [ - ("payment_method", "bank_transfer"->JSON.Encode.string), - ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), - ("payment_method_type", "ach"->JSON.Encode.string), - ( - "payment_method_data", - [ - ("billing", [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), - ( - "bank_transfer", - [("ach_bank_transfer", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), -] let bacsBankTransferBody = (~email, ~name, ~connectors) => { let (firstName, lastName) = name->Utils.getFirstAndLastNameFromFullName @@ -945,7 +930,7 @@ let appendRedirectPaymentMethods = [ ] let appendBankeDebitMethods = ["sepa"] -let appendBankTransferMethods = ["sepa"] +let appendBankTransferMethods = ["sepa", "ach"] let getPaymentMethodSuffix = (~paymentMethodType, ~paymentMethod, ~isQrPaymentMethod) => { if isQrPaymentMethod {