Skip to content

Commit

Permalink
fix: some more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja committed Sep 20, 2024
1 parent 8e750ae commit 8a85f88
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 30 deletions.
12 changes: 9 additions & 3 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 = () => {
let make = (~onClickHandler=?) => {
open RecoilAtoms
open Utils
let (showLoader, setShowLoader) = React.useState(() => false)
Expand All @@ -21,7 +21,6 @@ let make = () => {
let confirmPayload = sdkHandleConfirmPayment->PaymentBody.confirmPayloadForSDKButton
let buttonText = sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)


let handleMessage = (event: Types.event) => {
let json = event.data->Identity.anyTypeToJson->getStringFromJson("")->safeParse
let dict = json->getDictFromJson
Expand All @@ -35,6 +34,13 @@ let make = () => {
}
}

let onClickHandlerFunc = _ => {
switch onClickHandler {
| Some(fn) => fn()
| None => ()
}
}

let handleOnClick = _ => {
setIsPayNowButtonDisable(_ => true)
setShowLoader(_ => true)
Expand All @@ -45,7 +51,7 @@ let make = () => {
<div className="flex flex-col gap-1 h-auto w-full items-center">
<button
disabled=isPayNowButtonDisable
onClick=handleOnClick
onClick={onClickHandler->Option.isNone ? handleOnClick : onClickHandlerFunc}
className={`w-full flex flex-row justify-center items-center`}
style={
borderRadius: themeObj.buttonBorderRadius,
Expand Down
14 changes: 13 additions & 1 deletion src/Payments/BankDebitModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ let make = (~setModalData, ~paymentType: CardThemeType.mode) => {
iban !== "" ||
(accountNum->String.length > 0 && sortCode->String.length > 0)

let onClickHandler = () => {
setModalData(_ => Some({
routingNumber,
accountNumber: accountNum,
accountHolderName,
accountType: accountType->String.toLowerCase,
iban,
sortCode,
}))
Modal.close(setOpenModal)
}

<Modal loader=false testMode=true openModal setOpenModal>
<div className="flex flex-col w-full h-auto overflow-scroll">
<div className={`flex flex-col`}>
Expand All @@ -197,7 +209,7 @@ let make = (~setModalData, ~paymentType: CardThemeType.mode) => {
<DynamicFields
paymentType paymentMethod="bank_debit" paymentMethodType="sepa" setRequiredFieldsBody
/>
<PayNowButton />
<PayNowButton onClickHandler />
</>
} else {
<>
Expand Down
14 changes: 10 additions & 4 deletions src/Payments/PaymentMethodsWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ 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 All @@ -59,7 +61,7 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => {
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if complete {
if true {
let countryCode =
Country.getCountry(paymentMethodName)
->Array.filter(item => item.countryName == country)
Expand All @@ -71,8 +73,8 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => {
->Array.filter(item => item.displayName == selectedBank)
->Array.get(0)
->Option.getOr(Bank.defaultBank)
intent(
~bodyArr=PaymentBody.getPaymentBody(
let body =
PaymentBody.getPaymentBody(
~paymentMethod=paymentMethodDetails.methodType,
~paymentMethodType=paymentMethodName,
~country=countryCode.isoAlpha2,
Expand All @@ -89,7 +91,11 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => {
->JSON.Encode.object
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict,
->getArrayOfTupleFromDict

Js.log3("dcsidcksdncsdjcusd", body, requiredFieldsBody)
intent(
~bodyArr=body,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
~iframeId,
Expand Down
47 changes: 25 additions & 22 deletions src/Payments/SepaBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ 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 @@ -26,6 +28,10 @@ let make = (~paymentType: CardThemeType.mode) => {
let setComplete = Recoil.useSetRecoilState(fieldsComplete)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)

let requiredFields = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsValid)

Js.log2("requiredFields", requiredFields)

let pmAuthMapper = React.useMemo1(
() =>
PmAuthConnectorUtils.findPmAuthAllPMAuthConnectors(paymentMethodListValue.payment_methods),
Expand Down Expand Up @@ -54,7 +60,7 @@ let make = (~paymentType: CardThemeType.mode) => {
UtilityHooks.useHandlePostMessages(~complete, ~empty, ~paymentType="sepa_bank_debit")

React.useEffect(() => {
setComplete(_ => complete)
setComplete(_ => true)
None
}, [complete])

Expand All @@ -63,30 +69,27 @@ let make = (~paymentType: CardThemeType.mode) => {
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper

if confirm.doSubmit {
if complete {
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,
)
intent(
~bodyArr=body,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
~manualRetry=isManualRetryEnabled,
)
}
| 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,
// )
intent(
~bodyArr=[],
~confirmParam=confirm.confirmParams,
~handleUserError=false,
~manualRetry=isManualRetryEnabled,
)
| None => ()
}
()
} else {
postFailedSubmitResponse(~errortype="validation_error", ~message="Please enter all fields")
}
Expand Down
1 change: 1 addition & 0 deletions src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ let useRequiredFieldsBody = (
})
->addBillingDetailsIfUseBillingAddress

Js.log2("requiredFieldsBody", requiredFieldsBody)
setRequiredFieldsBody(_ => requiredFieldsBody)
None
}, (
Expand Down

0 comments on commit 8a85f88

Please sign in to comment.