Skip to content

Commit

Permalink
Revert to older flow (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: arun.mishra <[email protected]>
  • Loading branch information
2 people authored and prafulkoppalkar committed Nov 16, 2023
1 parent 810e5de commit 092a1ee
Show file tree
Hide file tree
Showing 5 changed files with 527 additions and 653 deletions.
15 changes: 14 additions & 1 deletion src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
type props = {sessionObj: option<Js.Json.t>, list: PaymentMethodsRecord.list}

let default = (props: props) => {
let {publishableKey} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)
let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)
let setIsShowOrPayUsing = Recoil.useSetRecoilState(RecoilAtoms.isShowOrPayUsing)
let {publishableKey} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)
let (showApplePay, setShowApplePay) = React.useState(() => false)
let (showApplePayLoader, setShowApplePayLoader) = React.useState(() => false)
let intent = PaymentHelpers.usePaymentIntent(None, Applepay)
Expand Down Expand Up @@ -195,6 +196,12 @@ let default = (props: props) => {
}`

let onApplePayButtonClicked = () => {
loggerState.setLogInfo(
~value="Apple Pay Button Clicked",
~eventName=APPLE_PAY_FLOW,
~paymentMethod="APPLE_PAY",
(),
)
setApplePayClicked(_ => true)

if isInvokeSDKFlow {
Expand All @@ -220,6 +227,12 @@ let default = (props: props) => {
let bodyDict = PaymentBody.applePayRedirectBody(~connectors)
processPayment(bodyDict)
}
loggerState.setLogInfo(
~value="",
~eventName=PAYMENT_DATA_FILLED,
~paymentMethod="APPLE_PAY",
(),
)
}

React.useEffect0(() => {
Expand Down
150 changes: 75 additions & 75 deletions src/Payments/PreMountLoader.res
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
@react.component
let make = (~sessionId, ~publishableKey, ~clientSecret, ~endpoint) => {
open Utils
let logger = OrcaLogger.make(
~sessionId,
~source=Loader,
~merchantId=publishableKey,
~clientSecret,
(),
)
// open Utils
// let logger = OrcaLogger.make(
// ~sessionId,
// ~source=Loader,
// ~merchantId=publishableKey,
// ~clientSecret,
// (),
// )

let (
paymentMethodsResponse,
customerPaymentMethodsResponse,
sessionTokensResponse,
) = React.useMemo0(() => {
(
PaymentHelpers.usePaymentMethodList(
~clientSecret,
~publishableKey,
~logger,
~switchToCustomPod=false,
~endpoint,
),
PaymentHelpers.useCustomerDetails(
~clientSecret,
~publishableKey,
~optLogger=Some(logger),
~switchToCustomPod=false,
~endpoint,
),
PaymentHelpers.useSessions(
~clientSecret,
~publishableKey,
~optLogger=Some(logger),
~switchToCustomPod=false,
~endpoint,
(),
),
)
})
// // let (
// // paymentMethodsResponse,
// // customerPaymentMethodsResponse,
// // sessionTokensResponse,
// // ) = React.useMemo0(() => {
// // (
// // PaymentHelpers.usePaymentMethodList(
// // ~clientSecret,
// // ~publishableKey,
// // ~logger,
// // ~switchToCustomPod=false,
// // ~endpoint,
// // ),
// // PaymentHelpers.useCustomerDetails(
// // ~clientSecret,
// // ~publishableKey,
// // ~optLogger=Some(logger),
// // ~switchToCustomPod=false,
// // ~endpoint,
// // ),
// // PaymentHelpers.useSessions(
// // ~clientSecret,
// // ~publishableKey,
// // ~optLogger=Some(logger),
// // ~switchToCustomPod=false,
// // ~endpoint,
// // (),
// // ),
// // )
// // })

let sendPromiseData = (promise, key) => {
open Promise
promise
->then(res => {
handlePostMessage([("response", res), ("data", key->Js.Json.string)])
resolve()
})
->catch(_err => {
handlePostMessage([("response", Js.Json.null), ("data", key->Js.Json.string)])
resolve()
})
->ignore
}
// // let sendPromiseData = (promise, key) => {
// // open Promise
// // promise
// // ->then(res => {
// // handlePostMessage([("response", res), ("data", key->Js.Json.string)])
// // resolve()
// // })
// // ->catch(_err => {
// // handlePostMessage([("response", Js.Json.null), ("data", key->Js.Json.string)])
// // resolve()
// // })
// // ->ignore
// // }

React.useEffect0(() => {
let handle = (ev: Window.event) => {
let json = try {
ev.data->Js.Json.parseExn
} catch {
| _ => Js.Json.null
}
let dict = json->Utils.getDictFromJson
if dict->Js.Dict.get("sendPaymentMethodsResponse")->Belt.Option.isSome {
paymentMethodsResponse->sendPromiseData("payment_methods")
} else if dict->Js.Dict.get("sendCustomerPaymentMethodsResponse")->Belt.Option.isSome {
customerPaymentMethodsResponse->sendPromiseData("customer_payment_methods")
} else if dict->Js.Dict.get("sendSessionTokensResponse")->Belt.Option.isSome {
sessionTokensResponse->sendPromiseData("session_tokens")
}
}
Window.addEventListener("message", handle)
handlePostMessage([("preMountLoaderInitCallback", true->Js.Json.boolean)])
Some(
() => {
Window.removeEventListener("message", handle)
},
)
})
// // React.useEffect0(() => {
// // let handle = (ev: Window.event) => {
// // let json = try {
// // ev.data->Js.Json.parseExn
// // } catch {
// // | _ => Js.Json.null
// // }
// // let dict = json->Utils.getDictFromJson
// // if dict->Js.Dict.get("sendPaymentMethodsResponse")->Belt.Option.isSome {
// // paymentMethodsResponse->sendPromiseData("payment_methods")
// // } else if dict->Js.Dict.get("sendCustomerPaymentMethodsResponse")->Belt.Option.isSome {
// // customerPaymentMethodsResponse->sendPromiseData("customer_payment_methods")
// // } else if dict->Js.Dict.get("sendSessionTokensResponse")->Belt.Option.isSome {
// // sessionTokensResponse->sendPromiseData("session_tokens")
// // }
// // }
// // Window.addEventListener("message", handle)
// // handlePostMessage([("preMountLoaderInitCallback", true->Js.Json.boolean)])
// // Some(
// // () => {
// // Window.removeEventListener("message", handle)
// // },
// // )
// // })

React.null
}
8 changes: 1 addition & 7 deletions src/Payments/QRCodeDisplay.res
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ let make = () => {
paymentIntentId,
headers->Js.Dict.entries,
~optLogger=Some(logger),
~switchToCustomPod,
)
->then(res => {
Modal.close(setOpenModal)
Expand Down Expand Up @@ -80,12 +79,7 @@ let make = () => {

let closeModal = () => {
open Promise
PaymentHelpers.retrievePaymentIntent(
clientSecret,
headers,
~optLogger=Some(logger),
~switchToCustomPod,
)
PaymentHelpers.retrievePaymentIntent(clientSecret, headers, ~optLogger=Some(logger))
->then(json => {
let dict = json->Js.Json.decodeObject->Belt.Option.getWithDefault(Js.Dict.empty())
let status = dict->getString("status", "")
Expand Down
Loading

0 comments on commit 092a1ee

Please sign in to comment.