Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apple pay debugging #333

Merged
merged 7 commits into from
Apr 25, 2024
35 changes: 28 additions & 7 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -141,16 +151,24 @@ let make = (
Window.querySelectorAll(`script[src="https://test-tpgw.trustpay.eu/js/v1.js"]`)->Array.length === 0
) {
let trustPayScriptURL =
publishableKey->String.startsWith("pk_prd_")
publishableKey->String.startsWith("pk_prd_")->not
vsrivatsa-edinburgh marked this conversation as resolved.
Show resolved Hide resolved
? "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
Expand Down Expand Up @@ -619,6 +637,9 @@ let make = (

try {
let trustpay = trustPayApi(secrets)
Window.window->alert(
"trustpay: " ++ trustpay->anyTypeToJson->JSON.stringify,
)
trustpay.finishApplePaymentV2(payment, paymentRequest)
->then(res => {
Window.window->alert(
Expand Down
Loading