Skip to content

Commit

Permalink
chore: added dynamic fields for ach (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakksham7 authored Nov 7, 2024
1 parent d24954a commit bb98ae6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
16 changes: 12 additions & 4 deletions src/Payments/ACHBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""
Expand All @@ -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,
Expand All @@ -43,7 +49,9 @@ let make = (~paymentType: CardThemeType.mode) => {
useSubmitPaymentData(submitCallback)

<div className="flex flex-col animate-slowShow" style={gridGap: themeObj.spacingTab}>
<EmailPaymentInput paymentType />
<DynamicFields
paymentType paymentMethod="bank_transfer" paymentMethodType="ach" setRequiredFieldsBody
/>
<Surcharge paymentMethod="bank_transfer" paymentMethodType="ach" />
<InfoElement />
</div>
Expand Down
1 change: 1 addition & 0 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ let dynamicFieldsEnabledPaymentMethods = [
"upi_collect",
"sepa",
"affirm",
"ach",
]

let getIsBillingField = requiredFieldType => {
Expand Down
17 changes: 1 addition & 16 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -945,7 +930,7 @@ let appendRedirectPaymentMethods = [
]

let appendBankeDebitMethods = ["sepa"]
let appendBankTransferMethods = ["sepa"]
let appendBankTransferMethods = ["sepa", "ach"]

let getPaymentMethodSuffix = (~paymentMethodType, ~paymentMethod, ~isQrPaymentMethod) => {
if isQrPaymentMethod {
Expand Down

0 comments on commit bb98ae6

Please sign in to comment.