From b61bc3cdd049a8b66bbfe38879367ecb22ec0659 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar <126236898+prafulkoppalkar@users.noreply.github.com> Date: Fri, 26 Apr 2024 21:46:50 +0530 Subject: [PATCH 1/2] feat: three_ds polling part2 (#334) --- src/Utilities/PaymentHelpers.res | 17 ++++++++---- src/orca-loader/Elements.res | 45 +++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index ccdcf56aa..884017dfe 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -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 => { @@ -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 @@ -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) }) } diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 37716fc43..287e70c44 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -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 => () From 95451bd676c0dfe357d0a7252f32ebbcab4c22e4 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 26 Apr 2024 16:18:58 +0000 Subject: [PATCH 2/2] chore(release): 0.46.0 [skip ci] # [0.46.0](https://github.com/juspay/hyperswitch-web/compare/v0.45.1...v0.46.0) (2024-04-26) ### Features * three_ds polling part2 ([#334](https://github.com/juspay/hyperswitch-web/issues/334)) ([b61bc3c](https://github.com/juspay/hyperswitch-web/commit/b61bc3cdd049a8b66bbfe38879367ecb22ec0659)) --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78c01f3b2..a3a0e49a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [0.46.0](https://github.com/juspay/hyperswitch-web/compare/v0.45.1...v0.46.0) (2024-04-26) + + +### Features + +* three_ds polling part2 ([#334](https://github.com/juspay/hyperswitch-web/issues/334)) ([b61bc3c](https://github.com/juspay/hyperswitch-web/commit/b61bc3cdd049a8b66bbfe38879367ecb22ec0659)) + ## [0.45.1](https://github.com/juspay/hyperswitch-web/compare/v0.45.0...v0.45.1) (2024-04-24) diff --git a/package-lock.json b/package-lock.json index 198b7af94..369f843b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "orca-payment-page", - "version": "0.45.1", + "version": "0.46.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "orca-payment-page", - "version": "0.45.1", + "version": "0.46.0", "hasInstallScript": true, "dependencies": { "@aws-sdk/client-cloudfront": "^3.414.0", diff --git a/package.json b/package.json index 88b168e81..97e0a0b45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orca-payment-page", - "version": "0.45.1", + "version": "0.46.0", "main": "index.js", "private": true, "dependencies": {