Skip to content

Commit

Permalink
fix: sepa debit required fields body
Browse files Browse the repository at this point in the history
  • Loading branch information
Saksham Sharma authored and Saksham Sharma committed Sep 30, 2024
1 parent 8a85f88 commit ee6c3c0
Show file tree
Hide file tree
Showing 9 changed files with 994 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/Components/AddBankAccount.res
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ToolTip = {
let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom)
<RenderIf condition={openTip}>
<button
className="h-auto max-w-20 w-auto cursor-pointer absolute m-1 px-1 py-2 top-[-3rem] right-[1em]"
className="h-auto max-w-30 w-auto cursor-pointer absolute m-1 px-1 py-2 top-[-3rem] right-[1em]"
style={
background: themeObj.colorBackground,
color: themeObj.colorDanger,
Expand Down
7 changes: 5 additions & 2 deletions src/Components/PayNowButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Loader = {
}
}
@react.component
let make = (~onClickHandler=?) => {
let make = (~onClickHandler=?, ~label=?) => {
open RecoilAtoms
open Utils
let (showLoader, setShowLoader) = React.useState(() => false)
Expand All @@ -19,7 +19,10 @@ let make = (~onClickHandler=?) => {
let {sdkHandleConfirmPayment} = optionAtom->Recoil.useRecoilValueFromAtom

let confirmPayload = sdkHandleConfirmPayment->PaymentBody.confirmPayloadForSDKButton
let buttonText = sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)
let buttonText = switch label {
| Some(val) => val
| _ => sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)
}

let handleMessage = (event: Types.event) => {
let json = event.data->Identity.anyTypeToJson->getStringFromJson("")->safeParse
Expand Down
3 changes: 2 additions & 1 deletion src/Payments/BankDebitModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ let make = (~setModalData, ~paymentType: CardThemeType.mode) => {
accountType: accountType->String.toLowerCase,
iban,
sortCode,
requiredFieldsBody,
}))
Modal.close(setOpenModal)
}
Expand All @@ -209,7 +210,7 @@ let make = (~setModalData, ~paymentType: CardThemeType.mode) => {
<DynamicFields
paymentType paymentMethod="bank_debit" paymentMethodType="sepa" setRequiredFieldsBody
/>
<PayNowButton onClickHandler />
<PayNowButton onClickHandler label="Done" />
</>
} else {
<>
Expand Down
2 changes: 0 additions & 2 deletions src/Payments/PaymentMethodsWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => {
let areRequiredFieldsValid = Recoil.useRecoilValueFromAtom(areRequiredFieldsValid)
let areRequiredFieldsEmpty = Recoil.useRecoilValueFromAtom(areRequiredFieldsEmpty)

Js.log2("requiredFieldsBodyrequiredFieldsBodyrequiredFieldsBody", requiredFieldsBody)

let complete = areRequiredFieldsValid

React.useEffect(() => {
Expand Down
65 changes: 49 additions & 16 deletions src/Payments/SepaBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ let make = (~paymentType: CardThemeType.mode) => {

let (modalData, setModalData) = React.useState(_ => None)

Js.log2("modalDatamodalData", modalData)

let (fullName, _) = Recoil.useLoggedRecoilState(userFullName, "fullName", loggerState)
let (email, _) = Recoil.useLoggedRecoilState(userEmailAddress, "email", loggerState)
let (line1, _) = Recoil.useLoggedRecoilState(userAddressline1, "line1", loggerState)
Expand All @@ -30,8 +28,6 @@ let make = (~paymentType: CardThemeType.mode) => {

let requiredFields = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsValid)

Js.log2("requiredFields", requiredFields)

let pmAuthMapper = React.useMemo1(
() =>
PmAuthConnectorUtils.findPmAuthAllPMAuthConnectors(paymentMethodListValue.payment_methods),
Expand Down Expand Up @@ -71,19 +67,56 @@ let make = (~paymentType: CardThemeType.mode) => {
if confirm.doSubmit {
if true {
switch modalData {
| Some(data: ACHTypes.data) => // let body = PaymentBody.sepaBankDebitBody(
// ~fullName=fullName.value,
// ~email=email.value,
// ~data,
// ~line1=line1.value,
// ~line2=line2.value,
// ~country=getCountryCode(country.value).isoAlpha2,
// ~city=city.value,
// ~postalCode=postalCode.value,
// ~state=state.value,
// )
| Some(data: ACHTypes.data) =>
let bodyFields = data.requiredFieldsBody->Option.getOr(Dict.make())
let sepaBody =
PaymentBody.bankDebitsCommonBody("sepa")->Array.concat([
(
"payment_method_data",
[
(
"billing",
[
(
"address",
[
(
"first_name",
bodyFields->getJsonObjectFromDict(
"payment_method_data.billing.address.first_name",
),
),
(
"last_name",
bodyFields->getJsonObjectFromDict(
"payment_method_data.billing.address.last_name",
),
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
(
"bank_debit",
[
(
"sepa_bank_debit",
[
(
"iban",
bodyFields->getJsonObjectFromDict(
"payment_method_data.bank_debit.sepa.iban",
),
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
])
intent(
~bodyArr=[],
~bodyArr=sepaBody,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
~manualRetry=isManualRetryEnabled,
Expand Down
1 change: 1 addition & 0 deletions src/Types/ACHTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ type data = {
accountType: string,
iban: string,
sortCode: string,
requiredFieldsBody?: Dict.t<JSON.t>,
}
1 change: 0 additions & 1 deletion src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ let useRequiredFieldsBody = (
})
->addBillingDetailsIfUseBillingAddress

Js.log2("requiredFieldsBody", requiredFieldsBody)
setRequiredFieldsBody(_ => requiredFieldsBody)
None
}, (
Expand Down
41 changes: 0 additions & 41 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -224,47 +224,6 @@ let achBankDebitBody = (
),
])

let sepaBankDebitBody = (
~fullName,
~email,
~data: ACHTypes.data,
~line1,
~line2,
~country,
~city,
~postalCode,
~state,
) =>
bankDebitsCommonBody("sepa")->Array.concat([
(
"payment_method_data",
[
billingDetailsTuple(
~fullName,
~email,
~line1,
~line2,
~city,
~state,
~postalCode,
~country,
),
(
"bank_debit",
[
(
"sepa_bank_debit",
[
("iban", data.iban->JSON.Encode.string),
("bank_account_holder_name", data.accountHolderName->JSON.Encode.string),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
]->Utils.getJsonFromArrayOfJson,
),
])

let bacsBankDebitBody = (
~email,
~accNum,
Expand Down
Loading

0 comments on commit ee6c3c0

Please sign in to comment.