Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added dynamic fields support for bacs bank transfer #780

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/Payments/BacsBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""
Expand All @@ -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,
Expand All @@ -48,8 +48,9 @@ let default = (~paymentType: CardThemeType.mode) => {
useSubmitPaymentData(submitCallback)

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

let getName = (item: PaymentMethodsRecord.required_fields, field: RecoilAtomTypes.field) => {
Expand Down
31 changes: 1 addition & 30 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading