From fbf2ee3ae556bb62d84e9191e5a73cef69de04e7 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Tue, 2 Jul 2024 01:27:32 +0530 Subject: [PATCH] fix: validations added --- src/Payments/PlaidSDKIframe.res | 12 +--- src/Payments/VerifyBankDetails.res | 89 ++++++++++-------------------- src/orca-loader/Elements.res | 3 +- 3 files changed, 31 insertions(+), 73 deletions(-) diff --git a/src/Payments/PlaidSDKIframe.res b/src/Payments/PlaidSDKIframe.res index 3503572ff..849cacecc 100644 --- a/src/Payments/PlaidSDKIframe.res +++ b/src/Payments/PlaidSDKIframe.res @@ -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), @@ -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) }, }) @@ -76,5 +68,5 @@ let make = () => { None }, (isReady, linkToken)) - React.null +
} diff --git a/src/Payments/VerifyBankDetails.res b/src/Payments/VerifyBankDetails.res index 795d49568..b41d6568f 100644 --- a/src/Payments/VerifyBankDetails.res +++ b/src/Payments/VerifyBankDetails.res @@ -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 + } } } @@ -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) +