@sunbay/checkout-sdk-react 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +166 -2
- package/dist/index.cjs +629 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +107 -0
- package/dist/index.d.ts +107 -0
- package/dist/index.mjs +581 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/CheckoutProvider.tsx","../src/context.ts","../src/internal/env.ts","../src/internal/parity.ts","../src/internal/structuralEqual.ts","../src/hooks/useCheckout.ts","../src/hooks/useCheckoutEvent.ts","../src/elements/createElementComponent.tsx","../src/elements/updatableOptions.ts","../src/elements/index.tsx","../src/hooks/useConfirm.ts"],"sourcesContent":["/**\n * @sunbay/checkout-sdk-react public entry.\n */\n\n/**\n * Package version. Injected at build time by tsup's `define` from `package.json` as\n * `__SDK_VERSION__` (see tsup.config.ts). Environments without a build (e.g. vitest running\n * src directly) fall back to `'0.0.0'`.\n */\ndeclare const __SDK_VERSION__: string;\nexport const version: string =\n typeof __SDK_VERSION__ !== 'undefined' ? __SDK_VERSION__ : '0.0.0';\n\nexport { CheckoutProvider } from './CheckoutProvider';\nexport type { CheckoutProviderProps, CheckoutProviderOptions } from './CheckoutProvider';\nexport type { CheckoutStatus } from './context';\nexport { useCheckout } from './hooks/useCheckout';\nexport type { UseCheckoutResult } from './hooks/useCheckout';\nexport { useCheckoutEvent } from './hooks/useCheckoutEvent';\nexport type { InstanceEventName } from './hooks/useCheckoutEvent';\nexport {\n CardElement,\n CardNumberElement,\n CardExpiryElement,\n CardCvcElement,\n AddressElement,\n ExpressCheckoutElement,\n} from './elements';\nexport type {\n CardElementProps,\n CardNumberElementProps,\n CardExpiryElementProps,\n CardCvcElementProps,\n AddressElementProps,\n ExpressCheckoutElementProps,\n} from './elements';\nexport type { ElementProps } from './elements/createElementComponent';\nexport { useConfirm } from './hooks/useConfirm';\nexport type { UseConfirmResult } from './hooks/useConfirm';\n\n// Re-exports from `@sunbay/checkout-sdk-js` so merchants need only this package's types.\n// `createCheckout`, the handle classes and js transport internals are intentionally omitted.\nexport { ErrorCode, WARNING_CODES } from '@sunbay/checkout-sdk-js';\nexport type {\n CheckoutInstance,\n CheckoutElement,\n ConfirmOptions,\n MountOptions,\n CreateCheckoutOptions,\n Env,\n ErrorCodeValue,\n CheckoutError,\n CheckoutErrorCategory,\n PaymentOutcome,\n PublicSessionView,\n PublicPaymentMethod,\n ExpressMethodView,\n PaymentMethodsView,\n ElementState,\n PublicProductLine,\n PaymentMethod,\n PaymentMethodFilter,\n Appearance,\n AddressInfo,\n TxnStatus,\n SessionStatus,\n ElementType,\n ElementOptions,\n ElementStatus,\n CardElementOptions,\n CardOnFileOptions,\n CardFieldElementOptions,\n AddressElementOptions,\n AddressFormStyle,\n ExpressCheckoutElementOptions,\n AvailableWallets,\n ApplePayOptions,\n GooglePayOptions,\n ApplePayButtonTheme,\n GooglePayButtonTheme,\n ApplePayButtonType,\n GooglePayButtonType,\n PaymentAction,\n WalletErrorStage,\n EventName,\n EventPayloadMap,\n ErrorEvent,\n WarningEvent,\n WarningCode,\n PaymentResultEvent,\n PaymentStateChangeEvent,\n ExpressAvailabilityChangeEvent,\n ElementReadyEvent,\n ChangeEvent,\n LoadErrorEvent,\n ReadyEvent,\n FocusEvent,\n BlurEvent,\n AppearanceVariables,\n AppearanceRuleTarget,\n AppearanceRuleStyle,\n} from '@sunbay/checkout-sdk-js';\n","/** @jsxRuntime classic */\n/** @jsx React.createElement */\n/** @jsxFrag React.Fragment */\nimport * as React from 'react';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport type { ReactElement, ReactNode } from 'react';\nimport { createCheckout, ErrorCode } from '@sunbay/checkout-sdk-js';\nimport type {\n CheckoutError,\n CheckoutInstance,\n CreateCheckoutOptions,\n WarningEvent,\n} from '@sunbay/checkout-sdk-js';\nimport { CheckoutContext } from './context';\nimport type { CheckoutContextValue, CheckoutStatus } from './context';\nimport { isDevelopment } from './internal/env';\nimport { IDENTITY_KEYS, UPDATABLE_KEYS } from './internal/parity';\nimport type { UpdatableKey } from './internal/parity';\nimport { structuralEqual } from './internal/structuralEqual';\n\n/** Options accepted by the Provider: everything `createCheckout` takes except internals. */\nexport type CheckoutProviderOptions = Omit<CreateCheckoutOptions, 'signal' | '__transportFactory'>;\n\nexport interface CheckoutProviderProps {\n options: CheckoutProviderOptions;\n /** Called once when creating the checkout fails (never for cancellation). */\n onError?: (error: CheckoutError) => void;\n /** Called for every checkout warning (including those raised during initialize). */\n onWarning?: (warning: WarningEvent) => void;\n children?: ReactNode;\n}\n\ntype WarningHandler = (w: WarningEvent) => void;\n\ninterface WarningRecord {\n buffer: WarningEvent[];\n delivered: WeakMap<WarningHandler, number>;\n}\n\ninterface ProviderState {\n /** Identity generation (a number, so React state and DevTools never hold a secret). */\n key: number;\n checkout: CheckoutInstance | null;\n status: CheckoutStatus;\n error: CheckoutError | null;\n}\n\ntype UpdateKey = UpdatableKey;\n\nfunction identityValues(o: CheckoutProviderOptions): unknown[] {\n return IDENTITY_KEYS.map((k) => o[k] ?? null);\n}\n\nfunction pickUpdatable(o: CheckoutProviderOptions): Partial<Pick<CheckoutProviderOptions, UpdateKey>> {\n const picked: Record<string, unknown> = {};\n UPDATABLE_KEYS.forEach((k) => {\n picked[k] = o[k];\n });\n return picked as Partial<Pick<CheckoutProviderOptions, UpdateKey>>;\n}\n\n/**\n * Creates a checkout instance for the given options and shares it with the tree below.\n */\nexport function CheckoutProvider(props: CheckoutProviderProps): ReactElement {\n const { options, children } = props;\n // The identity values (which include secrets) stay in a ref and are only compared; state and\n // effect dependencies carry a generation number that changes when the identity changes.\n const identityRef = useRef<{ values: unknown[]; generation: number } | null>(null);\n const values = identityValues(options);\n if (identityRef.current === null) {\n identityRef.current = { values, generation: 0 };\n } else if (!structuralEqual(identityRef.current.values, values)) {\n identityRef.current = { values, generation: identityRef.current.generation + 1 };\n }\n const key = identityRef.current.generation;\n\n const [state, setState] = useState<ProviderState>({\n key,\n checkout: null,\n status: 'loading',\n error: null,\n });\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const onErrorRef = useRef(props.onError);\n onErrorRef.current = props.onError;\n const onWarningRef = useRef(props.onWarning);\n onWarningRef.current = props.onWarning;\n\n const appliedRef = useRef<Partial<Pick<CheckoutProviderOptions, UpdateKey>>>(\n pickUpdatable(options),\n );\n const destroyedRef = useRef<WeakSet<CheckoutInstance>>(new WeakSet());\n const subscribersRef = useRef<Set<WarningHandler>>(new Set());\n const recordRef = useRef<WarningRecord>({ buffer: [], delivered: new WeakMap() });\n\n const deliver = useCallback((handler: WarningHandler) => {\n const record = recordRef.current;\n let index = record.delivered.get(handler) ?? 0;\n while (index < record.buffer.length) {\n const w = record.buffer[index];\n index += 1;\n record.delivered.set(handler, index);\n handler(w);\n }\n }, []);\n\n const subscribeWarning = useCallback(\n (handler: WarningHandler) => {\n subscribersRef.current.add(handler);\n deliver(handler);\n return () => {\n subscribersRef.current.delete(handler);\n };\n },\n [deliver],\n );\n\n // The `onWarning` prop is an ordinary subscriber (latest closure through a ref).\n useEffect(() => {\n const forward: WarningHandler = (w) => onWarningRef.current?.(w);\n return subscribeWarning(forward);\n }, [subscribeWarning]);\n\n // Identity effect: one AbortController per run.\n useEffect(() => {\n const controller = new AbortController();\n let cancelled = false;\n let instance: CheckoutInstance | null = null;\n const record: WarningRecord = { buffer: [], delivered: new WeakMap() };\n recordRef.current = record;\n appliedRef.current = pickUpdatable(optionsRef.current);\n\n const onInstanceWarning: WarningHandler = (w) => {\n record.buffer.push(w);\n subscribersRef.current.forEach((h) => deliver(h));\n };\n\n setState((prev) =>\n prev.key === key && prev.status === 'loading' && prev.checkout === null\n ? prev\n : { key, checkout: null, status: 'loading', error: null },\n );\n\n createCheckout({ ...optionsRef.current, signal: controller.signal }).then(\n (created) => {\n if (cancelled) {\n created.destroy();\n return;\n }\n instance = created;\n created.on('warning', onInstanceWarning);\n setState({ key, checkout: created, status: 'ready', error: null });\n },\n (err: unknown) => {\n if (cancelled) {\n return;\n }\n const error = err as CheckoutError;\n if (error && error.code === ErrorCode.CANCELLED) {\n return;\n }\n setState({ key, checkout: null, status: 'error', error });\n onErrorRef.current?.(error);\n },\n );\n\n return () => {\n cancelled = true;\n controller.abort();\n if (instance) {\n destroyedRef.current.add(instance);\n instance.off('warning', onInstanceWarning);\n instance.destroy();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key, deliver]);\n\n // Runtime updates: push only the changed keys, compared structurally.\n const current = state.key === key ? state.checkout : null;\n useEffect(() => {\n if (!current) {\n return;\n }\n const next = pickUpdatable(optionsRef.current);\n const patch: Partial<Pick<CheckoutProviderOptions, UpdateKey>> = {};\n const sent: UpdateKey[] = [];\n let advanced = false;\n for (const k of UPDATABLE_KEYS) {\n if (!structuralEqual(appliedRef.current[k], next[k])) {\n advanced = true;\n // A value that became undefined has nothing to send (JSON would drop it).\n if (next[k] !== undefined) {\n (patch as Record<string, unknown>)[k] = next[k];\n sent.push(k);\n }\n }\n }\n if (!advanced) {\n return;\n }\n const previous = appliedRef.current;\n appliedRef.current = next;\n if (sent.length === 0) {\n return;\n }\n const onFailure = (failure: unknown) => {\n if (destroyedRef.current.has(current)) {\n return;\n }\n // Restore the failed keys so a later render sends them again, unless a newer value\n // has been applied in the meantime.\n const restored = { ...appliedRef.current } as Record<string, unknown>;\n for (const k of sent) {\n if (structuralEqual(appliedRef.current[k], next[k])) {\n restored[k] = previous[k];\n }\n }\n appliedRef.current = restored as Partial<Pick<CheckoutProviderOptions, UpdateKey>>;\n if (isDevelopment) {\n const code = (failure as { code?: unknown } | null)?.code;\n // Only the error code is logged: never option values or secrets.\n console.warn(\n `[checkout-sdk-react] updateCheckout failed (code: ${\n typeof code === 'string' ? code : 'UNKNOWN'\n }). It will be retried on the next render.`,\n );\n }\n };\n let pending: Promise<unknown>;\n try {\n pending = Promise.resolve(current.updateCheckout(patch));\n } catch (failure) {\n pending = Promise.reject(failure);\n }\n pending.catch(onFailure);\n });\n\n // paymentMethods is creation-time only: warn once in development when it changes.\n const initialPaymentMethods = useRef(options.paymentMethods);\n const warnedRef = useRef(false);\n useEffect(() => {\n if (\n !warnedRef.current &&\n isDevelopment &&\n !structuralEqual(initialPaymentMethods.current, options.paymentMethods)\n ) {\n warnedRef.current = true;\n console.warn(\n '[checkout-sdk-react] `paymentMethods` is read only when the checkout is created. ' +\n 'Changing it later has no effect.',\n );\n }\n });\n\n const stale = state.key !== key;\n const checkout = stale ? null : state.checkout;\n const status: CheckoutStatus = stale ? 'loading' : state.status;\n const error = stale ? null : state.error;\n\n const value = useMemo<CheckoutContextValue>(\n () => ({ checkout, status, error, subscribeWarning }),\n [checkout, status, error, subscribeWarning],\n );\n\n return <CheckoutContext.Provider value={value}>{children}</CheckoutContext.Provider>;\n}\n","import { createContext } from 'react';\nimport type { CheckoutError, CheckoutInstance, WarningEvent } from '@sunbay/checkout-sdk-js';\n\n/** Lifecycle status of the checkout instance owned by `CheckoutProvider`. */\nexport type CheckoutStatus = 'loading' | 'ready' | 'error';\n\n/** Value shared by `CheckoutProvider` with hooks and Element components (internal). */\nexport interface CheckoutContextValue {\n checkout: CheckoutInstance | null;\n status: CheckoutStatus;\n error: CheckoutError | null;\n /**\n * Subscribe to checkout warnings. Warnings buffered before the subscription are replayed to\n * the subscriber once, then live warnings are delivered. Returns an unsubscribe function.\n */\n subscribeWarning(handler: (w: WarningEvent) => void): () => void;\n}\n\n/** Internal context. `null` means no `CheckoutProvider` above. */\nexport const CheckoutContext = createContext<CheckoutContextValue | null>(null);\n","declare const process: { env: { NODE_ENV?: string } } | undefined;\n\n/**\n * Development-mode flag, evaluated once at module load. The exact expression below is what\n * bundlers replace statically (`process.env.NODE_ENV`), so production builds drop every\n * `if (isDevelopment)` branch together with its warning strings.\n *\n * It is a constant on purpose: bundlers do not inline a function such as `isDevelopment()`, so\n * its call sites would keep the dev-only strings in production bundles. Do not rewrite the\n * expression with optional chaining: `process?.env?.NODE_ENV` is not replaced.\n */\nexport const isDevelopment: boolean =\n typeof process !== 'undefined' && process.env.NODE_ENV !== 'production';\n","import type { CreateCheckoutOptions, ElementType, EventName } from '@sunbay/checkout-sdk-js';\nimport type { InstanceEventName } from '../hooks/useCheckoutEvent';\n\n/**\n * Compile-time and test-time parity with `@sunbay/checkout-sdk-js` (internal; not exported from\n * the package entry). Each record is exhaustive: adding a member to the js union without updating\n * it fails `tsc`.\n */\nexport const ELEMENT_TYPES: Record<ElementType, true> = {\n card: true,\n cardNumber: true,\n cardExpiry: true,\n cardCvc: true,\n address: true,\n expressCheckout: true,\n};\n\nexport const INSTANCE_EVENTS: Record<InstanceEventName, true> = {\n paymentResult: true,\n paymentStateChange: true,\n error: true,\n warning: true,\n expressAvailabilityChange: true,\n};\n\n/** Events emitted by individual Elements (bound by the Element components as `on*` props). */\ntype ElementEventName = 'elementReady' | 'ready' | 'change' | 'focus' | 'blur' | 'loadError';\n\n/** Fails `tsc` when js adds an `EventName` that react classified as neither instance nor element. */\ntype Unclassified = Exclude<EventName, InstanceEventName | ElementEventName>;\nexport const ALL_EVENTS_CLASSIFIED: [Unclassified] extends [never] ? true : never = true;\n\n/** Fails `tsc` when a react-side member no longer exists in js `EventName` (stale entry). */\ntype Stale = Exclude<InstanceEventName | ElementEventName, EventName>;\nexport const NO_STALE_EVENTS: [Stale] extends [never] ? true : never = true;\n\n/** How the Provider treats each `createCheckout` option. */\nexport type CreateOptionKind = 'identity' | 'updatable' | 'creationOnly' | 'internal';\n\n/**\n * Classification of every js `CreateCheckoutOptions` key. It is exhaustive: a new js option\n * fails `tsc` until it is classified here, and the Provider derives its identity and update key\n * lists from this table.\n *\n * - `identity`: a change creates a new checkout (the Provider recreates the instance).\n * - `updatable`: a change is sent through `updateCheckout`.\n * - `creationOnly`: read once at creation; later changes have no effect.\n * - `internal`: not part of the Provider's options.\n */\nexport const CREATE_OPTION_KINDS = {\n sessionId: 'identity',\n checkoutClientSecret: 'identity',\n customerAccessSecret: 'identity',\n env: 'identity',\n hostOrigin: 'identity',\n locale: 'updatable',\n appearance: 'updatable',\n billingAddress: 'updatable',\n shippingAddress: 'updatable',\n paymentMethods: 'creationOnly',\n signal: 'internal',\n __transportFactory: 'internal',\n} as const satisfies Record<keyof CreateCheckoutOptions, CreateOptionKind>;\n\ntype KeysOfKind<K extends CreateOptionKind> = {\n [P in keyof typeof CREATE_OPTION_KINDS]: (typeof CREATE_OPTION_KINDS)[P] extends K ? P : never;\n}[keyof typeof CREATE_OPTION_KINDS];\n\nexport type IdentityKey = KeysOfKind<'identity'>;\nexport type UpdatableKey = KeysOfKind<'updatable'>;\n\nfunction keysOfKind<K extends CreateOptionKind>(kind: K): Array<KeysOfKind<K>> {\n return (Object.keys(CREATE_OPTION_KINDS) as Array<keyof typeof CREATE_OPTION_KINDS>).filter(\n (k) => CREATE_OPTION_KINDS[k] === kind,\n ) as Array<KeysOfKind<K>>;\n}\n\nexport const IDENTITY_KEYS: readonly IdentityKey[] = keysOfKind('identity');\nexport const UPDATABLE_KEYS: readonly UpdatableKey[] = keysOfKind('updatable');\n","/**\n * Structural equality for option values (locale strings, appearance, address objects, and the\n * `hide` / `order` arrays of `paymentMethods`).\n *\n * Plain objects (prototype `Object.prototype` or `null`) and arrays are compared recursively by\n * their own enumerable keys, so an inline literal re-created on every render compares equal to\n * the previous one when the values match. Any other object (Date, Map, class instance) is\n * compared with `Object.is`.\n */\nfunction isPlainObject(x: object): boolean {\n const proto = Object.getPrototypeOf(x);\n return proto === Object.prototype || proto === null;\n}\n\nexport function structuralEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) {\n return true;\n }\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {\n return false;\n }\n const aIsArray = Array.isArray(a);\n if (aIsArray !== Array.isArray(b)) {\n return false;\n }\n if (!aIsArray && !(isPlainObject(a) && isPlainObject(b))) {\n return false;\n }\n if (aIsArray) {\n const x = a as unknown[];\n const y = b as unknown[];\n return x.length === y.length && x.every((item, i) => structuralEqual(item, y[i]));\n }\n const x = a as Record<string, unknown>;\n const y = b as Record<string, unknown>;\n const keys = Object.keys(x);\n if (keys.length !== Object.keys(y).length) {\n return false;\n }\n return keys.every(\n (k) => Object.prototype.hasOwnProperty.call(y, k) && structuralEqual(x[k], y[k]),\n );\n}\n","import { useContext } from 'react';\nimport type { CheckoutError, CheckoutInstance } from '@sunbay/checkout-sdk-js';\nimport { CheckoutContext } from '../context';\nimport type { CheckoutStatus } from '../context';\n\nexport interface UseCheckoutResult {\n /** `null` until the checkout instance is ready. */\n checkout: CheckoutInstance | null;\n status: CheckoutStatus;\n error: CheckoutError | null;\n}\n\n/** Reads the checkout instance and its lifecycle status from the nearest `CheckoutProvider`. */\nexport function useCheckout(): UseCheckoutResult {\n const ctx = useContext(CheckoutContext);\n if (!ctx) {\n throw new Error('useCheckout must be used within <CheckoutProvider>');\n }\n return { checkout: ctx.checkout, status: ctx.status, error: ctx.error };\n}\n","import { useContext, useEffect, useRef } from 'react';\nimport type { EventName, EventPayloadMap } from '@sunbay/checkout-sdk-js';\nimport { CheckoutContext } from '../context';\n\n/** Events emitted at checkout instance level. */\nexport type InstanceEventName = Extract<\n EventName,\n 'paymentResult' | 'paymentStateChange' | 'error' | 'warning' | 'expressAvailabilityChange'\n>;\n\n/**\n * Subscribes to an instance-level event. The latest handler is always called; changing the\n * handler does not resubscribe.\n */\nexport function useCheckoutEvent<E extends InstanceEventName>(\n name: E,\n handler: (payload: EventPayloadMap[E]) => void,\n): void {\n const ctx = useContext(CheckoutContext);\n if (!ctx) {\n throw new Error('useCheckoutEvent must be used within <CheckoutProvider>');\n }\n const { checkout, subscribeWarning } = ctx;\n\n const handlerRef = useRef(handler);\n useEffect(() => {\n handlerRef.current = handler;\n });\n\n useEffect(() => {\n if (name === 'warning') {\n // Warnings are fanned out by the Provider (with replay), not via instance.on.\n return subscribeWarning((w) => (handlerRef.current as (p: unknown) => void)(w));\n }\n if (!checkout) {\n return undefined;\n }\n const listener = (payload: EventPayloadMap[E]) => handlerRef.current(payload);\n checkout.on(name, listener);\n return () => {\n checkout.off(name, listener);\n };\n }, [checkout, name, subscribeWarning]);\n}\n","/** @jsxRuntime classic */\n/** @jsx React.createElement */\n/** @jsxFrag React.Fragment */\nimport * as React from 'react';\nimport { forwardRef, useContext, useEffect, useRef, useState } from 'react';\nimport type { CSSProperties, ForwardedRef } from 'react';\nimport { ErrorCode } from '@sunbay/checkout-sdk-js';\nimport type {\n AvailableWallets,\n BlurEvent,\n ChangeEvent,\n CheckoutElement,\n CheckoutError,\n ElementOptions,\n ElementReadyEvent,\n ElementType,\n FocusEvent,\n} from '@sunbay/checkout-sdk-js';\nimport { CheckoutContext } from '../context';\nimport { isDevelopment } from '../internal/env';\nimport { structuralEqual } from '../internal/structuralEqual';\nimport { UPDATABLE_OPTION_KEYS } from './updatableOptions';\n\n/**\n * Props shared by every Element component.\n *\n * - `onReady` is bound to `elementReady` (the iframe is loaded). Field-level `ready` is not\n * exposed in v1, so the parameter type is `ElementReadyEvent`.\n * - Option changes: only `expressCheckout` accepts live updates, for `paymentMethods`, `layout`\n * and `buttonHeight`; they are sent through `element.update`. Any other option change, and the\n * removal of one of those three keys, destroys and recreates the Element (typed input in a card\n * field is lost).\n * - A failed `element.update` does not throw and does not call `onLoadError`. The Element is\n * destroyed and recreated with the current options so the iframe never stays out of date (typed\n * input in a card field would be lost, but only express checkout accepts updates). In\n * development it also logs a console warning with the error code only.\n */\nexport interface ElementProps<T> {\n options?: T;\n id?: string;\n className?: string;\n style?: CSSProperties;\n onReady?: (e: ElementReadyEvent) => void;\n onChange?: (e: ChangeEvent) => void;\n onFocus?: (e: FocusEvent) => void;\n onBlur?: (e: BlurEvent) => void;\n onLoadError?: (e: CheckoutError) => void;\n /** expressCheckout only. */\n onAvailabilityChange?: (w: AvailableWallets) => void;\n}\n\ntype AnyProps = ElementProps<Record<string, unknown>>;\n\nfunction codeOf(e: unknown): string {\n const code = (e as { code?: unknown } | null)?.code;\n return typeof code === 'string' ? code : 'UNKNOWN';\n}\n\nfunction assignRef<T>(ref: ForwardedRef<T>, value: T | null): void {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n ref.current = value;\n }\n}\n\n/** Serialize every option except the updatable keys; a change forces a recreate. */\nfunction recreateKeyOf(options: Record<string, unknown> | undefined, updatable: readonly string[]): string {\n const entries = Object.keys(options ?? {})\n .filter((k) => !updatable.includes(k) && options?.[k] !== undefined)\n .sort()\n .map((k) => [k, options?.[k]]);\n return JSON.stringify(entries);\n}\n\nexport function createElementComponent(type: ElementType, displayName: string) {\n const updatable = UPDATABLE_OPTION_KEYS[type];\n\n const Component = forwardRef<CheckoutElement, AnyProps>(function ElementComponent(props, ref) {\n const ctx = useContext(CheckoutContext);\n const checkout = ctx ? ctx.checkout : null;\n const divRef = useRef<HTMLDivElement>(null);\n const propsRef = useRef(props);\n propsRef.current = props;\n const refRef = useRef(ref);\n refRef.current = ref;\n const appliedRef = useRef<Record<string, unknown>>({});\n const elementRef = useRef<CheckoutElement | null>(null);\n const assignedRefRef = useRef<ForwardedRef<CheckoutElement> | null>(null);\n // Bumped when an updatable key is removed, which `update` cannot express.\n const [generation, setGeneration] = useState(0);\n const recreateKey = recreateKeyOf(props.options, updatable);\n\n useEffect(() => {\n const div = divRef.current;\n if (!checkout || !div) {\n return;\n }\n let cancelled = false;\n // De-duplication of onLoadError: each distinct error (by errorId, or by identity when it\n // has none) is reported once, and the mount rejection is skipped when it mirrors a\n // loadError event that was already reported.\n const reportedIds = new Set<string>();\n const reportedErrors = new WeakSet<object>();\n let loadErrorReported = false;\n const report = (error: CheckoutError, source: 'create' | 'event' | 'mount') => {\n if (cancelled || (source === 'mount' && loadErrorReported)) {\n return;\n }\n const errorId = (error as { errorId?: unknown } | null)?.errorId;\n if (typeof errorId === 'string') {\n if (reportedIds.has(errorId)) {\n return;\n }\n reportedIds.add(errorId);\n } else if (error !== null && typeof error === 'object') {\n if (reportedErrors.has(error)) {\n return;\n }\n reportedErrors.add(error);\n }\n if (source === 'event') {\n loadErrorReported = true;\n }\n if (codeOf(error) === ErrorCode.ELEMENT_CONFLICT && isDevelopment) {\n console.error(\n `[checkout-sdk-react] <${displayName}> could not be created (code: ELEMENT_CONFLICT). ` +\n 'Card Elements are mutually exclusive.',\n );\n }\n propsRef.current.onLoadError?.(error);\n };\n\n let element: CheckoutElement;\n try {\n element = checkout.create(type, propsRef.current.options as ElementOptions | undefined);\n } catch (error) {\n report(error as CheckoutError, 'create');\n return;\n }\n appliedRef.current = { ...(propsRef.current.options ?? {}) };\n elementRef.current = element;\n assignedRefRef.current = refRef.current;\n assignRef(refRef.current, element);\n\n element.on('elementReady', (e) => propsRef.current.onReady?.(e));\n element.on('change', (e) => propsRef.current.onChange?.(e));\n element.on('focus', (e) => propsRef.current.onFocus?.(e));\n element.on('blur', (e) => propsRef.current.onBlur?.(e));\n element.on('loadError', (e) => report(e.error, 'event'));\n if (type === 'expressCheckout') {\n element.on('expressAvailabilityChange', (e) =>\n propsRef.current.onAvailabilityChange?.(e.availableWallets),\n );\n }\n\n element.mount(div).catch((error: unknown) => {\n const code = codeOf(error);\n if (code === ErrorCode.CANCELLED || code === ErrorCode.INSTANCE_DESTROYED) {\n return;\n }\n report(error as CheckoutError, 'mount');\n });\n\n return () => {\n cancelled = true;\n elementRef.current = null;\n assignRef(assignedRefRef.current, null);\n assignedRefRef.current = null;\n element.destroy();\n };\n }, [checkout, recreateKey, generation]);\n\n // A different `ref` between renders: release the old one and hand the element to the new one.\n useEffect(() => {\n const assigned = assignedRefRef.current;\n if (!assigned || assigned === ref) {\n return;\n }\n assignRef(assigned, null);\n assignRef(ref, elementRef.current);\n assignedRefRef.current = ref;\n }, [ref]);\n\n // Updatable option changes: send only the changed keys.\n useEffect(() => {\n const element = elementRef.current;\n if (!element) {\n return;\n }\n const next: Record<string, unknown> = propsRef.current.options ?? {};\n const applied = appliedRef.current;\n const patch: Record<string, unknown> = {};\n let changed = false;\n let removed = false;\n updatable.forEach((k) => {\n if (structuralEqual(applied[k], next[k])) {\n return;\n }\n changed = true;\n if (next[k] === undefined) {\n removed = true;\n } else {\n patch[k] = next[k];\n }\n });\n if (!changed) {\n return;\n }\n if (removed) {\n // The runtime merges patches, so a removed key would keep its old value: recreate.\n setGeneration((g) => g + 1);\n return;\n }\n appliedRef.current = { ...next };\n const onFailure = (failure: unknown) => {\n if (elementRef.current !== element) {\n // Unmounted or already recreated: nothing left to reconcile.\n return;\n }\n if (isDevelopment) {\n // Only the error code is logged: never option values.\n console.warn(\n `[checkout-sdk-react] <${displayName}> update failed (code: ${codeOf(failure)}). ` +\n 'The Element is recreated with the current options.',\n );\n }\n // The iframe may not reflect the new options: recreate it from the current props.\n setGeneration((g) => g + 1);\n };\n try {\n Promise.resolve(element.update(patch as Partial<ElementOptions>)).catch(onFailure);\n } catch (failure) {\n onFailure(failure);\n }\n });\n\n return <div ref={divRef} id={props.id} className={props.className} style={props.style} />;\n });\n Component.displayName = displayName;\n return Component;\n}\n","import type { ElementType } from '@sunbay/checkout-sdk-js';\n\n/**\n * Option keys that can change at runtime through `element.update(patch)`. A change to any other\n * key destroys the Element and creates a new one, which is always correct and fails safe.\n *\n * Evidence (paths relative to the hosted checkout repository, `src/sdk-runtime/`):\n * - `Orchestrator.ts` `handleUpdateElement` accepts `updateElement` only for `expressCheckout`;\n * every other type is rejected with `UNSUPPORTED_CAPABILITY`.\n * - For `expressCheckout` the runtime merges the patch onto the current options and re-renders\n * the buttons. `element/sanitizeExpressOptions.ts` keeps only `paymentMethods`\n * (applePay / googlePay: boolean or { buttonTheme, buttonType }), `layout` ({ maxColumns }) and\n * `buttonHeight`. Other keys (including `appearance`) are dropped with an\n * `EXPRESS_OPTION_IGNORED` warning, so they never take effect through `update`.\n */\nexport const UPDATABLE_OPTION_KEYS: Record<ElementType, readonly string[]> = {\n card: [],\n cardNumber: [],\n cardExpiry: [],\n cardCvc: [],\n address: [],\n expressCheckout: ['paymentMethods', 'layout', 'buttonHeight'],\n};\n","import type { ComponentType } from 'react';\nimport type {\n AddressElementOptions,\n CardElementOptions,\n CardFieldElementOptions,\n CheckoutElement,\n ElementType,\n ExpressCheckoutElementOptions,\n} from '@sunbay/checkout-sdk-js';\nimport type { ForwardRefExoticComponent, RefAttributes } from 'react';\nimport { createElementComponent } from './createElementComponent';\nimport type { ElementProps } from './createElementComponent';\n\ntype Without<T, K extends string> = Omit<T, K>;\ntype Component<P> = ForwardRefExoticComponent<P & RefAttributes<CheckoutElement>>;\n\nexport type CardElementProps = Without<ElementProps<CardElementOptions>, 'onAvailabilityChange'>;\nexport type CardNumberElementProps = Without<ElementProps<CardFieldElementOptions>, 'onAvailabilityChange'>;\nexport type CardExpiryElementProps = CardNumberElementProps;\nexport type CardCvcElementProps = CardNumberElementProps;\nexport type AddressElementProps = Without<ElementProps<AddressElementOptions>, 'onAvailabilityChange' | 'options'> & {\n options: AddressElementOptions;\n};\nexport type ExpressCheckoutElementProps = ElementProps<ExpressCheckoutElementOptions>;\n\nexport const CardElement = createElementComponent('card', 'CardElement') as unknown as Component<CardElementProps>;\nexport const CardNumberElement = createElementComponent('cardNumber', 'CardNumberElement') as unknown as Component<CardNumberElementProps>;\nexport const CardExpiryElement = createElementComponent('cardExpiry', 'CardExpiryElement') as unknown as Component<CardExpiryElementProps>;\nexport const CardCvcElement = createElementComponent('cardCvc', 'CardCvcElement') as unknown as Component<CardCvcElementProps>;\nexport const AddressElement = createElementComponent('address', 'AddressElement') as unknown as Component<AddressElementProps>;\nexport const ExpressCheckoutElement = createElementComponent('expressCheckout', 'ExpressCheckoutElement') as unknown as Component<ExpressCheckoutElementProps>;\n\n/** Consistency-test registry (internal; not exported from the package entry). */\nexport const ELEMENT_COMPONENTS: Record<ElementType, ComponentType<any>> = {\n card: CardElement,\n cardNumber: CardNumberElement,\n cardExpiry: CardExpiryElement,\n cardCvc: CardCvcElement,\n address: AddressElement,\n expressCheckout: ExpressCheckoutElement,\n};\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport type { CheckoutError, ConfirmOptions, PaymentOutcome } from '@sunbay/checkout-sdk-js';\nimport { useCheckout } from './useCheckout';\n\nexport interface UseConfirmResult {\n /** Resolves with a terminal or `pending` outcome; rejects with the js `CheckoutError`. */\n confirm: (opts?: ConfirmOptions) => Promise<PaymentOutcome>;\n /** True while a call started by this hook is running. */\n isConfirming: boolean;\n /** Outcome of the latest call (including `pending`), `null` otherwise. */\n outcome: PaymentOutcome | null;\n /** Error of the latest call, `null` otherwise. */\n error: CheckoutError | null;\n}\n\nfunction notReadyError(): CheckoutError {\n const rand = Math.random().toString(36).slice(2, 10) || '0';\n return {\n code: 'INVALID_OPTIONS',\n category: 'configuration',\n message: 'Checkout is not ready',\n errorId: `err_${Date.now().toString(36)}_${rand}`,\n } as CheckoutError;\n}\n\n/** Confirms the payment on the current checkout and tracks its progress, outcome and error. */\nexport function useConfirm(): UseConfirmResult {\n const { checkout } = useCheckout();\n const checkoutRef = useRef(checkout);\n useEffect(() => {\n checkoutRef.current = checkout;\n }, [checkout]);\n\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n // Id of the call that currently owns `isConfirming`; a rejected duplicate must not clear it.\n const activeCall = useRef(0);\n const nextCall = useRef(0);\n\n const [isConfirming, setIsConfirming] = useState(false);\n const [outcome, setOutcome] = useState<PaymentOutcome | null>(null);\n const [error, setError] = useState<CheckoutError | null>(null);\n\n const confirm = useCallback((opts?: ConfirmOptions): Promise<PaymentOutcome> => {\n const instance = checkoutRef.current;\n // Only a call that starts while none is in flight owns the hook state; a busy duplicate\n // still gets its rejection but never writes `outcome` or `error`.\n const owner = activeCall.current === 0;\n if (owner && mounted.current) {\n setOutcome(null);\n setError(null);\n }\n if (!instance) {\n const err = notReadyError();\n if (owner && mounted.current) {\n setError(err);\n }\n return Promise.reject(err);\n }\n const id = ++nextCall.current;\n let promise: Promise<PaymentOutcome>;\n try {\n promise = instance.confirm(opts);\n } catch (e) {\n promise = Promise.reject(e);\n }\n if (owner) {\n activeCall.current = id;\n if (mounted.current) {\n setIsConfirming(true);\n }\n }\n const finish = () => {\n if (owner && activeCall.current === id) {\n activeCall.current = 0;\n if (mounted.current) {\n setIsConfirming(false);\n }\n }\n };\n return promise.then(\n (result) => {\n finish();\n if (owner && mounted.current) {\n setOutcome(result);\n }\n return result;\n },\n (err: CheckoutError) => {\n finish();\n if (owner && mounted.current) {\n setError(err);\n }\n throw err;\n },\n );\n }, []);\n\n return { confirm, isConfirming, outcome, error };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,YAAuB;AACvB,IAAAA,gBAAkE;AAElE,6BAA0C;;;ACN1C,mBAA8B;AAmBvB,IAAM,sBAAkB,4BAA2C,IAAI;;;ACRvE,IAAM,gBACT,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;;;ACqCxD,IAAM,sBAAsB;AAAA,EAC/B,WAAW;AAAA,EACX,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,QAAQ;AAAA,EACR,oBAAoB;AACxB;AASA,SAAS,WAAuC,MAA+B;AAC3E,SAAQ,OAAO,KAAK,mBAAmB,EAA8C;AAAA,IACjF,CAAC,MAAM,oBAAoB,CAAC,MAAM;AAAA,EACtC;AACJ;AAEO,IAAM,gBAAwC,WAAW,UAAU;AACnE,IAAM,iBAA0C,WAAW,WAAW;;;ACrE7E,SAAS,cAAc,GAAoB;AACvC,QAAM,QAAQ,OAAO,eAAe,CAAC;AACrC,SAAO,UA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E7D,QAAM,cAAU,2BAAY,CAAC,SAAmD;AAC5E,UAAM,WAAW,YAAY;AAG7B,UAAM,QAAQ,WAAW,YAAY;AACrC,QAAI,SAAS,QAAQ,SAAS;AAC1B,iBAAW,IAAI;AACf,eAAS,IAAI;AAAA,IACjB;AACA,QAAI,CAAC,UAAU;AACX,YAAM,MAAM,cAAc;AAC1B,UAAI,SAAS,QAAQ,SAAS;AAC1B,iBAAS,GAAG;AAAA,MAChB;AACA,aAAO,QAAQ,OAAO,GAAG;AAAA,IAC7B;AACA,UAAM,KAAK,EAAE,SAAS;AACtB,QAAI;AACJ,QAAI;AACA,gBAAU,SAAS,QAAQ,IAAI;AAAA,IACnC,SAAS,GAAG;AACR,gBAAU,QAAQ,OAAO,CAAC;AAAA,IAC9B;AACA,QAAI,OAAO;AACP,iBAAW,UAAU;AACrB,UAAI,QAAQ,SAAS;AACjB,wBAAgB,IAAI;AAAA,MACxB;AAAA,IACJ;AACA,UAAM,SAAS,MAAM;AACjB,UAAI,SAAS,WAAW,YAAY,IAAI;AACpC,mBAAW,UAAU;AACrB,YAAI,QAAQ,SAAS;AACjB,0BAAgB,KAAK;AAAA,QACzB;AAAA,MACJ;AAAA,IACJ;AACA,WAAO,QAAQ;AAAA,MACX,CAAC,WAAW;AACR,eAAO;AACP,YAAI,SAAS,QAAQ,SAAS;AAC1B,qBAAW,MAAM;AAAA,QACrB;AACA,eAAO;AAAA,MACX;AAAA,MACA,CAAC,QAAuB;AACpB,eAAO;AACP,YAAI,SAAS,QAAQ,SAAS;AAC1B,mBAAS,GAAG;AAAA,QAChB;AACA,cAAM;AAAA,MACV;AAAA,IACJ;AAAA,EACJ,GAAG,CAAC,CAAC;AAEL,SAAO,EAAE,SAAS,cAAc,SAAS,MAAM;AACnD;;;AX/DA,IAAAC,0BAAyC;AAhClC,IAAM,UACT,OAAyC,UAAkB;","names":["import_react","x","y","error","import_react","import_react","React","import_react","import_checkout_sdk_js","import_react","import_checkout_sdk_js"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ReactNode, ReactElement, CSSProperties, ForwardRefExoticComponent, RefAttributes } from 'react';
|
|
2
|
+
import { CreateCheckoutOptions, CheckoutError, WarningEvent, CheckoutInstance, EventName, EventPayloadMap, ElementReadyEvent, ChangeEvent, FocusEvent, BlurEvent, AvailableWallets, CheckoutElement, AddressElementOptions, CardFieldElementOptions, CardElementOptions, ExpressCheckoutElementOptions, ConfirmOptions, PaymentOutcome } from '@sunbay/checkout-sdk-js';
|
|
3
|
+
export { AddressElementOptions, AddressFormStyle, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, CardOnFileOptions, ChangeEvent, CheckoutElement, CheckoutError, CheckoutErrorCategory, CheckoutInstance, ConfirmOptions, CreateCheckoutOptions, ElementOptions, ElementReadyEvent, ElementState, ElementStatus, ElementType, Env, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, ExpressMethodView, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, MountOptions, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentMethodsView, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, SessionStatus, TxnStatus, WARNING_CODES, WalletErrorStage, WarningCode, WarningEvent } from '@sunbay/checkout-sdk-js';
|
|
4
|
+
|
|
5
|
+
/** Options accepted by the Provider: everything `createCheckout` takes except internals. */
|
|
6
|
+
type CheckoutProviderOptions = Omit<CreateCheckoutOptions, 'signal' | '__transportFactory'>;
|
|
7
|
+
interface CheckoutProviderProps {
|
|
8
|
+
options: CheckoutProviderOptions;
|
|
9
|
+
/** Called once when creating the checkout fails (never for cancellation). */
|
|
10
|
+
onError?: (error: CheckoutError) => void;
|
|
11
|
+
/** Called for every checkout warning (including those raised during initialize). */
|
|
12
|
+
onWarning?: (warning: WarningEvent) => void;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a checkout instance for the given options and shares it with the tree below.
|
|
17
|
+
*/
|
|
18
|
+
declare function CheckoutProvider(props: CheckoutProviderProps): ReactElement;
|
|
19
|
+
|
|
20
|
+
/** Lifecycle status of the checkout instance owned by `CheckoutProvider`. */
|
|
21
|
+
type CheckoutStatus = 'loading' | 'ready' | 'error';
|
|
22
|
+
|
|
23
|
+
interface UseCheckoutResult {
|
|
24
|
+
/** `null` until the checkout instance is ready. */
|
|
25
|
+
checkout: CheckoutInstance | null;
|
|
26
|
+
status: CheckoutStatus;
|
|
27
|
+
error: CheckoutError | null;
|
|
28
|
+
}
|
|
29
|
+
/** Reads the checkout instance and its lifecycle status from the nearest `CheckoutProvider`. */
|
|
30
|
+
declare function useCheckout(): UseCheckoutResult;
|
|
31
|
+
|
|
32
|
+
/** Events emitted at checkout instance level. */
|
|
33
|
+
type InstanceEventName = Extract<EventName, 'paymentResult' | 'paymentStateChange' | 'error' | 'warning' | 'expressAvailabilityChange'>;
|
|
34
|
+
/**
|
|
35
|
+
* Subscribes to an instance-level event. The latest handler is always called; changing the
|
|
36
|
+
* handler does not resubscribe.
|
|
37
|
+
*/
|
|
38
|
+
declare function useCheckoutEvent<E extends InstanceEventName>(name: E, handler: (payload: EventPayloadMap[E]) => void): void;
|
|
39
|
+
|
|
40
|
+
/** @jsxRuntime classic */
|
|
41
|
+
/** @jsx React.createElement */
|
|
42
|
+
/** @jsxFrag React.Fragment */
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Props shared by every Element component.
|
|
46
|
+
*
|
|
47
|
+
* - `onReady` is bound to `elementReady` (the iframe is loaded). Field-level `ready` is not
|
|
48
|
+
* exposed in v1, so the parameter type is `ElementReadyEvent`.
|
|
49
|
+
* - Option changes: only `expressCheckout` accepts live updates, for `paymentMethods`, `layout`
|
|
50
|
+
* and `buttonHeight`; they are sent through `element.update`. Any other option change, and the
|
|
51
|
+
* removal of one of those three keys, destroys and recreates the Element (typed input in a card
|
|
52
|
+
* field is lost).
|
|
53
|
+
* - A failed `element.update` does not throw and does not call `onLoadError`. The Element is
|
|
54
|
+
* destroyed and recreated with the current options so the iframe never stays out of date (typed
|
|
55
|
+
* input in a card field would be lost, but only express checkout accepts updates). In
|
|
56
|
+
* development it also logs a console warning with the error code only.
|
|
57
|
+
*/
|
|
58
|
+
interface ElementProps<T> {
|
|
59
|
+
options?: T;
|
|
60
|
+
id?: string;
|
|
61
|
+
className?: string;
|
|
62
|
+
style?: CSSProperties;
|
|
63
|
+
onReady?: (e: ElementReadyEvent) => void;
|
|
64
|
+
onChange?: (e: ChangeEvent) => void;
|
|
65
|
+
onFocus?: (e: FocusEvent) => void;
|
|
66
|
+
onBlur?: (e: BlurEvent) => void;
|
|
67
|
+
onLoadError?: (e: CheckoutError) => void;
|
|
68
|
+
/** expressCheckout only. */
|
|
69
|
+
onAvailabilityChange?: (w: AvailableWallets) => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type Without<T, K extends string> = Omit<T, K>;
|
|
73
|
+
type Component<P> = ForwardRefExoticComponent<P & RefAttributes<CheckoutElement>>;
|
|
74
|
+
type CardElementProps = Without<ElementProps<CardElementOptions>, 'onAvailabilityChange'>;
|
|
75
|
+
type CardNumberElementProps = Without<ElementProps<CardFieldElementOptions>, 'onAvailabilityChange'>;
|
|
76
|
+
type CardExpiryElementProps = CardNumberElementProps;
|
|
77
|
+
type CardCvcElementProps = CardNumberElementProps;
|
|
78
|
+
type AddressElementProps = Without<ElementProps<AddressElementOptions>, 'onAvailabilityChange' | 'options'> & {
|
|
79
|
+
options: AddressElementOptions;
|
|
80
|
+
};
|
|
81
|
+
type ExpressCheckoutElementProps = ElementProps<ExpressCheckoutElementOptions>;
|
|
82
|
+
declare const CardElement: Component<CardElementProps>;
|
|
83
|
+
declare const CardNumberElement: Component<CardNumberElementProps>;
|
|
84
|
+
declare const CardExpiryElement: Component<CardExpiryElementProps>;
|
|
85
|
+
declare const CardCvcElement: Component<CardCvcElementProps>;
|
|
86
|
+
declare const AddressElement: Component<AddressElementProps>;
|
|
87
|
+
declare const ExpressCheckoutElement: Component<ExpressCheckoutElementProps>;
|
|
88
|
+
|
|
89
|
+
interface UseConfirmResult {
|
|
90
|
+
/** Resolves with a terminal or `pending` outcome; rejects with the js `CheckoutError`. */
|
|
91
|
+
confirm: (opts?: ConfirmOptions) => Promise<PaymentOutcome>;
|
|
92
|
+
/** True while a call started by this hook is running. */
|
|
93
|
+
isConfirming: boolean;
|
|
94
|
+
/** Outcome of the latest call (including `pending`), `null` otherwise. */
|
|
95
|
+
outcome: PaymentOutcome | null;
|
|
96
|
+
/** Error of the latest call, `null` otherwise. */
|
|
97
|
+
error: CheckoutError | null;
|
|
98
|
+
}
|
|
99
|
+
/** Confirms the payment on the current checkout and tracks its progress, outcome and error. */
|
|
100
|
+
declare function useConfirm(): UseConfirmResult;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @sunbay/checkout-sdk-react public entry.
|
|
104
|
+
*/
|
|
105
|
+
declare const version: string;
|
|
106
|
+
|
|
107
|
+
export { AddressElement, type AddressElementProps, CardCvcElement, type CardCvcElementProps, CardElement, type CardElementProps, CardExpiryElement, type CardExpiryElementProps, CardNumberElement, type CardNumberElementProps, CheckoutProvider, type CheckoutProviderOptions, type CheckoutProviderProps, type CheckoutStatus, type ElementProps, ExpressCheckoutElement, type ExpressCheckoutElementProps, type InstanceEventName, type UseCheckoutResult, type UseConfirmResult, useCheckout, useCheckoutEvent, useConfirm, version };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ReactNode, ReactElement, CSSProperties, ForwardRefExoticComponent, RefAttributes } from 'react';
|
|
2
|
+
import { CreateCheckoutOptions, CheckoutError, WarningEvent, CheckoutInstance, EventName, EventPayloadMap, ElementReadyEvent, ChangeEvent, FocusEvent, BlurEvent, AvailableWallets, CheckoutElement, AddressElementOptions, CardFieldElementOptions, CardElementOptions, ExpressCheckoutElementOptions, ConfirmOptions, PaymentOutcome } from '@sunbay/checkout-sdk-js';
|
|
3
|
+
export { AddressElementOptions, AddressFormStyle, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, CardOnFileOptions, ChangeEvent, CheckoutElement, CheckoutError, CheckoutErrorCategory, CheckoutInstance, ConfirmOptions, CreateCheckoutOptions, ElementOptions, ElementReadyEvent, ElementState, ElementStatus, ElementType, Env, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, ExpressMethodView, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, MountOptions, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentMethodsView, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, SessionStatus, TxnStatus, WARNING_CODES, WalletErrorStage, WarningCode, WarningEvent } from '@sunbay/checkout-sdk-js';
|
|
4
|
+
|
|
5
|
+
/** Options accepted by the Provider: everything `createCheckout` takes except internals. */
|
|
6
|
+
type CheckoutProviderOptions = Omit<CreateCheckoutOptions, 'signal' | '__transportFactory'>;
|
|
7
|
+
interface CheckoutProviderProps {
|
|
8
|
+
options: CheckoutProviderOptions;
|
|
9
|
+
/** Called once when creating the checkout fails (never for cancellation). */
|
|
10
|
+
onError?: (error: CheckoutError) => void;
|
|
11
|
+
/** Called for every checkout warning (including those raised during initialize). */
|
|
12
|
+
onWarning?: (warning: WarningEvent) => void;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a checkout instance for the given options and shares it with the tree below.
|
|
17
|
+
*/
|
|
18
|
+
declare function CheckoutProvider(props: CheckoutProviderProps): ReactElement;
|
|
19
|
+
|
|
20
|
+
/** Lifecycle status of the checkout instance owned by `CheckoutProvider`. */
|
|
21
|
+
type CheckoutStatus = 'loading' | 'ready' | 'error';
|
|
22
|
+
|
|
23
|
+
interface UseCheckoutResult {
|
|
24
|
+
/** `null` until the checkout instance is ready. */
|
|
25
|
+
checkout: CheckoutInstance | null;
|
|
26
|
+
status: CheckoutStatus;
|
|
27
|
+
error: CheckoutError | null;
|
|
28
|
+
}
|
|
29
|
+
/** Reads the checkout instance and its lifecycle status from the nearest `CheckoutProvider`. */
|
|
30
|
+
declare function useCheckout(): UseCheckoutResult;
|
|
31
|
+
|
|
32
|
+
/** Events emitted at checkout instance level. */
|
|
33
|
+
type InstanceEventName = Extract<EventName, 'paymentResult' | 'paymentStateChange' | 'error' | 'warning' | 'expressAvailabilityChange'>;
|
|
34
|
+
/**
|
|
35
|
+
* Subscribes to an instance-level event. The latest handler is always called; changing the
|
|
36
|
+
* handler does not resubscribe.
|
|
37
|
+
*/
|
|
38
|
+
declare function useCheckoutEvent<E extends InstanceEventName>(name: E, handler: (payload: EventPayloadMap[E]) => void): void;
|
|
39
|
+
|
|
40
|
+
/** @jsxRuntime classic */
|
|
41
|
+
/** @jsx React.createElement */
|
|
42
|
+
/** @jsxFrag React.Fragment */
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Props shared by every Element component.
|
|
46
|
+
*
|
|
47
|
+
* - `onReady` is bound to `elementReady` (the iframe is loaded). Field-level `ready` is not
|
|
48
|
+
* exposed in v1, so the parameter type is `ElementReadyEvent`.
|
|
49
|
+
* - Option changes: only `expressCheckout` accepts live updates, for `paymentMethods`, `layout`
|
|
50
|
+
* and `buttonHeight`; they are sent through `element.update`. Any other option change, and the
|
|
51
|
+
* removal of one of those three keys, destroys and recreates the Element (typed input in a card
|
|
52
|
+
* field is lost).
|
|
53
|
+
* - A failed `element.update` does not throw and does not call `onLoadError`. The Element is
|
|
54
|
+
* destroyed and recreated with the current options so the iframe never stays out of date (typed
|
|
55
|
+
* input in a card field would be lost, but only express checkout accepts updates). In
|
|
56
|
+
* development it also logs a console warning with the error code only.
|
|
57
|
+
*/
|
|
58
|
+
interface ElementProps<T> {
|
|
59
|
+
options?: T;
|
|
60
|
+
id?: string;
|
|
61
|
+
className?: string;
|
|
62
|
+
style?: CSSProperties;
|
|
63
|
+
onReady?: (e: ElementReadyEvent) => void;
|
|
64
|
+
onChange?: (e: ChangeEvent) => void;
|
|
65
|
+
onFocus?: (e: FocusEvent) => void;
|
|
66
|
+
onBlur?: (e: BlurEvent) => void;
|
|
67
|
+
onLoadError?: (e: CheckoutError) => void;
|
|
68
|
+
/** expressCheckout only. */
|
|
69
|
+
onAvailabilityChange?: (w: AvailableWallets) => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type Without<T, K extends string> = Omit<T, K>;
|
|
73
|
+
type Component<P> = ForwardRefExoticComponent<P & RefAttributes<CheckoutElement>>;
|
|
74
|
+
type CardElementProps = Without<ElementProps<CardElementOptions>, 'onAvailabilityChange'>;
|
|
75
|
+
type CardNumberElementProps = Without<ElementProps<CardFieldElementOptions>, 'onAvailabilityChange'>;
|
|
76
|
+
type CardExpiryElementProps = CardNumberElementProps;
|
|
77
|
+
type CardCvcElementProps = CardNumberElementProps;
|
|
78
|
+
type AddressElementProps = Without<ElementProps<AddressElementOptions>, 'onAvailabilityChange' | 'options'> & {
|
|
79
|
+
options: AddressElementOptions;
|
|
80
|
+
};
|
|
81
|
+
type ExpressCheckoutElementProps = ElementProps<ExpressCheckoutElementOptions>;
|
|
82
|
+
declare const CardElement: Component<CardElementProps>;
|
|
83
|
+
declare const CardNumberElement: Component<CardNumberElementProps>;
|
|
84
|
+
declare const CardExpiryElement: Component<CardExpiryElementProps>;
|
|
85
|
+
declare const CardCvcElement: Component<CardCvcElementProps>;
|
|
86
|
+
declare const AddressElement: Component<AddressElementProps>;
|
|
87
|
+
declare const ExpressCheckoutElement: Component<ExpressCheckoutElementProps>;
|
|
88
|
+
|
|
89
|
+
interface UseConfirmResult {
|
|
90
|
+
/** Resolves with a terminal or `pending` outcome; rejects with the js `CheckoutError`. */
|
|
91
|
+
confirm: (opts?: ConfirmOptions) => Promise<PaymentOutcome>;
|
|
92
|
+
/** True while a call started by this hook is running. */
|
|
93
|
+
isConfirming: boolean;
|
|
94
|
+
/** Outcome of the latest call (including `pending`), `null` otherwise. */
|
|
95
|
+
outcome: PaymentOutcome | null;
|
|
96
|
+
/** Error of the latest call, `null` otherwise. */
|
|
97
|
+
error: CheckoutError | null;
|
|
98
|
+
}
|
|
99
|
+
/** Confirms the payment on the current checkout and tracks its progress, outcome and error. */
|
|
100
|
+
declare function useConfirm(): UseConfirmResult;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @sunbay/checkout-sdk-react public entry.
|
|
104
|
+
*/
|
|
105
|
+
declare const version: string;
|
|
106
|
+
|
|
107
|
+
export { AddressElement, type AddressElementProps, CardCvcElement, type CardCvcElementProps, CardElement, type CardElementProps, CardExpiryElement, type CardExpiryElementProps, CardNumberElement, type CardNumberElementProps, CheckoutProvider, type CheckoutProviderOptions, type CheckoutProviderProps, type CheckoutStatus, type ElementProps, ExpressCheckoutElement, type ExpressCheckoutElementProps, type InstanceEventName, type UseCheckoutResult, type UseConfirmResult, useCheckout, useCheckoutEvent, useConfirm, version };
|