Skip to content

Commit

Permalink
Pull request #269: Fixed ApplePay button not rendering and ApplePay t…
Browse files Browse the repository at this point in the history
…ransaction not happening

Merge in EXC/orca-elements from fix/apple-pay to master

* commit '3ee7066f61e2c30f7ef757099393bf12bc744e37':
  Fixed ApplePay button not rendering and ApplePay transaction not happening
  • Loading branch information
ArushKapoorJuspay authored and arun.mishra committed Oct 16, 2023
2 parents 76dbcbc + 3ee7066 commit a41c49e
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,32 @@ let make = (
}
)

let handleApplePayMounted = (event: Types.event) => {
let json = event.data->eventToJson
let dict = json->getDictFromJson

if dict->Js.Dict.get("applePayMounted")->Belt.Option.isSome {
switch sessionForApplePay->Js.Nullable.toOption {
| Some(session) =>
if session.canMakePayments(.) {
let msg =
[("applePayCanMakePayments", true->Js.Json.boolean)]->Js.Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
} else {
Utils.logInfo(Js.log("CANNOT MAKE PAYMENT USING APPLE PAY"))
}

| None => ()
}
}
}

addSmartEventListener(
"message",
handleApplePayMessages.contents,
"onApplePayMessages",
)
addSmartEventListener("message", handleApplePayMounted, "onApplePayMount")
}
if componentType === "payment" && googlePayPresent->Belt.Option.isSome {
let dict = json->getDictFromJson
Expand Down Expand Up @@ -634,26 +655,6 @@ let make = (
->ignore
}

let handleApplePayMounted = (event: Types.event) => {
let json = event.data->eventToJson
let dict = json->getDictFromJson

if dict->Js.Dict.get("applePayMounted")->Belt.Option.isSome {
switch sessionForApplePay->Js.Nullable.toOption {
| Some(session) =>
if session.canMakePayments(.) {
let msg =
[("applePayCanMakePayments", true->Js.Json.boolean)]->Js.Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
} else {
Utils.logInfo(Js.log("CANNOT MAKE PAYMENT USING APPLE PAY"))
}

| None => ()
}
}
}

let handleGooglePayThirdPartyFlow = (event: Types.event) => {
let json = event.data->eventToJson
let dict = json->getDictFromJson
Expand Down Expand Up @@ -734,9 +735,7 @@ let make = (
| _ => ()
}
}
addSmartEventListener("message", handleApplePayMounted, "onApplePayMount")
addSmartEventListener("message", handleGooglePayThirdPartyFlow, "onGooglePayThirdParty")
Window.removeEventListener("message", handleApplePayMessages.contents)
}
let msg = [("sendSessionTokensResponse", true->Js.Json.boolean)]->Js.Dict.fromArray
addSmartEventListener("message", handleSessionTokensLoaded, "onSessionTokensLoaded")
Expand Down

0 comments on commit a41c49e

Please sign in to comment.