Skip to content

Commit

Permalink
fix: removed unneccessary poll call if first retrieve is successful
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanskar2001 committed May 31, 2024
1 parent 29b558b commit 1c3033a
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions src/hooks/NetceteraThreeDsHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,22 @@ let useNetceteraThreeDsHook = (~retrievePayment) => {
~onFailure: string => unit,
) => {
let retriveAndShowStatus = () => {
// apiLogWrapper(
// ~logType=INFO,
// ~eventName=RETRIEVE_CALL_INIT,
// ~url=baseUrl,
// ~statusCode="",
// ~apiLogType=Request,
// ~data=JSON.Encode.null,
// (),
// )
retrievePayment(Types.Payment, clientSecret, publishableKey)
->Promise.then(res => {
if res == JSON.Encode.null {
onFailure(retrievePaymentStatus.apiCallFailure)
} else {
let status = res->Utils.getDictFromJson->Utils.getString("status", "")

// apiLogWrapper(
// ~logType=INFO,
// ~eventName=RETRIEVE_CALL,
// ~url=baseUrl,
// ~statusCode="",
// ~apiLogType=Response,
// ~data=res,
// (),
// )

switch status {
| "processing" | "succeeded" => onSuccess(retrievePaymentStatus.successMsg)
| _ => onFailure(retrievePaymentStatus.errorMsg)
}
}->ignore
Promise.resolve()
})
->Promise.catch(err => {
// apiLogWrapper(
// ~logType=ERROR,
// ~eventName=RETRIEVE_CALL,
// ~url=baseUrl,
// ~statusCode="504",
// ~apiLogType=NoResponse,
// ~data=err->toJson,
// (),
// )
->Promise.catch(_ => {
onFailure(SdkStatusMessages.retrievePaymentStatus.apiCallFailure)
Promise.resolve()
})
->ignore
Expand Down Expand Up @@ -231,6 +204,7 @@ let useNetceteraThreeDsHook = (~retrievePayment) => {
~data=err->toJson,
(),
)
retriveAndShowStatus()
Promise.resolve(None)
})
}
Expand Down Expand Up @@ -398,7 +372,7 @@ let useNetceteraThreeDsHook = (~retrievePayment) => {
})
}

let handleNetcetera3DS = (
let startNetcetera3DSFlow = (
~netceteraSDKApiKey: string,
~clientSecret: string,
~publishableKey: string,
Expand Down Expand Up @@ -445,7 +419,7 @@ let useNetceteraThreeDsHook = (~retrievePayment) => {
},
)
} catch {
| err => onFailure("")
| _ => retriveAndShowStatus()
}
}

Expand Down Expand Up @@ -473,16 +447,21 @@ let useNetceteraThreeDsHook = (~retrievePayment) => {
let status = res->Utils.getDictFromJson->Utils.getString("status", "")
switch status {
| "processing" => onSuccess(retrievePaymentStatus.successMsg)
| "succeeded" => onSuccess(retrievePaymentStatus.successMsg)
| "failed" => onFailure(retrievePaymentStatus.errorMsg)
| _ => shortPollStatusAndRetrieve(~pollConfig=threeDsData.pollConfig, ~publishableKey)
}
}
Promise.resolve()
})
->Promise.catch(_ => {
onFailure(retrievePaymentStatus.apiCallFailure)
Promise.resolve()
})
->ignore
}

handleNetcetera3DS(
startNetcetera3DSFlow(
~netceteraSDKApiKey,
~clientSecret,
~publishableKey,
Expand Down

0 comments on commit 1c3033a

Please sign in to comment.