Skip to content

Commit b61bc3c

Browse files
feat: three_ds polling part2 (#334)
1 parent 9d7e8ea commit b61bc3c

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

src/Utilities/PaymentHelpers.res

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ let retrieveStatus = (~headers, ~switchToCustomPod, pollID) => {
245245
})
246246
}
247247

248-
let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count) => {
248+
let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count, ~returnUrl) => {
249249
open Promise
250250
retrieveStatus(~headers, ~switchToCustomPod, pollId)
251251
->then(json => {
@@ -254,14 +254,21 @@ let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count)
254254
Promise.make((resolve, _) => {
255255
if status === "completed" {
256256
resolve(json)
257-
} else if !(count > 0) {
257+
} else if count === 0 {
258258
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
259-
postFailedSubmitResponse(~errortype="server_error", ~message="Something went wrong") // redirect to return url
259+
openUrl(returnUrl)
260260
} else {
261261
delay(interval)
262262
->then(
263263
_ => {
264-
pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count=count - 1)
264+
pollStatus(
265+
~headers,
266+
~switchToCustomPod,
267+
~pollId,
268+
~interval,
269+
~count=count - 1,
270+
~returnUrl,
271+
)
265272
},
266273
)
267274
->ignore
@@ -270,7 +277,7 @@ let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count)
270277
})
271278
->catch(e => {
272279
Console.log2("Unable to retrieve payment due to following error", e)
273-
pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count=count - 1)
280+
pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count=count - 1, ~returnUrl)
274281
})
275282
}
276283

src/orca-loader/Elements.res

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -439,20 +439,39 @@ let make = (
439439
dict->getString("delay_in_secs", "")->Int.fromString->Option.getOr(1) * 1000
440440
let count = dict->getString("frequency", "")->Int.fromString->Option.getOr(5)
441441
let url = dict->getString("return_url_with_query_params", "")
442-
PaymentHelpers.pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count)
443-
->then(res => {
444-
let dict = res->JSON.Decode.object->Option.getOr(Dict.make())
445-
let status = dict->getString("status", "")
446-
if status === "completed" {
447-
Window.Location.replace(url)->ignore // retrive status
448-
}->resolve
449-
})
450-
->catch(_e =>
451-
postFailedSubmitResponse(
452-
~errortype="Server_error",
453-
~message="Something went Wrong",
454-
)->resolve
442+
PaymentHelpers.pollStatus(
443+
~headers,
444+
~switchToCustomPod,
445+
~pollId,
446+
~interval,
447+
~count,
448+
~returnUrl=url,
455449
)
450+
->then(_ => {
451+
PaymentHelpers.retrievePaymentIntent(
452+
clientSecret,
453+
headers,
454+
~optLogger=Some(logger),
455+
~switchToCustomPod,
456+
~isForceSync=true,
457+
)
458+
->then(json => {
459+
let dict = json->JSON.Decode.object->Option.getOr(Dict.make())
460+
let status = dict->getString("status", "")
461+
let returnUrl = dict->getString("return_url", "")
462+
Window.Location.replace(
463+
`${returnUrl}?payment_intent_client_secret=${clientSecret}&status=${status}`,
464+
)
465+
resolve()
466+
})
467+
->catch(_ => {
468+
Window.Location.replace(url)
469+
resolve()
470+
})
471+
->ignore
472+
->resolve
473+
})
474+
->catch(e => Console.log2("POLL_STATUS ERROR -", e)->resolve)
456475
->ignore
457476
}
458477
| None => ()

0 commit comments

Comments
 (0)