Skip to content

Commit

Permalink
fix: validations added
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja committed Jul 1, 2024
1 parent 00b47dc commit fbf2ee3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 73 deletions.
12 changes: 2 additions & 10 deletions src/Payments/PlaidSDKIframe.res
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ let make = () => {
let handler = Plaid.create({
token: linkToken,
onSuccess: (publicToken, _) => {
Js.log2("Plaid link token onSuccess", publicToken)
handlePostMessage([
("fullscreen", false->JSON.Encode.bool),
("isPlaid", true->JSON.Encode.bool),
Expand All @@ -58,15 +57,8 @@ let make = () => {
handlePostMessage([
("fullscreen", false->JSON.Encode.bool),
("isPlaid", true->JSON.Encode.bool),
("publicToken", "sdjbcksdcjsncjsdc"->JSON.Encode.string),
("publicToken", ""->JSON.Encode.string),
])
Console.log2("Plaid link token onExit", json)
},
onLoad: json => {
Console.log2("Plaid link token onLoad", json)
},
onEvent: json => {
Console.log2("Plaid link token onEvent", json)
},
})

Expand All @@ -76,5 +68,5 @@ let make = () => {
None
}, (isReady, linkToken))

React.null
<div className="bg-black/40 backdrop-blur-sm" />
}
89 changes: 28 additions & 61 deletions src/Payments/VerifyBankDetails.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,33 @@ let make = (~paymentMethodType) => {
let {publishableKey, clientSecret, iframeId} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)
let {themeObj} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
let setShowFields = Recoil.useSetRecoilState(RecoilAtoms.showCardFieldsAtom)

let pmAuthConnectorsArr =
PmAuthConnectorUtils.findPmAuthAllPMAuthConnectors(
paymentMethodListValue.payment_methods,
)->PmAuthConnectorUtils.getAllRequiredPmAuthConnectors

// let callAuthExchange = publicToken => {
// open Promise
// let uri = `${endpoint}/payment_methods/auth/exchange`
// let updatedBody = body->Array.concat([("public_token", publicToken->JSON.Encode.string)])

// let headers =
// [("Content-Type", "application/json"), ("api-key", keys.publishableKey)]->Dict.fromArray

// fetchApi(
// uri,
// ~method=#POST,
// ~bodyStr=updatedBody->getJsonFromArrayOfJson->JSON.stringify,
// ~headers,
// (),
// )
// ->then(res => {
// let statusCode = res->Fetch.Response.status->Int.toString
// if statusCode->String.charAt(0) !== "2" {
// res
// ->Fetch.Response.json
// ->then(_ => {
// JSON.Encode.null->resolve
// })
// } else {
// PaymentHelpers.fetchCustomerPaymentMethodList(
// ~clientSecret=keys.clientSecret->Option.getOr(""),
// ~publishableKey=keys.publishableKey,
// ~optLogger=Some(logger),
// ~switchToCustomPod=false,
// ~endpoint,
// )
// ->then(customerListResponse => {
// let customerPaymentMethodsVal =
// customerListResponse
// ->getDictFromJson
// ->PaymentType.getCustomerMethods("customerPaymentMethods")
// setOptionValue(
// prev => {
// ...prev,
// customerPaymentMethods: customerPaymentMethodsVal,
// },
// )
// setShowFields(_ => false)
// res->Fetch.Response.json
// })
// ->catch(e => {
// Console.log2(
// "Unable to retrieve customer/payment_methods after auth/exchange because of ",
// e,
// )
// JSON.Encode.null->resolve
// })
// }
// })
// ->catch(e => {
// Console.log2("Unable to retrieve payment_methods auth/link because of ", e)
// JSON.Encode.null->resolve
// })
// }

React.useEffect0(() => {
let onPlaidCallback = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let dict = json->Utils.getDictFromJson
if dict->getBool("isPlaid", false) {
Js.log2("PlaidVerifftyddyaydcsdcsh", dict)
let publicToken = dict->getDictFromDict("data")->getString("publicToken", "")
if publicToken->String.length > 0 {
PaymentHelpers.callAuthExchange(
~publicToken,
~clientSecret,
~paymentMethodType,
~publishableKey,
)
->Promise.then(_ => {
setShowFields(_ => false)
JSON.Encode.null->Promise.resolve
})
->Promise.catch(_ => JSON.Encode.null->Promise.resolve)
->ignore
}
}
}

Expand All @@ -87,6 +42,18 @@ let make = (~paymentMethodType) => {
)
})

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
postFailedSubmitResponse(
~errortype="validation_error",
~message="Payment cannot be performed. Please go to saved PM Screen to update your payment method.",
)
}
}, [])
useSubmitPaymentData(submitCallback)

<button
onClick={_ =>
PaymentHelpers.callAuthLink(
Expand Down
3 changes: 1 addition & 2 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ let make = (
let dict = json->getDictFromJson
let isPlaidExist = dict->getBool("isPlaid", false)
if isPlaidExist {
Console.log("isPlaid send")
mountedIframeRef->Window.iframePostMessage(
[("isPlaid", true->JSON.Encode.bool), ("publicToken", json)]->Dict.fromArray,
[("isPlaid", true->JSON.Encode.bool), ("data", json)]->Dict.fromArray,
)
}
}
Expand Down

0 comments on commit fbf2ee3

Please sign in to comment.