Skip to content

Commit

Permalink
fix: added breakpoints to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrishab Srivatsa authored and prafulkoppalkar committed Apr 24, 2024
1 parent 9d7e8ea commit 1f754b6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ let make = (
postFailedSubmitResponse(~errortype="server_error", ~message="Something went wrong")
}
} else if dict->Dict.get("applePaySyncPayment")->Option.isSome {
syncPayment()
()
// syncPayment(breakpoint)
}
} catch {
| _ => Utils.logInfo(Console.log("Error in parsing Apple Pay Data"))
Expand Down
49 changes: 44 additions & 5 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open Identity
open Utils
open EventListenerManager
open ApplePayTypes
@send external alert: ('t, string) => unit = "alert"

type trustPayFunctions = {
finishApplePaymentV2: (string, paymentRequestData) => Promise.t<JSON.t>,
Expand Down Expand Up @@ -462,7 +463,6 @@ let make = (
addSmartEventListener("message", handleApplePayMounted, "onApplePayMount")
addSmartEventListener("message", handlePollStatusMessage, "onPollStatusMsg")
addSmartEventListener("message", handleGooglePayThirdPartyFlow, "onGooglePayThirdParty")
Window.removeEventListener("message", handleApplePayMessages.contents)

let fetchSessionTokens = mountedIframeRef => {
let handleSessionTokensLoaded = (event: Types.event) => {
Expand Down Expand Up @@ -536,6 +536,11 @@ let make = (
->JSON.Decode.bool
->Belt.Option.getWithDefault(false)

Window.window->alert(
"isDelayedSessionToken: " ++
isDelayedSessionToken->anyTypeToJson->JSON.stringify,
)

if isDelayedSessionToken {
logger.setLogInfo(
~value="Delayed Session Token Flow",
Expand All @@ -544,19 +549,28 @@ let make = (
(),
)

let applePayPresent =
let applePaySessionTokenData =
dict
->Dict.get("applePayPresent")
->Belt.Option.flatMap(JSON.Decode.object)
->Belt.Option.getWithDefault(Dict.make())

Window.window->alert(
"applePaySessionTokenData: " ++
applePaySessionTokenData->anyTypeToJson->JSON.stringify,
)

let connector =
applePayPresent
applePaySessionTokenData
->Dict.get("connector")
->Belt.Option.getWithDefault(JSON.Encode.null)
->JSON.Decode.string
->Belt.Option.getWithDefault("")

Window.window->alert(
"connector: " ++ connector->anyTypeToJson->JSON.stringify,
)

switch connector {
| "trustpay" =>
logger.setLogInfo(
Expand All @@ -566,21 +580,30 @@ let make = (
(),
)
let secrets =
applePayPresent
applePaySessionTokenData
->Dict.get("session_token_data")
->Belt.Option.getWithDefault(JSON.Encode.null)
->JSON.Decode.object
->Belt.Option.getWithDefault(Dict.make())
->Dict.get("secrets")
->Belt.Option.getWithDefault(JSON.Encode.null)

Window.window->alert(
"secrets: " ++ secrets->anyTypeToJson->JSON.stringify,
)

let paymentRequest =
applePayPresent
applePaySessionTokenData
->Dict.get("payment_request_data")
->Belt.Option.flatMap(JSON.Decode.object)
->Belt.Option.getWithDefault(Dict.make())
->ApplePayTypes.jsonToPaymentRequestDataType

Window.window->alert(
"paymentRequest: " ++
paymentRequest->anyTypeToJson->JSON.stringify,
)

let payment =
secrets
->JSON.Decode.object
Expand All @@ -590,10 +613,17 @@ let make = (
->JSON.Decode.string
->Belt.Option.getWithDefault("")

Window.window->alert(
"payment: " ++ payment->anyTypeToJson->JSON.stringify,
)

try {
let trustpay = trustPayApi(secrets)
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,
Expand All @@ -604,6 +634,7 @@ let make = (
let msg =
[
("applePaySyncPayment", true->JSON.Encode.bool),
("breakpoint", "1"->JSON.Encode.string),
]->Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
logger.setLogInfo(
Expand All @@ -617,6 +648,9 @@ let make = (
->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",
Expand All @@ -626,6 +660,7 @@ let make = (
let msg =
[
("applePaySyncPayment", true->JSON.Encode.bool),
("breakpoint", "2"->JSON.Encode.string),
]->Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
resolve()
Expand All @@ -639,9 +674,13 @@ let make = (
~paymentMethod="APPLE_PAY",
(),
)
Window.window->alert(
"exn: " ++ exn->Utils.formatException->JSON.stringify,
)
let msg =
[
("applePaySyncPayment", true->JSON.Encode.bool),
("breakpoint", "3"->JSON.Encode.string),
]->Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
}
Expand Down

0 comments on commit 1f754b6

Please sign in to comment.