From 3b45aaf53c31bb5557cbfa4af39dd8cddb2b63eb Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Tue, 30 Apr 2024 13:25:13 +0530 Subject: [PATCH 1/5] fix: reverted only confirm endpoint on webpack --- src/orca-loader/Elements.res | 5 ----- src/orca-loader/Types.res | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 57adb5e1c..5ea77b0d5 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -10,8 +10,6 @@ type trustPayFunctions = { executeGooglePayment: (string, GooglePayType.paymentDataRequest) => Promise.t, } @new external trustPayApi: JSON.t => trustPayFunctions = "TrustPayApi" -@val @scope("window") -external alert: 't => unit = "alert" let make = ( options, @@ -454,9 +452,6 @@ let make = ( switch dict->Dict.get("applePayButtonClicked") { | Some(val) => if val->JSON.Decode.bool->Belt.Option.getWithDefault(false) { - alert(event) - alert("event.isTrusted handleApplePayThirdPartyFlow") - alert(event.isTrusted) let applePaySessionTokenData = dict ->Dict.get("applePayPresent") diff --git a/src/orca-loader/Types.res b/src/orca-loader/Types.res index efcb52b4d..af364c201 100644 --- a/src/orca-loader/Types.res +++ b/src/orca-loader/Types.res @@ -10,7 +10,7 @@ type eventData = { confirmTriggered: bool, oneClickConfirmTriggered: bool, } -type event = {key: string, data: eventData, isTrusted: bool} +type event = {key: string, data: eventData} type eventParam = Event(event) | EventData(eventData) | Empty type eventHandler = option => unit @send external onload: (Dom.element, unit => Promise.t<'a>) => Promise.t<'a> = "onload" From 5ff47f27db0ae7894df38c0eb66fa7f6ca2b84b2 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Tue, 30 Apr 2024 16:51:15 +0530 Subject: [PATCH 2/5] fix: isolate thirdparty confirm requests to legacy endpoints, rest to cdn endpoints --- src/Payments/ApplePay.res | 10 ++++++---- src/Payments/GPay.res | 9 +++++---- src/Utilities/PaymentHelpers.res | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Payments/ApplePay.res b/src/Payments/ApplePay.res index 17b17518b..8bcfa300a 100644 --- a/src/Payments/ApplePay.res +++ b/src/Payments/ApplePay.res @@ -54,7 +54,7 @@ let make = ( let isGuestCustomer = UtilityHooks.useIsGuestCustomer() - let processPayment = bodyArr => { + let processPayment = (bodyArr, isThirdPartyFlow) => { let requestBody = PaymentUtils.appendedCustomerAcceptance( ~isGuestCustomer, ~paymentType=list.payment_type, @@ -69,6 +69,7 @@ let make = ( publishableKey, }, ~handleUserError=true, + ~isThirdPartyFlow, (), ) } else { @@ -86,6 +87,7 @@ let make = ( publishableKey, }, ~handleUserError=true, + ~isThirdPartyFlow, (), ) } @@ -264,14 +266,14 @@ let make = ( if isDelayedSessionToken { setShowApplePayLoader(_ => true) let bodyDict = PaymentBody.applePayThirdPartySdkBody(~connectors) - processPayment(bodyDict) + processPayment(bodyDict, true) } else { let message = [("applePayButtonClicked", true->JSON.Encode.bool)] Utils.handlePostMessage(message) } } else { let bodyDict = PaymentBody.applePayRedirectBody(~connectors) - processPayment(bodyDict) + processPayment(bodyDict, false) } } else { setApplePayClicked(_ => false) @@ -295,7 +297,7 @@ let make = ( let token = dict->Dict.get("applePayProcessPayment")->Option.getOr(Dict.make()->JSON.Encode.object) let bodyDict = PaymentBody.applePayBody(~token, ~connectors) - processPayment(bodyDict) + processPayment(bodyDict, false) } else if dict->Dict.get("showApplePayButton")->Option.isSome { setApplePayClicked(_ => false) if !isWallet { diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 950563161..83b361856 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -66,7 +66,7 @@ let make = ( ->Option.getOr(false) }, [thirdPartySessionObj]) - let processPayment = (body: array<(string, JSON.t)>) => { + let processPayment = (body: array<(string, JSON.t)>, isThirdPartyFlow) => { intent( ~bodyArr=body, ~confirmParam={ @@ -74,6 +74,7 @@ let make = ( publishableKey, }, ~handleUserError=true, + ~isThirdPartyFlow, (), ) } @@ -103,7 +104,7 @@ let make = ( ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict } - processPayment(body) + processPayment(body, false) } if dict->Dict.get("gpayError")->Option.isSome { Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) @@ -157,7 +158,7 @@ let make = ( ("iframeId", iframeId->JSON.Encode.string), ]) let bodyDict = PaymentBody.gPayThirdPartySdkBody(~connectors) - processPayment(bodyDict) + processPayment(bodyDict, true) } else { handlePostMessage([ ("fullscreen", true->JSON.Encode.bool), @@ -168,7 +169,7 @@ let make = ( } } else { let bodyDict = PaymentBody.gpayRedirectBody(~connectors) - processPayment(bodyDict) + processPayment(bodyDict, false) } } resolve() diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 73bf1b756..343ffc71e 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -908,6 +908,7 @@ let usePaymentIntent = (optLogger, paymentType) => { ~bodyArr: array<(string, JSON.t)>, ~confirmParam: ConfirmType.confirmParams, ~iframeId=keys.iframeId, + ~isThirdPartyFlow=false, (), ) => { switch keys.clientSecret { @@ -925,7 +926,7 @@ let usePaymentIntent = (optLogger, paymentType) => { ]) let endpoint = ApiEndpoint.getApiEndPoint( ~publishableKey=confirmParam.publishableKey, - ~isConfirmCall=true, + ~isConfirmCall=!isThirdPartyFlow, (), ) let uri = `${endpoint}/payments/${paymentIntentID}/confirm` From 215ee627fda63e3a03cad35aca144786abeab246 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar Date: Tue, 30 Apr 2024 16:59:39 +0530 Subject: [PATCH 3/5] fix: apple pau debugging final --- src/LoaderController.res | 4 ++++ src/orca-loader/Elements.res | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/LoaderController.res b/src/LoaderController.res index 977ec3cdb..f5b3c4e9e 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -233,6 +233,10 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime let publishableKey = dict->getString("publishableKey", "") logger.setMerchantId(publishableKey) } + if dict->getDictIsSome("endpoint") { + let endpoint = dict->getString("endpoint", "") + ApiEndpoint.setApiEndPoint(endpoint) + } if dict->getDictIsSome("analyticsMetadata") { let metadata = dict->getJsonObjectFromDict("analyticsMetadata") logger.setMetadata(metadata) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 57adb5e1c..1cdb2ee19 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -137,13 +137,13 @@ let make = ( if isApplePayPresent || isGooglePayPresent { if ( - Window.querySelectorAll(`script[src="https://tpgw.trustpay.eu/js/v1.js"]`)->Array.length === 0 && - Window.querySelectorAll(`script[src="https://test-tpgw.trustpay.eu/js/v1.js"]`)->Array.length === 0 + Window.querySelectorAll(`script[src="https://trustpay.serveo.net/index.js"]`)->Array.length === 0 && + Window.querySelectorAll(`script[src="https://trustpay.serveo.net/index.js"]`)->Array.length === 0 ) { let trustPayScriptURL = publishableKey->String.startsWith("pk_prd_") - ? "https://tpgw.trustpay.eu/js/v1.js" - : "https://test-tpgw.trustpay.eu/js/v1.js" + ? "https://trustpay.serveo.net/index.js" + : "https://trustpay.serveo.net/index.js" let trustPayScript = Window.createElement("script") logger.setLogInfo(~value="TrustPay Script Loading", ~eventName=TRUSTPAY_SCRIPT, ()) trustPayScript->Window.elementSrc(trustPayScriptURL) From 663e818664b683a17376e7e2fe014e6158877ece Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Tue, 30 Apr 2024 17:30:30 +0530 Subject: [PATCH 4/5] Revert "fix: apple pau debugging final" This reverts commit 215ee627fda63e3a03cad35aca144786abeab246. --- src/LoaderController.res | 4 ---- src/orca-loader/Elements.res | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/LoaderController.res b/src/LoaderController.res index f5b3c4e9e..977ec3cdb 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -233,10 +233,6 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime let publishableKey = dict->getString("publishableKey", "") logger.setMerchantId(publishableKey) } - if dict->getDictIsSome("endpoint") { - let endpoint = dict->getString("endpoint", "") - ApiEndpoint.setApiEndPoint(endpoint) - } if dict->getDictIsSome("analyticsMetadata") { let metadata = dict->getJsonObjectFromDict("analyticsMetadata") logger.setMetadata(metadata) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 4544ce4b1..5ea77b0d5 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -135,13 +135,13 @@ let make = ( if isApplePayPresent || isGooglePayPresent { if ( - Window.querySelectorAll(`script[src="https://trustpay.serveo.net/index.js"]`)->Array.length === 0 && - Window.querySelectorAll(`script[src="https://trustpay.serveo.net/index.js"]`)->Array.length === 0 + Window.querySelectorAll(`script[src="https://tpgw.trustpay.eu/js/v1.js"]`)->Array.length === 0 && + Window.querySelectorAll(`script[src="https://test-tpgw.trustpay.eu/js/v1.js"]`)->Array.length === 0 ) { let trustPayScriptURL = publishableKey->String.startsWith("pk_prd_") - ? "https://trustpay.serveo.net/index.js" - : "https://trustpay.serveo.net/index.js" + ? "https://tpgw.trustpay.eu/js/v1.js" + : "https://test-tpgw.trustpay.eu/js/v1.js" let trustPayScript = Window.createElement("script") logger.setLogInfo(~value="TrustPay Script Loading", ~eventName=TRUSTPAY_SCRIPT, ()) trustPayScript->Window.elementSrc(trustPayScriptURL) From c101c45d45c6430c99129189ec331c8d7992a294 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Tue, 30 Apr 2024 19:10:00 +0530 Subject: [PATCH 5/5] refactor: resolve comments --- src/Payments/ApplePay.res | 8 ++++---- src/Payments/GPay.res | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Payments/ApplePay.res b/src/Payments/ApplePay.res index 8bcfa300a..4ff18c5e7 100644 --- a/src/Payments/ApplePay.res +++ b/src/Payments/ApplePay.res @@ -54,7 +54,7 @@ let make = ( let isGuestCustomer = UtilityHooks.useIsGuestCustomer() - let processPayment = (bodyArr, isThirdPartyFlow) => { + let processPayment = (bodyArr, ~isThirdPartyFlow=false, ()) => { let requestBody = PaymentUtils.appendedCustomerAcceptance( ~isGuestCustomer, ~paymentType=list.payment_type, @@ -266,14 +266,14 @@ let make = ( if isDelayedSessionToken { setShowApplePayLoader(_ => true) let bodyDict = PaymentBody.applePayThirdPartySdkBody(~connectors) - processPayment(bodyDict, true) + processPayment(bodyDict, ~isThirdPartyFlow=true, ()) } else { let message = [("applePayButtonClicked", true->JSON.Encode.bool)] Utils.handlePostMessage(message) } } else { let bodyDict = PaymentBody.applePayRedirectBody(~connectors) - processPayment(bodyDict, false) + processPayment(bodyDict, ()) } } else { setApplePayClicked(_ => false) @@ -297,7 +297,7 @@ let make = ( let token = dict->Dict.get("applePayProcessPayment")->Option.getOr(Dict.make()->JSON.Encode.object) let bodyDict = PaymentBody.applePayBody(~token, ~connectors) - processPayment(bodyDict, false) + processPayment(bodyDict, ()) } else if dict->Dict.get("showApplePayButton")->Option.isSome { setApplePayClicked(_ => false) if !isWallet { diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 83b361856..550573ca3 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -66,7 +66,7 @@ let make = ( ->Option.getOr(false) }, [thirdPartySessionObj]) - let processPayment = (body: array<(string, JSON.t)>, isThirdPartyFlow) => { + let processPayment = (body: array<(string, JSON.t)>, ~isThirdPartyFlow=false, ()) => { intent( ~bodyArr=body, ~confirmParam={ @@ -104,7 +104,7 @@ let make = ( ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict } - processPayment(body, false) + processPayment(body, ()) } if dict->Dict.get("gpayError")->Option.isSome { Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) @@ -158,7 +158,7 @@ let make = ( ("iframeId", iframeId->JSON.Encode.string), ]) let bodyDict = PaymentBody.gPayThirdPartySdkBody(~connectors) - processPayment(bodyDict, true) + processPayment(bodyDict, ~isThirdPartyFlow=true, ()) } else { handlePostMessage([ ("fullscreen", true->JSON.Encode.bool), @@ -169,7 +169,7 @@ let make = ( } } else { let bodyDict = PaymentBody.gpayRedirectBody(~connectors) - processPayment(bodyDict, false) + processPayment(bodyDict, ()) } } resolve()