Skip to content

Commit

Permalink
feat: three_ds polling part2 (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
prafulkoppalkar authored Apr 26, 2024
1 parent 9d7e8ea commit b61bc3c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
17 changes: 12 additions & 5 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ let retrieveStatus = (~headers, ~switchToCustomPod, pollID) => {
})
}

let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count) => {
let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count, ~returnUrl) => {
open Promise
retrieveStatus(~headers, ~switchToCustomPod, pollId)
->then(json => {
Expand All @@ -254,14 +254,21 @@ let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count)
Promise.make((resolve, _) => {
if status === "completed" {
resolve(json)
} else if !(count > 0) {
} else if count === 0 {
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
postFailedSubmitResponse(~errortype="server_error", ~message="Something went wrong") // redirect to return url
openUrl(returnUrl)
} else {
delay(interval)
->then(
_ => {
pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count=count - 1)
pollStatus(
~headers,
~switchToCustomPod,
~pollId,
~interval,
~count=count - 1,
~returnUrl,
)
},
)
->ignore
Expand All @@ -270,7 +277,7 @@ let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count)
})
->catch(e => {
Console.log2("Unable to retrieve payment due to following error", e)
pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count=count - 1)
pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count=count - 1, ~returnUrl)
})
}

Expand Down
45 changes: 32 additions & 13 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -439,20 +439,39 @@ let make = (
dict->getString("delay_in_secs", "")->Int.fromString->Option.getOr(1) * 1000
let count = dict->getString("frequency", "")->Int.fromString->Option.getOr(5)
let url = dict->getString("return_url_with_query_params", "")
PaymentHelpers.pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count)
->then(res => {
let dict = res->JSON.Decode.object->Option.getOr(Dict.make())
let status = dict->getString("status", "")
if status === "completed" {
Window.Location.replace(url)->ignore // retrive status
}->resolve
})
->catch(_e =>
postFailedSubmitResponse(
~errortype="Server_error",
~message="Something went Wrong",
)->resolve
PaymentHelpers.pollStatus(
~headers,
~switchToCustomPod,
~pollId,
~interval,
~count,
~returnUrl=url,
)
->then(_ => {
PaymentHelpers.retrievePaymentIntent(
clientSecret,
headers,
~optLogger=Some(logger),
~switchToCustomPod,
~isForceSync=true,
)
->then(json => {
let dict = json->JSON.Decode.object->Option.getOr(Dict.make())
let status = dict->getString("status", "")
let returnUrl = dict->getString("return_url", "")
Window.Location.replace(
`${returnUrl}?payment_intent_client_secret=${clientSecret}&status=${status}`,
)
resolve()
})
->catch(_ => {
Window.Location.replace(url)
resolve()
})
->ignore
->resolve
})
->catch(e => Console.log2("POLL_STATUS ERROR -", e)->resolve)
->ignore
}
| None => ()
Expand Down

0 comments on commit b61bc3c

Please sign in to comment.