From df6ae054eeea49cb519b7f37c67cb3d374f933e1 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar Date: Sat, 18 May 2024 00:50:47 +0530 Subject: [PATCH 1/5] feat: 3DS netcetra Part B --- src/Components/Modal.res | 8 +- src/ThreeDSAuth.res | 135 ++++++++++++++++++++++--------- src/ThreeDSMethod.res | 1 + src/Utilities/PaymentHelpers.res | 4 + 4 files changed, 108 insertions(+), 40 deletions(-) diff --git a/src/Components/Modal.res b/src/Components/Modal.res index ae38c39b0..1fd319440 100644 --- a/src/Components/Modal.res +++ b/src/Components/Modal.res @@ -18,11 +18,11 @@ let make = ( let {themeObj} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom) let closeModal = () => { setOpenModal(_ => false) + switch closeCallback { + | Some(fn) => fn() + | None => () + } setTimeout(() => { - switch closeCallback { - | Some(fn) => fn() - | None => () - } Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) }, 450)->ignore } diff --git a/src/ThreeDSAuth.res b/src/ThreeDSAuth.res index b9903c789..a8efcbf89 100644 --- a/src/ThreeDSAuth.res +++ b/src/ThreeDSAuth.res @@ -5,8 +5,22 @@ let make = () => { let (openModal, setOpenModal) = React.useState(_ => false) let (loader, setloader) = React.useState(_ => true) + let threeDsAuthoriseUrl = React.useRef("") + let (expiryTime, setExpiryTime) = React.useState(_ => 600000.0) + let logger = OrcaLogger.make(~source=Elements(Payment), ()) + let handleFrictionLess = () => { + let ele = Window.querySelector("#threeDsAuthDiv") + switch ele->Nullable.toOption { + | Some(elem) => { + let form1 = elem->makeForm(threeDsAuthoriseUrl.current, "3dsFrictionLess") + form1.submit() + } + | None => () + } + } + React.useEffect0(() => { handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { @@ -24,7 +38,7 @@ let make = () => { ->getJsonObjectFromDict("headers") ->JSON.Decode.object ->Option.getOr(Dict.make()) - let threeDsAuthoriseUrl = + threeDsAuthoriseUrl.current = metaDataDict ->getJsonObjectFromDict("threeDSData") ->JSON.Decode.object @@ -48,38 +62,47 @@ let make = () => { ) ->then(json => { let dict = json->JSON.Decode.object->Option.getOr(Dict.make()) - let creq = dict->getString("challenge_request", "") - let transStatus = dict->getString("trans_status", "Y") - let acsUrl = dict->getString("acs_url", "") + if dict->Dict.get("error")->Option.isSome { + let errorObj = PaymentError.itemToObjMapper(dict) + handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + postFailedSubmitResponse( + ~errortype=errorObj.error.type_, + ~message=errorObj.error.message, + ) + JSON.Encode.null->resolve + } else { + let creq = dict->getString("challenge_request", "") + let transStatus = dict->getString("trans_status", "Y") + let acsUrl = dict->getString("acs_url", "") - let ele = Window.querySelector("#threeDsAuthDiv") + let ele = Window.querySelector("#threeDsAuthDiv") - LoggerUtils.handleLogging( - ~optLogger=Some(logger), - ~eventName=DISPLAY_THREE_DS_SDK, - ~value=transStatus, - ~paymentMethod="CARD", - (), - ) + LoggerUtils.handleLogging( + ~optLogger=Some(logger), + ~eventName=DISPLAY_THREE_DS_SDK, + ~value=transStatus, + ~paymentMethod="CARD", + (), + ) - switch ele->Nullable.toOption { - | Some(elem) => - if transStatus === "C" { - setloader(_ => false) - let form = elem->makeForm(acsUrl, "3dsChallenge") - let input = Types.createElement("input") - input.name = "creq" - input.value = creq - form.target = "threeDsAuthFrame" - form.appendChild(input) - form.submit() - } else { - let form1 = elem->makeForm(threeDsAuthoriseUrl, "3dsFrictionLess") - form1.submit() + switch ele->Nullable.toOption { + | Some(elem) => + if transStatus === "C" { + setloader(_ => false) + let form = elem->makeForm(acsUrl, "3dsChallenge") + let input = Types.createElement("input") + input.name = "creq" + input.value = creq + form.target = "threeDsAuthFrame" + form.appendChild(input) + form.submit() + } else { + handleFrictionLess() + } + | None => () } - | None => () + resolve(json) } - resolve(json) }) ->catch(err => { let exceptionMessage = err->formatException @@ -91,6 +114,8 @@ let make = () => { ~logType=ERROR, (), ) + let errorObj = PaymentError.itemToObjMapper(dict) + postFailedSubmitResponse(~errortype=errorObj.error.type_, ~message=errorObj.error.message) JSON.Encode.null->resolve }) ->ignore @@ -100,12 +125,50 @@ let make = () => { Some(() => {Window.removeEventListener("message", handle)}) }) - -
-
-