Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/bundle.js

Large diffs are not rendered by default.

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": "@juspay-tech/react-hyper-js",
"version": "2.11.0",
"version": "2.12.0",
"main": "dist/bundle.js",
"files": [
"dist/",
Expand Down
39 changes: 22 additions & 17 deletions src/OrcaJs.bs.js

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

35 changes: 19 additions & 16 deletions src/OrcaJs.res
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,25 @@ type paymentElement = {
focus: unit => unit,
clear: unit => unit,
onSDKHandleClick: (unit => Promise.t<unit>) => unit,
confirmPayment: JSON.t => Promise.t<JSON.t>,
}

let makeErrorResponse = (code: string, message: string): JSON.t => {
let errorDict = Dict.make()
errorDict->Dict.set("code", code->JSON.Encode.string)
errorDict->Dict.set("message", message->JSON.Encode.string)
let resultDict = Dict.make()
resultDict->Dict.set("status", "error"->JSON.Encode.string)
resultDict->Dict.set("error", errorDict->JSON.Encode.object)
resultDict->JSON.Encode.object
}

let sdkNotReadyError = (): JSON.t =>
makeErrorResponse(
"sdk_not_ready",
"Hyper is not initialized yet — the card form is not ready",
)

let defaultPaymentElement = {
on: (_str, _func) => (),
collapse: () => (),
Expand All @@ -40,6 +58,7 @@ let defaultPaymentElement = {
focus: () => (),
clear: () => (),
onSDKHandleClick: _ => (),
confirmPayment: _ => Promise.resolve(sdkNotReadyError()),
}

type fieldHandle = {
Expand Down Expand Up @@ -181,22 +200,6 @@ type cardFieldProps = {
onBlur: option<JSON.t => unit>,
}

let makeErrorResponse = (code: string, message: string): JSON.t => {
let errorDict = Dict.make()
errorDict->Dict.set("code", code->JSON.Encode.string)
errorDict->Dict.set("message", message->JSON.Encode.string)
let resultDict = Dict.make()
resultDict->Dict.set("status", "error"->JSON.Encode.string)
resultDict->Dict.set("error", errorDict->JSON.Encode.object)
resultDict->JSON.Encode.object
}

let sdkNotReadyError = (): JSON.t =>
makeErrorResponse(
"sdk_not_ready",
"Hyper is not initialized yet — the card form is not ready",
)

let unsupportedOnSurfaceError = (~method: string, ~surface: string, ~alternative: string): JSON.t =>
makeErrorResponse(
"unsupported_on_surface",
Expand Down
35 changes: 34 additions & 1 deletion src/Utils.bs.js

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

22 changes: 22 additions & 0 deletions src/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,25 @@
// a plain JSON object (backward compat) or a Promise<JSON> (new pattern).

let normalizeToPromise = (options: JSON.t): Promise.t<JSON.t> => Promise.resolve(options)

@val @scope("crypto") external randomUUID: unit => string = "randomUUID"

let useWidgetId = id => {
let generated = React.useRef("")
let (generatedId, setGeneratedId) = React.useState(() => "")
// Keep server output and the first client render identical. Generate the ID
// after hydration; callers wait for it before mounting the browser widget.
React.useEffect1(() => {
if id === "" {
if generated.current === "" {
let uniqueId = try randomUUID() catch {
| _ => Js.Math.random()->Js.Float.toString->Js.String2.replace(".", "")
}
generated.current = `widget-${uniqueId}`
}
setGeneratedId(_ => generated.current)
}
None
}, [id])
id === "" ? generatedId : id
}
88 changes: 68 additions & 20 deletions src/components/PaymentElementsWrapper.bs.js

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

Loading
Loading