@paydock/client-sdk
Version:
Paydock client sdk
106 lines • 3.57 kB
TypeScript
import type { EVENT } from '../enum/event.enum';
import type { ERROR_OPERATION } from '../enum/error-operation.enum';
import type { OpenWalletBaseEvent, OpenWalletDataEvent } from '../types/base-event-data.interface';
import type { Billing, CreateOTTResponse, Shipping } from '../types/payment-source.type';
/**
* Data emitted when the wallet button is clicked.
*
* The merchant's `onClick` handler controls the payment flow via its return value:
* - Return `void` / `undefined` to continue normally.
* - Return `false` to abort the payment flow.
* - Return a `Promise<void>` to defer the wallet sheet until the promise resolves.
* - Return a `Promise<boolean>` — if it resolves to `false`, the flow is aborted.
* - Throwing an error also aborts the flow.
*/
export interface OnClickEventData extends OpenWalletBaseEvent {
event: EVENT.ON_CLICK;
}
/**
* Payload for the onSuccess event data.
*/
export interface OnCreateOTTSuccessPayload {
/** The created OTT response containing the temporary token. */
token: CreateOTTResponse;
/** The payment amount. */
amount: number;
/** The shipping address and contact information, if provided. */
shipping?: Shipping;
/** The billing address, if provided. */
billing?: Billing;
}
/**
* Data emitted when the OTT (One-Time Token) creation is successful.
*/
export interface OnCreateOTTSuccessfulEventData extends OpenWalletDataEvent<OnCreateOTTSuccessPayload> {
event: EVENT.SUCCESS;
}
/**
* Payload for the OTT error event data.
*/
export interface OnCreateOTTErrorPayload {
/** Error message from the API. */
message?: string;
/** Error code from the API. */
code?: string;
}
/**
* Data emitted when the OTT creation fails.
*/
export interface OnCreateOTTErrorEventData extends OpenWalletDataEvent<OnCreateOTTErrorPayload> {
event: EVENT.ERROR;
}
/**
* Typed details for the unavailable event.
*/
export interface OnUnavailableDetails {
/** The service ID that was checked. */
service_id: string;
}
/**
* Payload for the onUnavailable event data.
*/
export interface OnUnavailablePayload {
/** A human-readable reason why the wallet is unavailable. */
reason: string;
/** Additional details about the unavailability. */
details?: OnUnavailableDetails;
}
/**
* Data emitted when the wallet is not available on the current device or browser.
*/
export interface OnUnavailableEventData extends OpenWalletDataEvent<OnUnavailablePayload> {
event: EVENT.UNAVAILABLE;
}
/**
* Payload for the onError event data.
*/
export interface OnErrorPayload {
/** The Error object describing what went wrong. */
error: Error;
/** Context about the error. */
context?: {
/** The operation that failed. */
operation?: ERROR_OPERATION;
};
}
/**
* Data emitted when an error occurs during wallet operation.
*/
export interface OnErrorEventData extends OpenWalletDataEvent<OnErrorPayload> {
event: EVENT.ERROR;
}
/**
* Data emitted when the wallet button has been loaded and rendered in the DOM.
* No payload — the specific wallet type is determined by the concrete button class.
*/
export interface OnLoadedEventData extends OpenWalletBaseEvent {
event: EVENT.LOADED;
}
/**
* Data emitted when the wallet checkout is cancelled or closed by the user.
* No payload — matches WalletButtonsExpress `OnCloseEventData` convention.
*/
export interface OnCancelEventData extends OpenWalletBaseEvent {
event: EVENT.CHECKOUT_CLOSE;
}
//# sourceMappingURL=events.interface.d.ts.map