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

fix: customer acceptance issue for bank debits #516

Merged
merged 1 commit into from
Jul 24, 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
1 change: 0 additions & 1 deletion src/Payments/ACHBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ let make = (~paymentType: CardThemeType.mode) => {
~city=city.value,
~postalCode=postalCode.value,
~state=state.value,
~paymentType=paymentMethodListValue.payment_type,
)
intent(
~bodyArr=body,
Expand Down
204 changes: 103 additions & 101 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ let confirmPayloadForSDKButton = (sdkHandleConfirmPayment: PaymentType.sdkHandle
),
]->Utils.getJsonFromArrayOfJson

let bankDebitsCommonBody = paymentMethodType => {
[
("payment_method", "bank_debit"->JSON.Encode.string),
("setup_future_usage", "off_session"->JSON.Encode.string),
("payment_method_type", paymentMethodType->JSON.Encode.string),
("customer_acceptance", customerAcceptanceBody),
]
}

let achBankDebitBody = (
~email,
~bank: ACHTypes.data,
Expand All @@ -178,12 +187,8 @@ let achBankDebitBody = (
~city,
~postalCode,
~state,
~paymentType,
) =>
[
("payment_method", "bank_debit"->JSON.Encode.string),
("setup_future_usage", "off_session"->JSON.Encode.string),
("payment_method_type", "ach"->JSON.Encode.string),
bankDebitsCommonBody("ach")->Array.concat([
(
"payment_method_data",
[
Expand Down Expand Up @@ -213,7 +218,7 @@ let achBankDebitBody = (
),
]->Utils.getJsonFromArrayOfJson,
),
]->Array.concat(mandateBody(paymentType->PaymentMethodsRecord.paymentTypeToStringMapper))
])

let sepaBankDebitBody = (
~fullName,
Expand All @@ -225,37 +230,36 @@ let sepaBankDebitBody = (
~city,
~postalCode,
~state,
) => [
("payment_method", "bank_debit"->JSON.Encode.string),
("payment_method_type", "sepa"->JSON.Encode.string),
(
"payment_method_data",
[
(
"bank_debit",
[
(
"sepa_bank_debit",
[
billingDetailsTuple(
~fullName,
~email,
~line1,
~line2,
~city,
~state,
~postalCode,
~country,
),
("iban", data.iban->JSON.Encode.string),
("bank_account_holder_name", data.accountHolderName->JSON.Encode.string),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]
) =>
bankDebitsCommonBody("sepa")->Array.concat([
(
"payment_method_data",
[
(
"bank_debit",
[
(
"sepa_bank_debit",
[
billingDetailsTuple(
~fullName,
~email,
~line1,
~line2,
~city,
~state,
~postalCode,
~country,
),
("iban", data.iban->JSON.Encode.string),
("bank_account_holder_name", data.accountHolderName->JSON.Encode.string),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
])

let bacsBankDebitBody = (
~email,
Expand All @@ -268,38 +272,37 @@ let bacsBankDebitBody = (
~state,
~country,
~bankAccountHolderName,
) => [
("payment_method", "bank_debit"->JSON.Encode.string),
("payment_method_type", "bacs"->JSON.Encode.string),
(
"payment_method_data",
[
(
"bank_debit",
[
(
"bacs_bank_debit",
[
billingDetailsTuple(
~fullName=bankAccountHolderName,
~email,
~line1,
~line2,
~city,
~state,
~postalCode=zip,
~country,
),
("bank_account_holder_name", bankAccountHolderName->JSON.Encode.string),
("sort_code", sortCode->JSON.Encode.string),
("account_number", accNum->JSON.Encode.string),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]
) =>
bankDebitsCommonBody("bacs")->Array.concat([
(
"payment_method_data",
[
(
"bank_debit",
[
(
"bacs_bank_debit",
[
billingDetailsTuple(
~fullName=bankAccountHolderName,
~email,
~line1,
~line2,
~city,
~state,
~postalCode=zip,
~country,
),
("bank_account_holder_name", bankAccountHolderName->JSON.Encode.string),
("sort_code", sortCode->JSON.Encode.string),
("account_number", accNum->JSON.Encode.string),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
])

let becsBankDebitBody = (
~fullName,
Expand All @@ -311,38 +314,37 @@ let becsBankDebitBody = (
~city,
~postalCode,
~state,
) => [
("payment_method", "bank_debit"->JSON.Encode.string),
("payment_method_type", "becs"->JSON.Encode.string),
(
"payment_method_data",
[
(
"bank_debit",
[
(
"becs_bank_debit",
[
billingDetailsTuple(
~fullName,
~email,
~line1,
~line2,
~city,
~state,
~postalCode,
~country,
),
("bsb_number", data.sortCode->JSON.Encode.string),
("account_number", data.accountNumber->JSON.Encode.string),
("bank_account_holder_name", data.accountHolderName->JSON.Encode.string),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]
) =>
bankDebitsCommonBody("becs")->Array.concat([
(
"payment_method_data",
[
(
"bank_debit",
[
(
"becs_bank_debit",
[
billingDetailsTuple(
~fullName,
~email,
~line1,
~line2,
~city,
~state,
~postalCode,
~country,
),
("bsb_number", data.sortCode->JSON.Encode.string),
("account_number", data.accountNumber->JSON.Encode.string),
("bank_account_holder_name", data.accountHolderName->JSON.Encode.string),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
])

let klarnaRedirectionBody = (~fullName, ~email, ~country, ~connectors) => [
("payment_method", "pay_later"->JSON.Encode.string),
Expand Down
Loading