Skip to content

Commit

Permalink
fix: customer acceptance issue for bank debits (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored Jul 24, 2024
1 parent ec65f15 commit e797149
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 102 deletions.
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

0 comments on commit e797149

Please sign in to comment.