diff --git a/CHANGELOG.md b/CHANGELOG.md index bd73e3637..1fdcefa46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## [0.45.4](https://github.com/juspay/hyperswitch-web/compare/v0.45.3...v0.45.4) (2024-04-25) + + +### Bug Fixes + +* apple pay debug ([34d4828](https://github.com/juspay/hyperswitch-web/commit/34d4828894c284c514dc869c6c75c4af59e873cd)) + +## [0.45.3](https://github.com/juspay/hyperswitch-web/compare/v0.45.2...v0.45.3) (2024-04-25) + + +### Bug Fixes + +* apple pay debugging ([#333](https://github.com/juspay/hyperswitch-web/issues/333)) ([ca96770](https://github.com/juspay/hyperswitch-web/commit/ca96770a46c0e273da77ae3f4d1fa154c6f8a87f)) + ## [0.45.2](https://github.com/juspay/hyperswitch-web/compare/v0.45.1...v0.45.2) (2024-04-24) diff --git a/package-lock.json b/package-lock.json index bbb44dd3d..43f9a8609 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "orca-payment-page", - "version": "0.45.2", + "version": "0.45.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "orca-payment-page", - "version": "0.45.2", + "version": "0.45.4", "hasInstallScript": true, "dependencies": { "@aws-sdk/client-cloudfront": "^3.414.0", diff --git a/package.json b/package.json index da65d966d..1e2d851c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orca-payment-page", - "version": "0.45.2", + "version": "0.45.4", "main": "index.js", "private": true, "dependencies": { diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 6c206410c..bd37e6f31 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -23,6 +23,16 @@ let make = ( ) => { let handleApplePayMessages = ref(_ => ()) let applePaySessionRef = ref(Nullable.null) + let isReadyToLoadTrustpayPromise = Promise.make((resolve, _) => { + let handleOnReady = (event: Types.event) => { + let json = event.data->anyTypeToJson + let dict = json->getDictFromJson + if dict->Dict.get("preMountLoaderIframeUnMount")->Belt.Option.isSome { + resolve() + } + } + addSmartEventListener("message", handleOnReady, "handleOnReadyToLoadTrustpayScript") + }) try { let iframeRef = [] @@ -144,13 +154,21 @@ let make = ( publishableKey->String.startsWith("pk_prd_") ? "https://tpgw.trustpay.eu/js/v1.js" : "https://test-tpgw.trustpay.eu/js/v1.js" - let trustPayScript = Window.createElement("script") - trustPayScript->Window.elementSrc(trustPayScriptURL) - trustPayScript->Window.elementOnerror(err => { - Utils.logInfo(Console.log2("ERROR DURING LOADING TRUSTPAY APPLE PAY", err)) + isReadyToLoadTrustpayPromise + ->Promise.then(_ => { + let trustPayScript = Window.createElement("script") + logger.setLogInfo(~value="TrustPay Script Loading", ~eventName=TRUSTPAY_SCRIPT, ()) + trustPayScript->Window.elementSrc(trustPayScriptURL) + trustPayScript->Window.elementOnerror(err => { + Utils.logInfo(Console.log2("ERROR DURING LOADING TRUSTPAY APPLE PAY", err)) + }) + trustPayScript->Window.elementOnload(_ => { + logger.setLogInfo(~value="TrustPay Script Loaded", ~eventName=TRUSTPAY_SCRIPT, ()) + }) + Window.body->Window.appendChild(trustPayScript) + Promise.resolve() }) - Window.body->Window.appendChild(trustPayScript) - logger.setLogInfo(~value="TrustPay Script Loaded", ~eventName=TRUSTPAY_SCRIPT, ()) + ->ignore } } let msg = [("paymentMethodList", json)]->Dict.fromArray @@ -618,54 +636,63 @@ let make = ( ) try { - let trustpay = trustPayApi(secrets) - trustpay.finishApplePaymentV2(payment, paymentRequest) - ->then(res => { + setTimeout(() => { + let trustpay = trustPayApi(secrets) Window.window->alert( - "res: " ++ res->anyTypeToJson->JSON.stringify, + "trustpay: " ++ trustpay->anyTypeToJson->JSON.stringify, ) - logger.setLogInfo( - ~value="TrustPay ApplePay Success Response", - ~internalMetadata=res->JSON.stringify, - ~eventName=APPLE_PAY_FLOW, - ~paymentMethod="APPLE_PAY", - (), + trustpay.finishApplePaymentV2(payment, paymentRequest) + ->then( + res => { + Window.window->alert( + "res: " ++ res->anyTypeToJson->JSON.stringify, + ) + logger.setLogInfo( + ~value="TrustPay ApplePay Success Response", + ~internalMetadata=res->JSON.stringify, + ~eventName=APPLE_PAY_FLOW, + ~paymentMethod="APPLE_PAY", + (), + ) + let msg = + [ + ("applePaySyncPayment", true->JSON.Encode.bool), + ("breakpoint", "1"->JSON.Encode.string), + ]->Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + logger.setLogInfo( + ~value="", + ~eventName=PAYMENT_DATA_FILLED, + ~paymentMethod="APPLE_PAY", + (), + ) + resolve() + }, ) - let msg = - [ - ("applePaySyncPayment", true->JSON.Encode.bool), - ("breakpoint", "1"->JSON.Encode.string), - ]->Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - logger.setLogInfo( - ~value="", - ~eventName=PAYMENT_DATA_FILLED, - ~paymentMethod="APPLE_PAY", - (), - ) - resolve() - }) - ->catch(err => { - let exceptionMessage = - err->Utils.formatException->JSON.stringify - Window.window->alert( - "err: " ++ err->anyTypeToJson->JSON.stringify, - ) - logger.setLogInfo( - ~eventName=APPLE_PAY_FLOW, - ~paymentMethod="APPLE_PAY", - ~value=exceptionMessage, - (), + ->catch( + err => { + let exceptionMessage = + err->Utils.formatException->JSON.stringify + Window.window->alert( + "err: " ++ err->anyTypeToJson->JSON.stringify, + ) + logger.setLogInfo( + ~eventName=APPLE_PAY_FLOW, + ~paymentMethod="APPLE_PAY", + ~value=exceptionMessage, + (), + ) + let msg = + [ + ("applePaySyncPayment", true->JSON.Encode.bool), + ("breakpoint", "2"->JSON.Encode.string), + ]->Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }, ) - let msg = - [ - ("applePaySyncPayment", true->JSON.Encode.bool), - ("breakpoint", "2"->JSON.Encode.string), - ]->Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - resolve() - }) - ->ignore + ->ignore + }, 0)->ignore } catch { | exn => { logger.setLogInfo(