forked from tebexio/Tebex.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.d.ts
More file actions
159 lines (159 loc) · 5.41 KB
/
checkout.d.ts
File metadata and controls
159 lines (159 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/// <reference path="../../src/types/zoid.d.ts" />
import { type ZoidComponent, type ZoidComponentInstance } from "zoid";
import { type Unsubscribe } from "nanoevents";
import { type TebexColorConfig, type TebexColorDefinition, type TebexTheme } from "./common";
import { Lightbox } from "./components/lightbox";
import { type CssDimension, type Implements } from "./utils";
export declare const THEME_NAMES: readonly ["auto", "default", "light", "dark"];
export declare const COLOR_NAMES: readonly ["primary", "secondary", "background", "surface", "surface-variant", "success", "warning", "error", "green", "red", "fields", "field-border"];
export declare const EVENT_NAMES: readonly ["open", "close", "payment:complete", "payment:error"];
/**
* Configuration options for `Tebex.checkout.init()`.
*/
export type CheckoutOptions = {
/**
* The checkout request ident received from either the Headless or Checkout APIs.
*/
ident: string;
/**
* The default language to use, defined as an ISO locale code - e.g. `"en_US"` for American English, "de_DE" for German, etc.
* @default `navigator.language`
*/
locale?: string;
/**
* Tebex checkout panel color theme.
* @default "light"
*/
theme?: TebexTheme;
/**
* Tebex checkout panel UI brand colors.
* @default []
*/
colors?: TebexColorConfig;
/**
* Whether to close the Tebex.js popup when the user clicks outside of the modal.
* @default false
*/
closeOnClickOutside?: boolean;
/**
* Whether to close the Tebex.js popup when the user presses the Escape key.
* @default false
*/
closeOnEsc?: boolean;
/**
* Whether to automatically close the Tebex.js popup as soon as the payment is completed; `payment:complete` and `close` events will still be emitted.
* @default false
*/
closeOnPaymentComplete?: boolean;
/**
* Select a payment method to highlight on the checkout by passing its ident.
* @default undefined
*/
defaultPaymentMethod?: string;
/**
* Whether to still display a popup on mobile or not. If `false` or undefined, then calling `launch()` will open a new window on mobile devices.
* @default false
*/
popupOnMobile?: boolean;
/**
* API endpoint to use. Do not change this unless otherwise guided to do so.
* @default ""
* @internal
*/
endpoint?: string;
};
/**
* Checkout event type. You can subscribe to checkout events with `Tebex.checkout.on()`.
*/
export type CheckoutEvent = typeof EVENT_NAMES[number];
/**
* Maps a {@link CheckoutEvent} to its event callback type.
*/
export type CheckoutEventMap = Implements<Record<CheckoutEvent, Function>, {
"open": () => void;
"close": () => void;
"payment:complete": (e: Event) => void;
"payment:error": (e: Event) => void;
}>;
/**
* Props passed through Zoid component.
* @internal
*/
export type CheckoutZoidProps = {
locale: string;
colors: TebexColorConfig;
closeOnClickOutside: boolean;
closeOnEsc: boolean;
closeOnPaymentComplete: boolean;
defaultPaymentMethod?: string;
theme: TebexTheme;
onOpenWindow: (url: string) => void;
onClosePopup: () => Promise<void>;
onPaymentComplete: (e: any) => void;
onPaymentError: (e: any) => void;
isApplePayAvailable: boolean;
isEmbedded: boolean;
referrer: string;
origin: string;
path: string;
params: string;
version: string;
};
/**
* Tebex checkout instance.
*/
export default class Checkout {
#private;
ident: string;
locale: string;
theme: TebexTheme;
colors: TebexColorDefinition[];
closeOnClickOutside: boolean;
closeOnEsc: boolean;
closeOnPaymentComplete: boolean;
defaultPaymentMethod?: string;
popupOnMobile: boolean;
endpoint: string;
isOpen: boolean;
emitter: import("nanoevents").Emitter<{
open: () => void;
close: () => void;
"payment:complete": (e: Event) => void;
"payment:error": (e: Event) => void;
}>;
lightbox: Lightbox;
componentFactory: ZoidComponent<CheckoutZoidProps>;
zoid: ZoidComponentInstance;
/**
* Configure the Tebex checkout settings.
*/
init(options: CheckoutOptions): void;
/**
* Subscribe to Tebex checkout events, such as when the embed is closed or when a payment is completed.
* NOTE: None of these events should not be used to confirm actual receipt of payment - you should use Webhooks for that.
*/
on<T extends CheckoutEvent>(event: T, callback: CheckoutEventMap[T]): Unsubscribe;
/**
* Launch the Tebex checkout panel.
* On desktop, the panel will launch in a "lightbox" mode that covers the screen. On mobile, it will be opened as a new page.
*/
launch(): Promise<void>;
/**
* Close the Tebex checkout panel.
*/
close(): Promise<void>;
/**
* Close and destroy the element immediately, without waiting for CSS transitions.
*/
destroy(): void;
/**
* Render the Tebex checkout panel immediately, into a specified HTML element.
* If `popupOnMobile` is true, then on mobile devices the checkout will be immediately opened as a new page instead.
*/
render(element: HTMLElement, width: CssDimension, height: CssDimension, popupOnMobile?: boolean): Promise<void>;
/**
* Await internal Zoid render tests - primarily exposed for tests.
* @internal
*/
renderFinished(): Promise<void>;
}