diff --git a/Hyperswitch-React-Demo-App/package.json b/Hyperswitch-React-Demo-App/package.json
index 475db9f9..1cf70312 100644
--- a/Hyperswitch-React-Demo-App/package.json
+++ b/Hyperswitch-React-Demo-App/package.json
@@ -4,7 +4,6 @@
"private": true,
"dependencies": {
"@juspay-tech/hyper-js": "^1.6.0",
- "@juspay-tech/hyperswitch-node": "^1.0.1",
"@juspay-tech/react-hyper-js": "^1.0.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
diff --git a/Hyperswitch-React-Demo-App/server.js b/Hyperswitch-React-Demo-App/server.js
index 514948ce..833639ae 100644
--- a/Hyperswitch-React-Demo-App/server.js
+++ b/Hyperswitch-React-Demo-App/server.js
@@ -2,14 +2,11 @@ const fetch = require("node-fetch");
const express = require("express");
const { resolve } = require("path");
const dotenv = require("dotenv");
-const hyper = require("@juspay-tech/hyperswitch-node");
dotenv.config({ path: "./.env" });
const app = express();
const PORT = 5252;
-const hyperswitch = hyper(process.env.HYPERSWITCH_SECRET_KEY);
-
function getUrl(envVar, selfHostedValue) {
return process.env[envVar] === selfHostedValue ? "" : process.env[envVar];
}
@@ -95,7 +92,7 @@ const paymentData = {
country_code: "+91",
},
},
-}
+};
const profileId = process.env.PROFILE_ID;
if (profileId) {
@@ -122,29 +119,25 @@ app.get("/create-payment-intent", async (_, res) => {
});
async function createPaymentIntent(request) {
- if (SERVER_URL) {
- const url =
- process.env.HYPERSWITCH_SERVER_URL_FOR_DEMO_APP ||
- process.env.HYPERSWITCH_SERVER_URL;
- const apiResponse = await fetch(`${url}/payments`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Accept: "application/json",
- "api-key": process.env.HYPERSWITCH_SECRET_KEY,
- },
- body: JSON.stringify(request),
- });
- const paymentIntent = await apiResponse.json();
+ const url =
+ process.env.HYPERSWITCH_SERVER_URL_FOR_DEMO_APP ||
+ process.env.HYPERSWITCH_SERVER_URL;
+ const apiResponse = await fetch(`${url}/payments`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ "api-key": process.env.HYPERSWITCH_SECRET_KEY,
+ },
+ body: JSON.stringify(request),
+ });
+ const paymentIntent = await apiResponse.json();
- if (paymentIntent.error) {
- console.error("Error - ", paymentIntent.error);
- throw new Error(paymentIntent?.error?.message ?? "Something went wrong.");
- }
- return paymentIntent;
- } else {
- return await hyperswitch?.paymentIntents?.create(request);
+ if (paymentIntent.error) {
+ console.error("Error - ", paymentIntent.error);
+ throw new Error(paymentIntent?.error?.message ?? "Something went wrong.");
}
+ return paymentIntent;
}
app.listen(PORT, () => {
diff --git a/src/App.res b/src/App.res
index b1ff9712..aab35134 100644
--- a/src/App.res
+++ b/src/App.res
@@ -57,7 +57,7 @@ let make = () => {
switch fullscreenMode {
| "paymentloader" =>
| "plaidSDK" =>
- | "pazeWallet" =>
+ | "pazeWallet" =>
| "fullscreen" =>
diff --git a/src/CardTheme.res b/src/CardTheme.res
index c5cd8eb1..ebbff5e5 100644
--- a/src/CardTheme.res
+++ b/src/CardTheme.res
@@ -97,6 +97,7 @@ let getLocaleObject = async string => {
| NL => Js.import(DutchLocale.localeStrings)
| SV => Js.import(SwedishLocale.localeStrings)
| RU => Js.import(RussianLocale.localeStrings)
+ | ZH_HANT => Js.import(TraditionalChineseLocale.localeStrings)
}
let awaitedLocaleValue = await promiseLocale
diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res
index 2ea74b97..7ec6ec08 100644
--- a/src/Payments/GPay.res
+++ b/src/Payments/GPay.res
@@ -190,7 +190,13 @@ let make = (
syncPayment()
}
} catch {
- | _ => logInfo(Console.log("Error in syncing GooglePay Payment"))
+ | err =>
+ loggerState.setLogError(
+ ~value="Error in syncing GooglePay Payment",
+ ~eventName=GOOGLE_PAY_FLOW,
+ ~internalMetadata=err->formatException->JSON.stringify,
+ ~paymentMethod="GOOGLE_PAY",
+ )
}
}
Window.addEventListener("message", handleGooglePayMessages)
diff --git a/src/Payments/PaypalSDK.res b/src/Payments/PaypalSDK.res
index 17852695..82abecc8 100644
--- a/src/Payments/PaypalSDK.res
+++ b/src/Payments/PaypalSDK.res
@@ -140,7 +140,13 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) =
}
}
} catch {
- | _err => Utils.logInfo(Console.log("Error loading Paypal"))
+ | err =>
+ loggerState.setLogError(
+ ~value="Error loading Paypal",
+ ~eventName=PAYPAL_SDK_FLOW,
+ ~internalMetadata=err->Utils.formatException->JSON.stringify,
+ ~paymentMethod="PAYPAL_SDK",
+ )
}
None
}, [stateJson])
diff --git a/src/Payments/PazeButton.res b/src/Payments/PazeButton.res
index 9fe799f0..4ffdfa63 100644
--- a/src/Payments/PazeButton.res
+++ b/src/Payments/PazeButton.res
@@ -16,6 +16,11 @@ let make = (~token: SessionsType.token) => {
let paymentIntentID = clientSecret->Option.getOr("")->getPaymentId
let (showLoader, setShowLoader) = React.useState(() => false)
let onClick = _ => {
+ loggerState.setLogInfo(
+ ~value="Paze SDK Button Clicked",
+ ~eventName=PAZE_SDK_FLOW,
+ ~paymentMethod="PAZE",
+ )
setShowLoader(_ => true)
let metadata =
[
diff --git a/src/Payments/PazeWallet.res b/src/Payments/PazeWallet.res
index 6f70bce8..e96fa21d 100644
--- a/src/Payments/PazeWallet.res
+++ b/src/Payments/PazeWallet.res
@@ -4,7 +4,7 @@ open PazeTypes
external digitalWalletSdk: digitalWalletSdk = "DIGITAL_WALLET_SDK"
@react.component
-let make = () => {
+let make = (~logger: HyperLogger.loggerMake) => {
open Promise
open Utils
@@ -97,7 +97,13 @@ let make = () => {
resolve()
} catch {
- | _ =>
+ | err =>
+ logger.setLogError(
+ ~value=err->formatException->JSON.stringify,
+ ~eventName=PAZE_SDK_FLOW,
+ ~paymentMethod="PAZE",
+ ~logType=ERROR,
+ )
messageParentWindow([
("fullscreen", false->JSON.Encode.bool),
("isPaze", true->JSON.Encode.bool),
@@ -107,14 +113,21 @@ let make = () => {
resolve()
}
}
-
+ logger.setLogInfo(~value="PAZE SDK Script Loading", ~eventName=PAZE_SDK_FLOW)
let pazeScript = Window.createElement("script")
pazeScript->Window.elementSrc(pazeScriptURL)
pazeScript->Window.elementOnerror(exn => {
- let err = exn->Identity.anyTypeToJson->JSON.stringify
- Console.log2("PAZE --- errrorrr", err)
+ logger.setLogError(
+ ~value=`Error During Loading PAZE SDK Script: ${exn
+ ->Identity.anyTypeToJson
+ ->JSON.stringify}`,
+ ~eventName=PAZE_SDK_FLOW,
+ )
+ })
+ pazeScript->Window.elementOnload(_ => {
+ logger.setLogInfo(~value="PAZE SDK Script Loaded", ~eventName=PAZE_SDK_FLOW)
+ loadPazeSDK()->ignore
})
- pazeScript->Window.elementOnload(_ => loadPazeSDK()->ignore)
Window.body->Window.appendChild(pazeScript)
}
diff --git a/src/Payments/PlaidSDKIframe.res b/src/Payments/PlaidSDKIframe.res
index 45b9c1b3..e69a3612 100644
--- a/src/Payments/PlaidSDKIframe.res
+++ b/src/Payments/PlaidSDKIframe.res
@@ -78,7 +78,13 @@ let make = () => {
}
messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
} catch {
- | e => logInfo(Console.log2("Retrieve Failed", e))
+ | err =>
+ logger.setLogError(
+ ~value="Retrieve failed via Plaid",
+ ~eventName=PLAID_SDK,
+ ~internalMetadata=err->formatException->JSON.stringify,
+ ~paymentMethod="PLAID",
+ )
}
}
diff --git a/src/Payments/SamsungPayComponent.res b/src/Payments/SamsungPayComponent.res
index 72560487..b31fee14 100644
--- a/src/Payments/SamsungPayComponent.res
+++ b/src/Payments/SamsungPayComponent.res
@@ -28,6 +28,11 @@ let make = (~sessionObj: option, ~walletOptions) => {
})
let onSamsungPaymentButtonClick = _ => {
+ loggerState.setLogInfo(
+ ~value="SamsungPay Button Clicked",
+ ~eventName=SAMSUNG_PAY,
+ ~paymentMethod="SAMSUNG_PAY",
+ )
SamsungPayHelpers.handleSamsungPayClicked(
~sessionObj=sessionObj->Option.getOr(JSON.Encode.null)->getDictFromJson,
~componentName,
diff --git a/src/Utilities/ApplePayHelpers.res b/src/Utilities/ApplePayHelpers.res
index 3a342cac..cee2cef9 100644
--- a/src/Utilities/ApplePayHelpers.res
+++ b/src/Utilities/ApplePayHelpers.res
@@ -189,10 +189,9 @@ let startApplePaySession = (
let payment = event.payment
payment->callBackFunc
}
- ssn.oncancel = _ev => {
+ ssn.oncancel = _ => {
applePaySessionRef := Nullable.null
- logInfo(Console.log("Apple Pay Payment Cancelled"))
- logger.setLogInfo(
+ logger.setLogError(
~value="Apple Pay Payment Cancelled",
~eventName=APPLE_PAY_FLOW,
~paymentMethod="APPLE_PAY",
@@ -218,6 +217,7 @@ let useHandleApplePayResponse = (
let options = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let {publishableKey} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
+ let logger = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)
let (stateJson, setStatesJson) = React.useState(_ => JSON.Encode.null)
@@ -279,7 +279,13 @@ let useHandleApplePayResponse = (
syncPayment()
}
} catch {
- | _ => logInfo(Console.log("Error in parsing Apple Pay Data"))
+ | err =>
+ logger.setLogError(
+ ~value="Error in parsing Apple Pay Data",
+ ~eventName=APPLE_PAY_FLOW,
+ ~paymentMethod="APPLE_PAY",
+ ~internalMetadata=err->formatException->JSON.stringify,
+ )
}
}
Window.addEventListener("message", handleApplePayMessages)
diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res
index b5241366..c2c0cd32 100644
--- a/src/Utilities/Utils.res
+++ b/src/Utilities/Utils.res
@@ -764,10 +764,6 @@ let snakeToTitleCase = str => {
->Array.joinWith(" ")
}
-let logInfo = log => {
- Window.isProd ? () : log
-}
-
let formatIBAN = iban => {
let formatted = iban->String.replaceRegExp(%re(`/[^a-zA-Z0-9]/g`), "")
let countryCode = formatted->String.substring(~start=0, ~end=2)->String.toUpperCase
diff --git a/src/hyper-loader/Elements.res b/src/hyper-loader/Elements.res
index c32755c6..911290ff 100644
--- a/src/hyper-loader/Elements.res
+++ b/src/hyper-loader/Elements.res
@@ -182,7 +182,11 @@ let make = (
logger.setLogInfo(~value="TrustPay Script Loading", ~eventName=TRUSTPAY_SCRIPT)
trustPayScript->Window.elementSrc(trustPayScriptURL)
trustPayScript->Window.elementOnerror(err => {
- logInfo(Console.log2("ERROR DURING LOADING TRUSTPAY APPLE PAY", err))
+ logger.setLogError(
+ ~value="ERROR DURING LOADING TRUSTPAY APPLE PAY",
+ ~eventName=TRUSTPAY_SCRIPT,
+ ~internalMetadata=err->formatException->JSON.stringify,
+ )
})
trustPayScript->Window.elementOnload(_ => {
logger.setLogInfo(~value="TrustPay Script Loaded", ~eventName=TRUSTPAY_SCRIPT)
@@ -1173,7 +1177,15 @@ let make = (
mountedIframeRef->Window.iframePostMessage(msg)
resolve()
})
- ->catch(_ => resolve())
+ ->catch(err => {
+ logger.setLogError(
+ ~value=`SAMSUNG PAY not ready ${err->formatException->JSON.stringify}`,
+ ~eventName=SAMSUNG_PAY,
+ ~paymentMethod="SAMSUNG_PAY",
+ ~logType=ERROR,
+ )
+ resolve()
+ })
->ignore
let handleSamsungPayMessages = (event: Types.event) => {
@@ -1196,6 +1208,14 @@ let make = (
resolve()
})
->catch(err => {
+ logger.setLogError(
+ ~value=`SAMSUNG PAY Initialization fail ${err
+ ->formatException
+ ->JSON.stringify}`,
+ ~eventName=SAMSUNG_PAY,
+ ~paymentMethod="SAMSUNG_PAY",
+ ~logType=ERROR,
+ )
event.source->Window.sendPostMessage(
[("samsungPayError", err->anyTypeToJson)]->Dict.fromArray,
)
@@ -1210,8 +1230,22 @@ let make = (
"onSamsungPayMessages",
)
} catch {
- | _ => Console.log("Error loading Samsung Pay")
+ | err =>
+ logger.setLogError(
+ ~value=`SAMSUNG PAY Not Ready - ${err->formatException->JSON.stringify}`,
+ ~eventName=SAMSUNG_PAY,
+ ~paymentMethod="SAMSUNG_PAY",
+ ~logType=ERROR,
+ )
+ Console.log("Error loading Samsung Pay")
}
+ } else if wallets.samsungPay === Never {
+ logger.setLogInfo(
+ ~value="SAMSUNG PAY is set as never by merchant",
+ ~eventName=SAMSUNG_PAY,
+ ~paymentMethod="SAMSUNG_PAY",
+ ~logType=INFO,
+ )
}
json->resolve
diff --git a/src/hyper-loader/Hyper.res b/src/hyper-loader/Hyper.res
index e712c61d..f8750ac6 100644
--- a/src/hyper-loader/Hyper.res
+++ b/src/hyper-loader/Hyper.res
@@ -139,26 +139,25 @@ let make = (publishableKey, options: option, analyticsInfo: optionOption.getOr(JSON.Encode.null)
- ->Utils.getDictFromJson
- ->Utils.getBool("isPreloadEnabled", true)
+ ->getDictFromJson
+ ->getBool("isPreloadEnabled", true)
let shouldUseTopRedirection =
options
->Option.getOr(JSON.Encode.null)
- ->Utils.getDictFromJson
- ->Utils.getBool("shouldUseTopRedirection", false)
+ ->getDictFromJson
+ ->getBool("shouldUseTopRedirection", false)
let analyticsMetadata =
options
->Option.getOr(JSON.Encode.null)
- ->Utils.getDictFromJson
- ->Utils.getDictFromObj("analytics")
- ->Utils.getJsonObjectFromDict("metadata")
+ ->getDictFromJson
+ ->getDictFromObj("analytics")
+ ->getJsonObjectFromDict("metadata")
if isPreloadEnabled {
preloader()
}
let analyticsInfoDict =
analyticsInfo->Option.flatMap(JSON.Decode.object)->Option.getOr(Dict.make())
- let sessionID =
- analyticsInfoDict->getString("sessionID", "hyp_" ++ Utils.generateRandomString(8))
+ let sessionID = analyticsInfoDict->getString("sessionID", "hyp_" ++ generateRandomString(8))
let sdkTimestamp = analyticsInfoDict->getString("timeStamp", Date.now()->Float.toString)
let logger = HyperLogger.make(
~sessionId=sessionID,
@@ -266,7 +265,12 @@ let make = (publishableKey, options: option, analyticsInfo: optionWindow.elementSrc(googlePayScriptURL)
googlePayScript->Window.elementOnerror(err => {
- Utils.logInfo(Console.log2("ERROR DURING LOADING GOOGLE PAY SCRIPT", err))
+ logger.setLogError(
+ ~value="ERROR DURING LOADING GOOGLE PAY SCRIPT",
+ ~eventName=GOOGLE_PAY_SCRIPT,
+ ~internalMetadata=err->formatException->JSON.stringify,
+ ~paymentMethod="GOOGLE_PAY",
+ )
})
Window.body->Window.appendChild(googlePayScript)
logger.setLogInfo(~value="GooglePay Script Loaded", ~eventName=GOOGLE_PAY_SCRIPT)
@@ -279,9 +283,17 @@ let make = (publishableKey, options: option, analyticsInfo: optionWindow.elementSrc(samsungPayScriptUrl)
samsungPayScript->Window.elementOnerror(err => {
- Console.log2("ERROR LOADING SAMSUNG PAY SCRIPT", err)
+ logger.setLogError(
+ ~value="ERROR DURING LOADING SAMSUNG PAY SCRIPT",
+ ~eventName=SAMSUNG_PAY_SCRIPT,
+ ~internalMetadata=err->formatException->JSON.stringify,
+ ~paymentMethod="SAMSUNG_PAY",
+ )
})
Window.body->Window.appendChild(samsungPayScript)
+ samsungPayScript->Window.elementOnload(_ =>
+ logger.setLogInfo(~value="SamsungPay Script Loaded", ~eventName=SAMSUNG_PAY_SCRIPT)
+ )
}
let iframeRef = ref([])
diff --git a/src/hyper-log-catcher/HyperLogger.res b/src/hyper-log-catcher/HyperLogger.res
index 715ed560..a0f5851f 100644
--- a/src/hyper-log-catcher/HyperLogger.res
+++ b/src/hyper-log-catcher/HyperLogger.res
@@ -86,6 +86,9 @@ type eventName =
| EXTERNAL_TAX_CALCULATION
| POST_SESSION_TOKENS_CALL
| POST_SESSION_TOKENS_CALL_INIT
+ | PAZE_SDK_FLOW
+ | SAMSUNG_PAY_SCRIPT
+ | SAMSUNG_PAY
let eventNameToStrMapper = (eventName: eventName) => (eventName :> string)
@@ -104,9 +107,6 @@ let toSnakeCaseWithSeparator = (str, separator) => {
type maskableDetails = Email | CardDetails
type source = Loader | Elements(CardThemeType.mode) | Headless
-let logInfo = log => {
- Window.isProd ? () : log
-}
type logFile = {
timestamp: string,