Skip to content

Commit

Permalink
Merge branch 'main' into phone-number-validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja authored Apr 25, 2024
2 parents 762e20f + 4c3df29 commit 32563dd
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 9 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## [0.45.2](https://github.com/juspay/hyperswitch-web/compare/v0.45.1...v0.45.2) (2024-04-24)


### Bug Fixes

* added breakpoints to debug ([1f754b6](https://github.com/juspay/hyperswitch-web/commit/1f754b6f4023709752ef892c0e2861d34aa4f2fe))

## [0.45.1](https://github.com/juspay/hyperswitch-web/compare/v0.45.0...v0.45.1) (2024-04-24)


### Bug Fixes

* priority array to include apple pay logs ([#332](https://github.com/juspay/hyperswitch-web/issues/332)) ([937248f](https://github.com/juspay/hyperswitch-web/commit/937248f8ff3507cd9b6ccef3fe56769456f6ccbe))

# [0.45.0](https://github.com/juspay/hyperswitch-web/compare/v0.44.1...v0.45.0) (2024-04-24)


### Features

* polling status for 3ds flow Part 1 ([#329](https://github.com/juspay/hyperswitch-web/issues/329)) ([bd499b7](https://github.com/juspay/hyperswitch-web/commit/bd499b70af9c79012cbe87f15d953b837dcbfe18))

## [0.44.1](https://github.com/juspay/hyperswitch-web/compare/v0.44.0...v0.44.1) (2024-04-19)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orca-payment-page",
"version": "0.44.1",
"version": "0.45.2",
"main": "index.js",
"private": true,
"dependencies": {
Expand Down
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
88 changes: 88 additions & 0 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,94 @@ let rec pollRetrievePaymentIntent = (
})
}

let retrieveStatus = (~headers, ~switchToCustomPod, pollID) => {
open Promise
let endpoint = ApiEndpoint.getApiEndPoint()
let uri = `${endpoint}/poll/status/${pollID}`
let logger = OrcaLogger.make()
logApi(
~optLogger=Some(logger),
~url=uri,
~apiLogType=Request,
~eventName=POLL_STATUS_INIT,
~logType=INFO,
~logCategory=API,
(),
)
fetchApi(
uri,
~method=#GET,
~headers=headers->ApiEndpoint.addCustomPodHeader(~switchToCustomPod, ()),
(),
)
->then(res => {
let statusCode = res->Fetch.Response.status->Int.toString
if statusCode->String.charAt(0) !== "2" {
res
->Fetch.Response.json
->then(data => {
logApi(
~optLogger=Some(logger),
~url=uri,
~data,
~statusCode,
~apiLogType=Err,
~eventName=POLL_STATUS_CALL,
~logType=ERROR,
~logCategory=API,
(),
)
JSON.Encode.null->resolve
})
} else {
logApi(
~optLogger=Some(logger),
~url=uri,
~statusCode,
~apiLogType=Response,
~eventName=POLL_STATUS_CALL,
~logType=INFO,
~logCategory=API,
(),
)
res->Fetch.Response.json
}
})
->catch(e => {
Console.log2("Unable to Poll status details because of ", e)
JSON.Encode.null->resolve
})
}

let rec pollStatus = (~headers, ~switchToCustomPod, ~pollId, ~interval, ~count) => {
open Promise
retrieveStatus(~headers, ~switchToCustomPod, pollId)
->then(json => {
let dict = json->JSON.Decode.object->Option.getOr(Dict.make())
let status = dict->getString("status", "")
Promise.make((resolve, _) => {
if status === "completed" {
resolve(json)
} else if !(count > 0) {
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
postFailedSubmitResponse(~errortype="server_error", ~message="Something went wrong") // redirect to return url
} else {
delay(interval)
->then(
_ => {
pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count=count - 1)
},
)
->ignore
}
})
})
->catch(e => {
Console.log2("Unable to retrieve payment due to following error", e)
pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count=count - 1)
})
}

let rec intentCall = (
~fetchApi: (
string,
Expand Down
86 changes: 81 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 @@ -423,9 +424,45 @@ let make = (
}
}

let handlePollStatusMessage = (ev: Types.event) => {
let eventDataObject = ev.data->anyTypeToJson
let headers = [("Content-Type", "application/json"), ("api-key", publishableKey)]
switch eventDataObject->getOptionalJsonFromJson("poll_status") {
| Some(val) => {
handlePostMessage([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", selectorString->JSON.Encode.string),
])
let dict = val->getDictFromJson
let pollId = dict->getString("poll_id", "")
let interval =
dict->getString("delay_in_secs", "")->Int.fromString->Option.getOr(1) * 1000
let count = dict->getString("frequency", "")->Int.fromString->Option.getOr(5)
let url = dict->getString("return_url_with_query_params", "")
PaymentHelpers.pollStatus(~headers, ~switchToCustomPod, ~pollId, ~interval, ~count)
->then(res => {
let dict = res->JSON.Decode.object->Option.getOr(Dict.make())
let status = dict->getString("status", "")
if status === "completed" {
Window.Location.replace(url)->ignore // retrive status
}->resolve
})
->catch(_e =>
postFailedSubmitResponse(
~errortype="Server_error",
~message="Something went Wrong",
)->resolve
)
->ignore
}
| None => ()
}
}

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 @@ -499,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 @@ -507,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 @@ -529,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 @@ -553,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 @@ -567,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 @@ -580,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 @@ -589,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 @@ -602,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
5 changes: 5 additions & 0 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type eventName =
| PAYMENT_METHODS_RESPONSE
| LOADER_CHANGED
| PAYMENT_SESSION_INITIATED
| POLL_STATUS_INIT
| POLL_STATUS_CALL

let eventNameToStrMapper = eventName => {
switch eventName {
Expand Down Expand Up @@ -126,6 +128,8 @@ let eventNameToStrMapper = eventName => {
| PAYMENT_METHODS_RESPONSE => "PAYMENT_METHODS_RESPONSE"
| LOADER_CHANGED => "LOADER_CHANGED"
| PAYMENT_SESSION_INITIATED => "PAYMENT_SESSION_INITIATED"
| POLL_STATUS_INIT => "POLL_STATUS_INIT"
| POLL_STATUS_CALL => "POLL_STATUS_CALL"
}
}

Expand Down Expand Up @@ -505,6 +509,7 @@ let make = (
SESSIONS_CALL,
RETRIEVE_CALL,
DISPLAY_THREE_DS_SDK,
APPLE_PAY_FLOW,
]
arrayOfLogs
->Array.find(log => {
Expand Down

0 comments on commit 32563dd

Please sign in to comment.