From 205054ff0dd1083c28c3ef5eb159e70440715efc Mon Sep 17 00:00:00 2001 From: ArushKapoorJuspay <121166031+ArushKapoorJuspay@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:37:00 +0530 Subject: [PATCH 1/2] fix: added support for redirectUrl for netcetera flow (#636) --- src/orca-loader/Elements.res | 108 ++++++++++++++++++++--------------- src/orca-loader/Hyper.res | 6 +- 2 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 1785ab672..a493e6ed7 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -609,6 +609,25 @@ let make = ( | Some(obj) => redirect := obj->getDictFromJson->getString("redirect", "if_required") | None => () } + + let handleRetrievePaymentResponse = json => { + let dict = json->getDictFromJson + let status = dict->getString("status", "") + let returnUrl = dict->getString("return_url", "") + let redirectUrl = `${returnUrl}?payment_intent_client_secret=${clientSecret}&status=${status}` + if redirect.contents === "always" { + Window.replaceRootHref(redirectUrl) + resolve(JSON.Encode.null) + } else { + messageCurrentWindow([ + ("submitSuccessful", true->JSON.Encode.bool), + ("data", json), + ("url", redirectUrl->JSON.Encode.string), + ]) + resolve(json) + } + } + switch eventDataObject->getOptionalJsonFromJson("poll_status") { | Some(val) => { messageCurrentWindow([ @@ -622,6 +641,18 @@ 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", "") + + let handleErrorResponse = err => { + if redirect.contents === "always" { + Window.replaceRootHref(url) + } + messageCurrentWindow([ + ("submitSuccessful", false->JSON.Encode.bool), + ("error", err->Identity.anyTypeToJson), + ("url", url->JSON.Encode.string), + ]) + } + PaymentHelpers.pollStatus( ~headers, ~customPodUri, @@ -639,74 +670,54 @@ let make = ( ~customPodUri, ~isForceSync=true, ) - ->then(json => { - if redirect.contents === "always" { - let dict = json->getDictFromJson - let status = dict->getString("status", "") - let returnUrl = dict->getString("return_url", "") - Window.replaceRootHref( - `${returnUrl}?payment_intent_client_secret=${clientSecret}&status=${status}`, - ) - resolve(JSON.Encode.null) - } else { - messageCurrentWindow([ - ("fullscreen", false->JSON.Encode.bool), - ("submitSuccessful", true->JSON.Encode.bool), - ("data", json), - ]) - resolve(json) - } - }) + ->then(json => json->handleRetrievePaymentResponse) ->catch(err => { - if redirect.contents === "always" { - Window.replaceRootHref(url) - } - messageCurrentWindow([ - ("submitSuccessful", false->JSON.Encode.bool), - ("error", err->Identity.anyTypeToJson), - ]) + err->handleErrorResponse resolve(err->Identity.anyTypeToJson) }) ->ignore ->resolve }) - ->catch(e => Console.log2("POLL_STATUS ERROR -", e)->resolve) + ->catch(err => { + err->handleErrorResponse + resolve() + }) + ->finally(_ => messageCurrentWindow([("fullscreen", false->JSON.Encode.bool)])) ->ignore } | None => () } switch eventDataObject->getOptionalJsonFromJson("openurl_if_required") { - | Some(val) => + | Some(redirectUrl) => messageCurrentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", selectorString->JSON.Encode.string), ]) - if redirect.contents === "always" { - Window.Location.replace(val->JSON.Decode.string->Option.getOr("")) - resolve(JSON.Encode.null) - } else { - PaymentHelpers.retrievePaymentIntent( - clientSecret, - headers, - ~optLogger=Some(logger), - ~customPodUri, - ~isForceSync=true, - ) - ->then(json => { - messageCurrentWindow([("submitSuccessful", true->JSON.Encode.bool), ("data", json)]) - resolve(json) - }) - ->catch(err => { + PaymentHelpers.retrievePaymentIntent( + clientSecret, + headers, + ~optLogger=Some(logger), + ~customPodUri, + ~isForceSync=true, + ) + ->then(json => json->handleRetrievePaymentResponse) + ->catch(err => { + if redirect.contents === "always" { + Window.replaceRootHref(redirectUrl->JSON.Decode.string->Option.getOr("")) + resolve(JSON.Encode.null) + } else { messageCurrentWindow([ ("submitSuccessful", false->JSON.Encode.bool), ("error", err->Identity.anyTypeToJson), + ("url", redirectUrl), ]) resolve(err->Identity.anyTypeToJson) - }) - ->finally(_ => messageCurrentWindow([("fullscreen", false->JSON.Encode.bool)])) - }->ignore + } + }) + ->finally(_ => messageCurrentWindow([("fullscreen", false->JSON.Encode.bool)])) + ->ignore | None => () } @@ -774,7 +785,10 @@ let make = ( switch ( dict->Dict.get("applePayButtonClicked"), dict->Dict.get("applePayPaymentRequest"), - dict->Dict.get("isTaxCalculationEnabled")->Option.flatMap(JSON.Decode.bool)->Option.getOr(false), + dict + ->Dict.get("isTaxCalculationEnabled") + ->Option.flatMap(JSON.Decode.bool) + ->Option.getOr(false), ) { | (Some(val), Some(paymentRequest), isTaxCalculationEnabled) => if val->JSON.Decode.bool->Option.getOr(false) { diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res index c3f5be69c..692a53196 100644 --- a/src/orca-loader/Hyper.res +++ b/src/orca-loader/Hyper.res @@ -317,11 +317,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionJSON.Decode.bool->Option.getOr(false)) { - resolve1(json) - } else { - Window.replaceRootHref(returnUrl) - } + Window.replaceRootHref(returnUrl) } else if val->JSON.Decode.bool->Option.getOr(false) && redirect === "always" { Window.replaceRootHref(returnUrl) } else if !(val->JSON.Decode.bool->Option.getOr(false)) { From d8abf880b0fa151734c2ed3d7d2ea001c2bce80d Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 23 Sep 2024 13:08:38 +0000 Subject: [PATCH 2/2] chore(release): 0.88.4 [skip ci] ## [0.88.4](https://github.com/juspay/hyperswitch-web/compare/v0.88.3...v0.88.4) (2024-09-23) ### Bug Fixes * added support for redirectUrl for netcetera flow ([#636](https://github.com/juspay/hyperswitch-web/issues/636)) ([205054f](https://github.com/juspay/hyperswitch-web/commit/205054ff0dd1083c28c3ef5eb159e70440715efc)) --- 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 bb89e3c0f..e97ffd60e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [0.88.4](https://github.com/juspay/hyperswitch-web/compare/v0.88.3...v0.88.4) (2024-09-23) + + +### Bug Fixes + +* added support for redirectUrl for netcetera flow ([#636](https://github.com/juspay/hyperswitch-web/issues/636)) ([205054f](https://github.com/juspay/hyperswitch-web/commit/205054ff0dd1083c28c3ef5eb159e70440715efc)) + ## [0.88.3](https://github.com/juspay/hyperswitch-web/compare/v0.88.2...v0.88.3) (2024-09-20) diff --git a/package-lock.json b/package-lock.json index acd2e7e2a..e5ab1c962 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "orca-payment-page", - "version": "0.88.3", + "version": "0.88.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "orca-payment-page", - "version": "0.88.3", + "version": "0.88.4", "hasInstallScript": true, "dependencies": { "@glennsl/rescript-fetch": "^0.2.0", diff --git a/package.json b/package.json index bbff902fe..4784f7b41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orca-payment-page", - "version": "0.88.3", + "version": "0.88.4", "main": "index.js", "private": true, "dependencies": {