Skip to content

Commit

Permalink
Merge branch 'master' of ssh://ssh.bitbucket.juspay.net/exc/orca-elem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
arun.mishra committed Sep 12, 2023
2 parents 2ac5118 + ca56bd6 commit bcf2ca9
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/Components/PaymentField.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let make = (
}
let floatinglabelClass = inputFocused ? "Label--floating" : "Label--resting"
let getClassName = initialLabel => {
if value.value->Js.String.length == 0 {
if value.value->Js.String2.length == 0 {
`${initialLabel}--empty`
} else {
switch value.isValid {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/PaymentInputField.res
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let make = (
}
let floatinglabelClass = inputFocused ? "Label--floating" : "Label--resting"
let getClassName = initialLabel => {
if value->Js.String.length == 0 {
if value->Js.String2.length == 0 {
`${initialLabel}--empty`
} else {
switch isValid {
Expand Down
2 changes: 1 addition & 1 deletion src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ let make = (
->Js.Json.object_
->Js.Json.stringify,
~eventName=PAYMENT_METHOD_CHANGED,
~paymentMethod=selectedOption->Js.String.toUpperCase,
~paymentMethod=selectedOption->Js.String2.toUpperCase,
(),
)
}
Expand Down
1 change: 1 addition & 0 deletions src/Types/PaymentType.res
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ let itemToObjMapper = (dict, logger) => {
"terms",
"wallets",
"showCardFormByDefault",
"disableSaveCards",
],
dict,
"options",
Expand Down
10 changes: 6 additions & 4 deletions src/Utilities/LoggerUtils.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type logType = Response | NoResponse | Method | Err
type logType = Request | Response | NoResponse | Method | Err
let getLogtype = val => {
switch val {
| "request" => Request
| "response" => Response
| "no_response" => NoResponse
| "method" => Method
Expand All @@ -23,6 +24,7 @@ let logApi = (
) => {
let logtype = getLogtype(type_)
let value = switch logtype {
| Request => [("url", url->Js.Json.string)]
| Response => [
("url", url->Js.Json.string),
("statusCode", statusCode->Js.Json.string),
Expand All @@ -31,18 +33,18 @@ let logApi = (
| NoResponse => [
("url", url->Js.Json.string),
("statusCode", "504"->Js.Json.string),
("response", `{"error": "No Response from Server"}`->Js.Json.string),
("response", data),
]
| Err => [
("url", url->Js.Json.string),
("statusCode", statusCode->Js.Json.string),
("response", `{"error": "No Response from Server"}`->Js.Json.string),
("response", data),
]
| Method => [("method", paymentMethod->Js.Json.string), ("result", result)]
}
switch optLogger {
| Some(logger) =>
logger.setLogApi(~eventName, ~value=ArrayType(value), ~logType, ~logCategory, ())
logger.setLogApi(~eventName, ~value=ArrayType(value), ~logType, ~logCategory, ~type_, ())
logger.sendLogs()
| None => ()
}
Expand Down
148 changes: 136 additions & 12 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ let retrievePaymentIntent = (clientSecret, headers, ~optLogger) => {
let uri = `${ApiEndpoint.endpoint}/payments/${paymentIntentID}?client_secret=${clientSecret}`

//let headers = [("Accept", "application/json"), ("api-key", publishableKey)]
logApi(
~optLogger,
~url=uri,
~type_="request",
~eventName=RETRIEVE_CALL_INIT,
~logType=INFO,
~logCategory=API,
(),
)
fetchApi(uri, ~method_=Fetch.Get, ~headers=headers->addCustomPodHeader, ())
->then(res => {
let statusCode = res->Fetch.Response.status->string_of_int
Expand Down Expand Up @@ -104,8 +113,19 @@ let intentCall = (
~setIsManualRetryEnabled,
) => {
open Promise
let isConfirm = uri->Js.String.includes("/confirm")
let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL
let isConfirm = uri->Js.String2.includes("/confirm")
let (eventName: OrcaLogger.eventName, initEventName: OrcaLogger.eventName) = isConfirm
? (CONFIRM_CALL, CONFIRM_CALL_INIT)
: (RETRIEVE_CALL, RETRIEVE_CALL_INIT)
logApi(
~optLogger,
~url=uri,
~type_="request",
~eventName=initEventName,
~logType=INFO,
~logCategory=API,
(),
)
fetchApi(uri, ~method_=fetchMethod, ~headers=headers->addCustomPodHeader, ~bodyStr, ())
->then(res => {
let statusCode = res->Fetch.Response.status->string_of_int
Expand Down Expand Up @@ -154,12 +174,19 @@ let intentCall = (
}
resolve()
})
->catch(_err => {
->catch(err => {
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
logApi(
~optLogger,
~url=uri,
~statusCode,
~type_="no_response",
~data=exceptionJson,
~eventName,
~logType=ERROR,
~logCategory=API,
Expand All @@ -179,12 +206,22 @@ let intentCall = (
->then(data => {
logApi(~optLogger, ~url=uri, ~statusCode, ~type_="response", ~eventName, ())
let intent = PaymentConfirmTypes.itemToObjMapper(data->getDictFromJson)
let paymentMethod = switch paymentType {
| Card => "CARD"
| _ => intent.payment_method_type
}

let url = urlSearch(confirmParam.return_url)
url.searchParams.set(. "payment_intent_client_secret", clientSecret)
url.searchParams.set(. "status", intent.status)
if intent.status == "requires_customer_action" {
if intent.nextAction.type_ == "redirect_to_url" {
handleLogging(
~optLogger,
~value=intent.nextAction.redirectToUrl,
~eventName=REDIRECTING_USER,
~paymentMethod,
)
openUrl(intent.nextAction.redirectToUrl)
} else if intent.nextAction.type_ == "display_bank_transfer_information" {
let metadata = switch intent.nextAction.bank_transfer_steps_and_charges_details {
Expand All @@ -194,6 +231,12 @@ let intentCall = (
let dict = deepCopyDict(metadata)
dict->Js.Dict.set("data", data)
dict->Js.Dict.set("url", url.href->Js.Json.string)
handleLogging(
~optLogger,
~value=dict->Js.Json.object_->Js.Json.stringify,
~eventName=DISPLAY_BANK_TRANSFER_INFO_PAGE,
~paymentMethod,
)
handlePostMessage([
("fullscreen", true->Js.Json.boolean),
("param", `${intent.payment_method_type}BankTransfer`->Js.Json.string),
Expand All @@ -215,12 +258,34 @@ let intentCall = (
("expiryTime", Js.Json.null),
("url", url.href->Js.Json.string),
]->Js.Dict.fromArray
handleLogging(
~optLogger,
~value=metaData->Js.Json.object_->Js.Json.stringify,
~eventName=DISPLAY_QR_CODE_INFO_PAGE,
~paymentMethod,
)
handlePostMessage([
("fullscreen", true->Js.Json.boolean),
("param", `qrData`->Js.Json.string),
("iframeId", iframeId->Js.Json.string),
("metadata", metaData->Js.Json.object_),
])
} else if intent.nextAction.type_ == "third_party_sdk_session_token" {
let session_token = switch intent.nextAction.session_token {
| Some(token) => token->Utils.getDictFromJson
| None => Js.Dict.empty()
}
let walletName = session_token->Utils.getString("wallet_name", "")
let message = switch walletName {
| "apple_pay" => [
("applePayButtonClicked", true->Js.Json.boolean),
("applePayPresent", session_token->toJson),
]
| "google_pay" => [("googlePayThirdPartyFlow", session_token->toJson)]
| _ => []
}

handlePostMessage(message)
} else {
postFailedSubmitResponse(
~errortype="confirm_payment_failed",
Expand Down Expand Up @@ -251,10 +316,6 @@ let intentCall = (
}
}
} else if intent.status != "" {
let paymentMethod = switch paymentType {
| Card => "CARD"
| _ => intent.payment_method_type
}
if intent.status === "succeeded" {
handleLogging(
~optLogger,
Expand Down Expand Up @@ -289,15 +350,22 @@ let intentCall = (
}
resolve()
})
->catch(_err => {
->catch(err => {
let url = urlSearch(confirmParam.return_url)
url.searchParams.set(. "payment_intent_client_secret", clientSecret)
url.searchParams.set(. "status", "failed")
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
logApi(
~optLogger,
~url=uri,
~eventName,
~type_="no_response",
~data=exceptionJson,
~logType=ERROR,
~logCategory=API,
(),
Expand Down Expand Up @@ -500,6 +568,15 @@ let useSessions = (
->Js.Dict.fromArray
->Js.Json.object_
let uri = `${endpoint}/payments/session_tokens`
logApi(
~optLogger,
~url=uri,
~type_="request",
~eventName=SESSIONS_CALL_INIT,
~logType=INFO,
~logCategory=API,
(),
)
fetchApi(
uri,
~method_=Fetch.Post,
Expand Down Expand Up @@ -544,14 +621,21 @@ let useSessions = (
->then(json => {
json->resolve
})
->catch(_e => {
->catch(err => {
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
logApi(
~optLogger,
~url=uri,
~type_="no_response",
~eventName=SESSIONS_CALL,
~logType=ERROR,
~logCategory=API,
~data=exceptionJson,
(),
)
Js.Dict.empty()->Js.Json.object_->resolve
Expand All @@ -564,6 +648,15 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => {
open Promise
let headers = [("Content-Type", "application/json"), ("api-key", publishableKey)]
let uri = `${endpoint}/account/payment_methods?client_secret=${clientSecret}`
logApi(
~optLogger=Some(logger),
~url=uri,
~type_="request",
~eventName=PAYMENT_METHODS_CALL_INIT,
~logType=INFO,
~logCategory=API,
(),
)
fetchApi(uri, ~method_=Fetch.Get, ~headers=headers->addCustomPodHeader, ())
->then(resp => {
let statusCode = resp->Fetch.Response.status->string_of_int
Expand Down Expand Up @@ -602,14 +695,21 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => {
->then(json => {
json->resolve
})
->catch(_e => {
->catch(err => {
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
logApi(
~optLogger=Some(logger),
~url=uri,
~type_="no_response",
~eventName=PAYMENT_METHODS_CALL,
~logType=ERROR,
~logCategory=API,
~data=exceptionJson,
(),
)
Js.Dict.empty()->Js.Json.object_->resolve
Expand All @@ -621,7 +721,15 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => {
let fetchApi = CommonHooks.useApiFetcher()
let headers = [("Content-Type", "application/json"), ("api-key", publishableKey)]
let uri = `${ApiEndpoint.endpoint}/customers/payment_methods?client_secret=${clientSecret}`

logApi(
~optLogger,
~url=uri,
~type_="request",
~eventName=CUSTOMER_PAYMENT_METHODS_CALL_INIT,
~logType=INFO,
~logCategory=API,
(),
)
fetchApi(uri, ~method_=Fetch.Get, ~headers=headers->ApiEndpoint.addCustomPodHeader, ())
->then(res => {
let statusCode = res->Fetch.Response.status->string_of_int
Expand Down Expand Up @@ -658,7 +766,23 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => {
res->Fetch.Response.json
})
->then(res => resolve(res))
->catch(e => {
->catch(err => {
let exceptionJson =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.flatMap(OrcaUtils.safeParseOpt)
->Belt.Option.getWithDefault(Js.Json.null)
logApi(
~optLogger,
~url=uri,
~type_="no_response",
~eventName=CUSTOMER_PAYMENT_METHODS_CALL,
~logType=ERROR,
~logCategory=API,
~data=exceptionJson,
(),
)
Js.Dict.empty()->Js.Json.object_->resolve
})
}
Expand Down
20 changes: 16 additions & 4 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,18 @@ let make = (
mountedIframeRef->Window.iframePostMessage(msg)
resolve()
})
->catch(_ => {
->catch(err => {
let exceptionMessage =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.getWithDefault("TrustPay GooglePay Error")
logger.setLogInfo(
~value="TrustPay GooglePay Error",
~value=exceptionMessage,
~eventName=GOOGLE_PAY_FLOW,
~paymentMethod="GOOGLE_PAY",
~logType=ERROR,
~logCategory=USER_ERROR,
(),
)
let msg = [("googlePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray
Expand Down Expand Up @@ -457,11 +464,16 @@ let make = (
mountedIframeRef->Window.iframePostMessage(msg)
resolve()
})
->catch(_ => {
->catch(err => {
let exceptionMessage =
err
->Js.Exn.asJsExn
->Belt.Option.flatMap(Js.Exn.message)
->Belt.Option.getWithDefault("TrustPay ApplePay Error")
logger.setLogInfo(
~value="TrustPay ApplePay Error",
~eventName=APPLE_PAY_FLOW,
~paymentMethod="APPLE_PAY",
~value=exceptionMessage,
(),
)
let msg =
Expand Down
Loading

0 comments on commit bcf2ca9

Please sign in to comment.