@sunbay/checkout-sdk-protocol 0.0.1 → 0.0.3
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 +43 -0
- package/dist/index.cjs +16 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +232 -101
- package/dist/index.d.ts +232 -101
- package/dist/index.mjs +13 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +28 -30
package/dist/index.d.cts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Public protocol types (source of truth).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* checkout
|
|
6
|
-
*
|
|
4
|
+
* These types are public and shared by the merchant-side SDK (transport/CheckoutInstance/Element)
|
|
5
|
+
* and the checkout hosted-side synchronized copy. Fields align with the existing checkout backend
|
|
6
|
+
* types, but the public view (PublicSessionView) does **not** include sensitive/internal fields
|
|
7
|
+
* such as rsaPublicKey.
|
|
7
8
|
*/
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
* - `I` =
|
|
11
|
-
* - `S` =
|
|
12
|
-
* - `F` =
|
|
13
|
-
* - `R` =
|
|
10
|
+
* Transaction status (reuses the checkout backend TxnStatus verbatim, no translation).
|
|
11
|
+
* - `I` = unpaid / created (non-terminal)
|
|
12
|
+
* - `S` = succeeded (terminal)
|
|
13
|
+
* - `F` = failed (terminal)
|
|
14
|
+
* - `R` = requires redirect / processing (non-terminal)
|
|
14
15
|
*/
|
|
15
16
|
type TxnStatus = 'I' | 'S' | 'F' | 'R';
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
18
|
+
* Address information (aligned with the checkout backend AddressInfo fields).
|
|
19
|
+
* Non-sensitive data; allowed to be transmitted over the public protocol.
|
|
19
20
|
*/
|
|
20
21
|
interface AddressInfo {
|
|
21
22
|
country: string;
|
|
@@ -30,10 +31,10 @@ interface AddressInfo {
|
|
|
30
31
|
recipientName?: string;
|
|
31
32
|
phone?: string;
|
|
32
33
|
}
|
|
33
|
-
/**
|
|
34
|
+
/** Payment methods supported in the first phase. */
|
|
34
35
|
type PaymentMethod = 'card' | 'applePay' | 'googlePay';
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
+
* Public payment method view (only exposes method/type/name/logoUrl, no internal config).
|
|
37
38
|
*/
|
|
38
39
|
interface PublicPaymentMethod {
|
|
39
40
|
method: string;
|
|
@@ -41,15 +42,15 @@ interface PublicPaymentMethod {
|
|
|
41
42
|
name: string;
|
|
42
43
|
logoUrl: string;
|
|
43
44
|
}
|
|
44
|
-
/**
|
|
45
|
+
/** Public product line. */
|
|
45
46
|
interface PublicProductLine {
|
|
46
47
|
amount: number;
|
|
47
48
|
name: string;
|
|
48
49
|
num: string;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
52
|
+
* Public session view: amount / currency / products / collect flags / available payment methods /
|
|
53
|
+
* merchant info. Does **not** include sensitive or internal fields such as rsaPublicKey.
|
|
53
54
|
*/
|
|
54
55
|
interface PublicSessionView {
|
|
55
56
|
sessionId: string;
|
|
@@ -69,8 +70,8 @@ interface PublicSessionView {
|
|
|
69
70
|
merchantReturnUrl?: string;
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
|
-
*
|
|
73
|
-
* `pending`
|
|
73
|
+
* Four payment outcome states (spec 8.2).
|
|
74
|
+
* `pending` is non-terminal; consumers must not accept only the first result.
|
|
74
75
|
*/
|
|
75
76
|
type PaymentOutcome = {
|
|
76
77
|
status: 'succeeded';
|
|
@@ -89,14 +90,14 @@ type PaymentOutcome = {
|
|
|
89
90
|
operationId: string;
|
|
90
91
|
txnId?: string;
|
|
91
92
|
};
|
|
92
|
-
/**
|
|
93
|
+
/** Error categories (spec 5.4). */
|
|
93
94
|
type CheckoutErrorCategory = 'configuration' | 'validation' | 'network' | 'runtime' | 'payment';
|
|
94
95
|
/**
|
|
95
|
-
*
|
|
96
|
+
* Structured error (spec 5.4).
|
|
96
97
|
*/
|
|
97
98
|
interface CheckoutError {
|
|
98
99
|
code: string;
|
|
99
|
-
/**
|
|
100
|
+
/** Message for display. */
|
|
100
101
|
message: string;
|
|
101
102
|
category: CheckoutErrorCategory;
|
|
102
103
|
errorId: string;
|
|
@@ -105,75 +106,160 @@ interface CheckoutError {
|
|
|
105
106
|
traceId?: string;
|
|
106
107
|
}
|
|
107
108
|
/**
|
|
108
|
-
*
|
|
109
|
+
* Whitelisted design variables (mapped to the hosted-side `ThemeConfig`, reusing the existing
|
|
110
|
+
* `generateThemeStyles` and dark-mode derivation).
|
|
111
|
+
*
|
|
112
|
+
* All optional; values are color or length strings, and only enter `<style>` after being validated
|
|
113
|
+
* by the hosted-side whitelist validator. Property names use camelCase (e.g. `borderRadius`); the
|
|
114
|
+
* hosted side converts them to kebab-case.
|
|
115
|
+
*/
|
|
116
|
+
interface AppearanceVariables {
|
|
117
|
+
/** Primary color → `ThemeConfig.primary` (also drives ring). */
|
|
118
|
+
colorPrimary?: string;
|
|
119
|
+
/** Background color → background / card / popover. */
|
|
120
|
+
colorBackground?: string;
|
|
121
|
+
/** Text color → foreground. */
|
|
122
|
+
colorText?: string;
|
|
123
|
+
/** Border color → border / input. */
|
|
124
|
+
colorBorder?: string;
|
|
125
|
+
/** Danger color → destructive. */
|
|
126
|
+
colorDanger?: string;
|
|
127
|
+
/** Border radius → radius (length value). */
|
|
128
|
+
borderRadius?: string;
|
|
129
|
+
/** Font family → `:root` font-family (not part of `ThemeConfig`, injected separately). */
|
|
130
|
+
fontFamily?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Customizable element anchors for rules (semantic keys, corresponding to the hosted-side
|
|
134
|
+
* `data-sunbay-el`).
|
|
135
|
+
*
|
|
136
|
+
* Selectors are generated by the hosted side; merchants only provide semantic keys and selector
|
|
137
|
+
* strings are not accepted.
|
|
138
|
+
* - `'input'`: card number / expiry / CVV input fields;
|
|
139
|
+
* - `'input:focus'`: input focus state;
|
|
140
|
+
* - `'input:invalid'`: input error state (`[data-sunbay-invalid]`);
|
|
141
|
+
* - `'label'`: label text inside the iframe;
|
|
142
|
+
* - `'error'`: error text inside the iframe;
|
|
143
|
+
* - `'cardBrand'`: card brand icon container;
|
|
144
|
+
* - `'cvvIcon'`: CVV icon.
|
|
145
|
+
*/
|
|
146
|
+
type AppearanceRuleTarget = 'input' | 'input:focus' | 'input:invalid' | 'label' | 'error' | 'cardBrand' | 'cvvIcon';
|
|
147
|
+
/**
|
|
148
|
+
* A single rule: a mapping from whitelisted CSS properties (camelCase or kebab) to values.
|
|
149
|
+
*
|
|
150
|
+
* Both property names and values only enter `<style>` after hosted-side whitelist validation;
|
|
151
|
+
* non-whitelisted properties / invalid values are discarded.
|
|
152
|
+
*/
|
|
153
|
+
type AppearanceRuleStyle = Record<string, string>;
|
|
154
|
+
/**
|
|
155
|
+
* Appearance customization. Controlled in two layers: `variables` (whitelisted design variables for
|
|
156
|
+
* the overall style) + `rules` (controlled semantic selectors for fine-tuning key elements). Due to
|
|
157
|
+
* cross-origin iframes + PCI compliance, arbitrary CSS is **not** allowed.
|
|
158
|
+
*
|
|
159
|
+
* All text entering `<style>` is whitelist-validated by the hosted side throughout; appearance
|
|
160
|
+
* contains no card values / payment parameters.
|
|
109
161
|
*/
|
|
110
162
|
interface Appearance {
|
|
111
|
-
|
|
112
|
-
variables?:
|
|
163
|
+
/** Whitelisted design variables (overall style). */
|
|
164
|
+
variables?: AppearanceVariables;
|
|
165
|
+
/** Controlled semantic rules (fine-tuning key elements); keys limited to `AppearanceRuleTarget`. */
|
|
166
|
+
rules?: Partial<Record<AppearanceRuleTarget, AppearanceRuleStyle>>;
|
|
167
|
+
/**
|
|
168
|
+
* Color scheme preference.
|
|
169
|
+
* - `'light'`: light;
|
|
170
|
+
* - `'dark'`: dark;
|
|
171
|
+
* - `'auto'`: follow the system / host environment.
|
|
172
|
+
*
|
|
173
|
+
* The protocol layer only defines the type; the default semantics when omitted (the SDK defaults
|
|
174
|
+
* to `'light'`) are implemented by the consumer, and the protocol does not enforce a default
|
|
175
|
+
* value. A backward-compatible optional new field.
|
|
176
|
+
*/
|
|
177
|
+
colorScheme?: 'light' | 'dark' | 'auto';
|
|
113
178
|
}
|
|
114
179
|
/**
|
|
115
|
-
*
|
|
180
|
+
* Payment method filter configuration (spec 9: subtraction/ordering only, enabling new methods on
|
|
181
|
+
* the frontend is forbidden).
|
|
116
182
|
*/
|
|
117
183
|
interface PaymentMethodFilter {
|
|
118
|
-
/**
|
|
184
|
+
/** Payment methods to hide (method identifiers). */
|
|
119
185
|
hide?: string[];
|
|
120
|
-
/**
|
|
186
|
+
/** Display order (method identifiers). */
|
|
121
187
|
order?: string[];
|
|
122
188
|
}
|
|
123
|
-
/**
|
|
189
|
+
/** Mountable Element types (spec 6). */
|
|
124
190
|
type ElementType = 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address' | 'expressCheckout';
|
|
125
|
-
/** card Element
|
|
191
|
+
/** card Element options (spec 6). */
|
|
126
192
|
interface CardElementOptions {
|
|
127
193
|
showBillingAddress?: boolean;
|
|
128
194
|
showShippingAddress?: boolean;
|
|
129
195
|
showPostalCode?: boolean;
|
|
130
196
|
appearance?: Appearance;
|
|
131
197
|
}
|
|
132
|
-
/**
|
|
198
|
+
/** Split card field options (spec 6). */
|
|
133
199
|
interface CardFieldElementOptions {
|
|
134
200
|
appearance?: Appearance;
|
|
135
201
|
}
|
|
136
|
-
/** address Element
|
|
202
|
+
/** address Element options (spec 6). */
|
|
137
203
|
interface AddressElementOptions {
|
|
138
204
|
mode: 'billing' | 'shipping';
|
|
139
205
|
appearance?: Appearance;
|
|
140
206
|
}
|
|
141
|
-
/**
|
|
207
|
+
/** Apple Pay official button theme. Defaults to follow the current color scheme (light black / dark white). */
|
|
208
|
+
type ApplePayButtonTheme = 'black' | 'white' | 'white-outline';
|
|
209
|
+
/** Google Pay official button theme. Defaults to follow the current color scheme (light black / dark white). */
|
|
210
|
+
type GooglePayButtonTheme = 'black' | 'white' | 'default';
|
|
211
|
+
/** Apple Pay official button text type (the `type` attribute of `apple-pay-button`, full official set). */
|
|
212
|
+
type ApplePayButtonType = 'plain' | 'buy' | 'donate' | 'check-out' | 'book' | 'subscribe' | 'reload' | 'add-money' | 'top-up' | 'order' | 'rent' | 'support' | 'contribute' | 'tip';
|
|
213
|
+
/** Google Pay official button text type (`buttonType`, full official set). */
|
|
214
|
+
type GooglePayButtonType = 'buy' | 'plain' | 'checkout' | 'pay' | 'donate' | 'book' | 'order' | 'subscribe';
|
|
215
|
+
/** Apple Pay single-wallet options (fine-grained options when shown). */
|
|
216
|
+
interface ApplePayOptions {
|
|
217
|
+
/** Button theme; defaults to follow the current color scheme. */
|
|
218
|
+
buttonTheme?: ApplePayButtonTheme;
|
|
219
|
+
/** Button text type; defaults to `'pay'`. */
|
|
220
|
+
buttonType?: ApplePayButtonType;
|
|
221
|
+
}
|
|
222
|
+
/** Google Pay single-wallet options (fine-grained options when shown). */
|
|
223
|
+
interface GooglePayOptions {
|
|
224
|
+
/** Button theme; defaults to follow the current color scheme. */
|
|
225
|
+
buttonTheme?: GooglePayButtonTheme;
|
|
226
|
+
/** Button text type; defaults to `'pay'`. */
|
|
227
|
+
buttonType?: GooglePayButtonType;
|
|
228
|
+
}
|
|
229
|
+
/** expressCheckout Element options (spec 6). */
|
|
142
230
|
interface ExpressCheckoutElementOptions {
|
|
143
231
|
/**
|
|
144
|
-
*
|
|
145
|
-
* - `false
|
|
146
|
-
* - `true`
|
|
232
|
+
* Per-wallet toggle / configuration:
|
|
233
|
+
* - `false`: force-hide this wallet;
|
|
234
|
+
* - `true` or omitted: auto-show (backend business allows ∩ environment available), theme follows
|
|
235
|
+
* the current color scheme;
|
|
236
|
+
* - config object: auto-show, and apply the fine-grained config in the object (e.g. buttonTheme).
|
|
147
237
|
*/
|
|
148
238
|
paymentMethods?: {
|
|
149
|
-
applePay?: boolean;
|
|
150
|
-
googlePay?: boolean;
|
|
239
|
+
applePay?: boolean | ApplePayOptions;
|
|
240
|
+
googlePay?: boolean | GooglePayOptions;
|
|
151
241
|
};
|
|
152
|
-
/**
|
|
242
|
+
/** Layout constraints (first phase: maximum columns only). */
|
|
153
243
|
layout?: {
|
|
154
244
|
maxColumns?: number;
|
|
155
245
|
};
|
|
156
|
-
/**
|
|
157
|
-
buttonTheme?: {
|
|
158
|
-
applePay?: string;
|
|
159
|
-
googlePay?: string;
|
|
160
|
-
};
|
|
161
|
-
/** 按钮高度(像素)。 */
|
|
246
|
+
/** Wallet button height (pixels, applied globally to all wallet buttons). The hosted side clamps to [30, 64]; defaults to 40. */
|
|
162
247
|
buttonHeight?: number;
|
|
163
248
|
}
|
|
164
249
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
250
|
+
* Express available wallets view (spec 6).
|
|
251
|
+
* Indicates whether each wallet is available in the current environment; used as the payload for the
|
|
252
|
+
* express availability event.
|
|
167
253
|
*/
|
|
168
254
|
interface AvailableWallets {
|
|
169
255
|
applePay: boolean;
|
|
170
256
|
googlePay: boolean;
|
|
171
257
|
}
|
|
172
|
-
/** Element
|
|
258
|
+
/** Element options union (distinguished by type). */
|
|
173
259
|
type ElementOptions = CardElementOptions | CardFieldElementOptions | AddressElementOptions | ExpressCheckoutElementOptions;
|
|
174
|
-
/** Element
|
|
260
|
+
/** Element runtime state machine (spec 6). */
|
|
175
261
|
type ElementStatus = 'created' | 'loading' | 'ready' | 'destroyed' | 'loadError';
|
|
176
|
-
/** action
|
|
262
|
+
/** action payload (spec 8.3; qrCode/showContent reserved for the first phase). */
|
|
177
263
|
interface PaymentAction {
|
|
178
264
|
type: 'qrCode' | 'redirect' | 'showContent';
|
|
179
265
|
redirectUrl?: string;
|
|
@@ -182,33 +268,35 @@ interface PaymentAction {
|
|
|
182
268
|
}
|
|
183
269
|
|
|
184
270
|
/**
|
|
185
|
-
*
|
|
271
|
+
* Envelope and handshake contract (spec 5.1, source of truth).
|
|
186
272
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
273
|
+
* Protocol name `sunbay-checkout`, `major = 1`. This is a different protocol from the existing
|
|
274
|
+
* Native Bridge `{v:1,type,...}`; identical numbers do not imply compatibility.
|
|
189
275
|
*
|
|
190
|
-
* `encodeEnvelope`/`decodeEnvelope
|
|
191
|
-
*
|
|
192
|
-
*
|
|
276
|
+
* `encodeEnvelope`/`decodeEnvelope`: JSON serialization + minimal runtime structural validation
|
|
277
|
+
* (validates protocol/major/kind/required fields), throwing on invalid input. The decoder does
|
|
278
|
+
* **not** validate whether request.name is a known CommandName — an unknown name is still decoded
|
|
279
|
+
* as kind==='request' and rejected by the caller.
|
|
193
280
|
*/
|
|
194
281
|
|
|
195
|
-
/**
|
|
282
|
+
/** Protocol name constant. */
|
|
196
283
|
declare const PROTOCOL_NAME: "sunbay-checkout";
|
|
197
|
-
/**
|
|
284
|
+
/** Current major version. */
|
|
198
285
|
declare const PROTOCOL_MAJOR: 1;
|
|
199
286
|
/**
|
|
200
|
-
*
|
|
287
|
+
* Handshake message (spec 5.1). Broadcast first after the main iframe loads, when there is no
|
|
288
|
+
* checkoutId yet.
|
|
201
289
|
*/
|
|
202
290
|
type RuntimeHello = {
|
|
203
291
|
protocol: 'sunbay-checkout';
|
|
204
292
|
kind: 'hello';
|
|
205
293
|
runtimeId: string;
|
|
206
294
|
supportedMajorVersions: number[];
|
|
207
|
-
/**
|
|
295
|
+
/** First phase: ['card','splitCard','address','express','paymentMethodFilter']. */
|
|
208
296
|
capabilities: string[];
|
|
209
297
|
};
|
|
210
298
|
/**
|
|
211
|
-
*
|
|
299
|
+
* Public envelope after initialization (spec 5.1).
|
|
212
300
|
*/
|
|
213
301
|
type Envelope = {
|
|
214
302
|
protocol: 'sunbay-checkout';
|
|
@@ -238,28 +326,28 @@ type Envelope = {
|
|
|
238
326
|
operationId?: string;
|
|
239
327
|
payload: unknown;
|
|
240
328
|
});
|
|
241
|
-
/**
|
|
329
|
+
/** Protocol validation failure error. */
|
|
242
330
|
declare class EnvelopeDecodeError extends Error {
|
|
243
331
|
constructor(message: string);
|
|
244
332
|
}
|
|
245
333
|
/**
|
|
246
|
-
*
|
|
334
|
+
* Serialize an envelope into a wire string (JSON).
|
|
247
335
|
*
|
|
248
|
-
* @param envelope
|
|
249
|
-
* @returns JSON
|
|
336
|
+
* @param envelope The envelope to send
|
|
337
|
+
* @returns JSON string
|
|
250
338
|
* @example
|
|
251
339
|
* const wire = encodeEnvelope({ protocol: 'sunbay-checkout', major: 1, ... });
|
|
252
340
|
*/
|
|
253
341
|
declare function encodeEnvelope(envelope: Envelope): string;
|
|
254
342
|
/**
|
|
255
|
-
*
|
|
256
|
-
*
|
|
343
|
+
* Parse and minimally structurally validate an envelope. Invalid input (missing protocol, wrong
|
|
344
|
+
* major, invalid kind, missing required fields, non-JSON) always throws {@link EnvelopeDecodeError}.
|
|
257
345
|
*
|
|
258
|
-
*
|
|
259
|
-
* kind==='request'
|
|
346
|
+
* Note: the decoder does not validate whether request.name is a known command — an unknown name is
|
|
347
|
+
* still decoded as kind==='request' and left for the caller (e.g. the Orchestrator) to reject.
|
|
260
348
|
*
|
|
261
|
-
* @param wire
|
|
262
|
-
* @returns
|
|
349
|
+
* @param wire The wire string
|
|
350
|
+
* @returns The structurally validated envelope
|
|
263
351
|
* @example
|
|
264
352
|
* const env = decodeEnvelope(wire);
|
|
265
353
|
* if (env.kind === 'request') { ... }
|
|
@@ -267,10 +355,10 @@ declare function encodeEnvelope(envelope: Envelope): string;
|
|
|
267
355
|
declare function decodeEnvelope(wire: string): Envelope;
|
|
268
356
|
|
|
269
357
|
/**
|
|
270
|
-
*
|
|
358
|
+
* Protocol error code constants (single source of truth, spec 5.4).
|
|
271
359
|
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
360
|
+
* Does not provide a generic `retryable` boolean that could mislead into duplicate payments.
|
|
361
|
+
* Only keeps error codes that are actually produced; new codes must have a production point.
|
|
274
362
|
*/
|
|
275
363
|
declare const ErrorCode: {
|
|
276
364
|
readonly INVALID_OPTIONS: "INVALID_OPTIONS";
|
|
@@ -285,20 +373,21 @@ declare const ErrorCode: {
|
|
|
285
373
|
readonly PAYMENT_FLOW_ERROR: "PAYMENT_FLOW_ERROR";
|
|
286
374
|
readonly UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY";
|
|
287
375
|
};
|
|
288
|
-
/**
|
|
376
|
+
/** Error code literal union type. */
|
|
289
377
|
type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
290
378
|
|
|
291
379
|
/**
|
|
292
|
-
*
|
|
380
|
+
* Command contract (merchant SDK → main, spec 5.2 table, source of truth).
|
|
293
381
|
*
|
|
294
|
-
*
|
|
382
|
+
* The request/response types for each command are defined here; only JSON-serializable data is sent
|
|
383
|
+
* across the channel.
|
|
295
384
|
*/
|
|
296
385
|
|
|
297
|
-
/**
|
|
386
|
+
/** All command names (spec 5.2). */
|
|
298
387
|
type CommandName = 'initialize' | 'createElement' | 'updateElement' | 'destroyElement' | 'focus' | 'blur' | 'clear' | 'updateCheckout' | 'getSession' | 'refresh' | 'getPaymentStatus' | 'confirm' | 'destroy';
|
|
299
|
-
/**
|
|
388
|
+
/** Set of known command names (for callers to validate whether request.name is supported). */
|
|
300
389
|
declare const COMMAND_NAMES: readonly CommandName[];
|
|
301
|
-
/**
|
|
390
|
+
/** Determine whether a string is a known command name. */
|
|
302
391
|
declare function isCommandName(name: string): name is CommandName;
|
|
303
392
|
interface InitializeReq {
|
|
304
393
|
sessionId: string;
|
|
@@ -370,7 +459,7 @@ type DestroyReq = Record<string, never>;
|
|
|
370
459
|
interface DestroyResp {
|
|
371
460
|
released: true;
|
|
372
461
|
}
|
|
373
|
-
/**
|
|
462
|
+
/** Command name → request payload mapping. */
|
|
374
463
|
interface CommandRequestMap {
|
|
375
464
|
initialize: InitializeReq;
|
|
376
465
|
createElement: CreateElementReq;
|
|
@@ -386,7 +475,7 @@ interface CommandRequestMap {
|
|
|
386
475
|
confirm: ConfirmReq;
|
|
387
476
|
destroy: DestroyReq;
|
|
388
477
|
}
|
|
389
|
-
/**
|
|
478
|
+
/** Command name → success response payload mapping. */
|
|
390
479
|
interface CommandResponseMap {
|
|
391
480
|
initialize: InitializeResp;
|
|
392
481
|
createElement: CreateElementResp;
|
|
@@ -404,24 +493,25 @@ interface CommandResponseMap {
|
|
|
404
493
|
}
|
|
405
494
|
|
|
406
495
|
/**
|
|
407
|
-
*
|
|
496
|
+
* Event contract (main → merchant SDK, spec 5.3 table, source of truth).
|
|
408
497
|
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
498
|
+
* Public events only expose allowed states such as empty/complete/brand/error, and **never contain
|
|
499
|
+
* card values**; no card-data getValue is provided. After `on` registration, historical events are
|
|
500
|
+
* not replayed.
|
|
411
501
|
*/
|
|
412
502
|
|
|
413
|
-
/**
|
|
414
|
-
type EventName = 'ready' | 'change' | 'focus' | 'blur' | 'loadError' | 'elementReady' | '
|
|
415
|
-
/**
|
|
503
|
+
/** All event names (spec 5.3). */
|
|
504
|
+
type EventName = 'ready' | 'change' | 'focus' | 'blur' | 'loadError' | 'elementReady' | 'expressAvailabilityChange' | 'paymentStateChange' | 'paymentResult' | 'error';
|
|
505
|
+
/** Set of known event names. */
|
|
416
506
|
declare const EVENT_NAMES: readonly EventName[];
|
|
417
|
-
/**
|
|
507
|
+
/** Determine whether a string is a known event name. */
|
|
418
508
|
declare function isEventName(name: string): name is EventName;
|
|
419
509
|
interface ReadyEvent {
|
|
420
510
|
elementId: string;
|
|
421
511
|
}
|
|
422
512
|
interface ElementReadyEvent {
|
|
423
513
|
elementId: string;
|
|
424
|
-
/**
|
|
514
|
+
/** Only carried when the expressCheckout Element is ready: per-wallet availability. */
|
|
425
515
|
availableWallets?: AvailableWallets;
|
|
426
516
|
}
|
|
427
517
|
interface ChangeEvent {
|
|
@@ -429,7 +519,7 @@ interface ChangeEvent {
|
|
|
429
519
|
empty: boolean;
|
|
430
520
|
complete: boolean;
|
|
431
521
|
error?: CheckoutError;
|
|
432
|
-
/**
|
|
522
|
+
/** Only the card number field may carry brand; never contains card values. */
|
|
433
523
|
brand?: string;
|
|
434
524
|
}
|
|
435
525
|
interface FocusEvent {
|
|
@@ -442,13 +532,10 @@ interface LoadErrorEvent {
|
|
|
442
532
|
elementId: string;
|
|
443
533
|
error: CheckoutError;
|
|
444
534
|
}
|
|
445
|
-
interface AvailablePaymentMethodsChangeEvent {
|
|
446
|
-
availablePaymentMethods: PublicPaymentMethod[];
|
|
447
|
-
}
|
|
448
535
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
536
|
+
* Express available-wallets change event (spec 6).
|
|
537
|
+
* Dedicated to expressCheckout: uses AvailableWallets to express the availability of each wallet
|
|
538
|
+
* (Apple/Google Pay).
|
|
452
539
|
*/
|
|
453
540
|
interface ExpressAvailabilityChangeEvent {
|
|
454
541
|
availableWallets: AvailableWallets;
|
|
@@ -456,7 +543,7 @@ interface ExpressAvailabilityChangeEvent {
|
|
|
456
543
|
interface PaymentStateChangeEvent {
|
|
457
544
|
operationId: string;
|
|
458
545
|
method: PaymentMethod;
|
|
459
|
-
/**
|
|
546
|
+
/** Intermediate state; carries action info when requiresAction. */
|
|
460
547
|
state: string;
|
|
461
548
|
action?: PaymentAction;
|
|
462
549
|
}
|
|
@@ -466,11 +553,11 @@ interface PaymentResultEvent {
|
|
|
466
553
|
outcome: PaymentOutcome;
|
|
467
554
|
}
|
|
468
555
|
interface ErrorEvent {
|
|
469
|
-
/**
|
|
556
|
+
/** Error in an asynchronous proactive flow; may include operationId (if already created). */
|
|
470
557
|
operationId?: string;
|
|
471
558
|
error: CheckoutError;
|
|
472
559
|
}
|
|
473
|
-
/**
|
|
560
|
+
/** Event name → payload mapping. */
|
|
474
561
|
interface EventPayloadMap {
|
|
475
562
|
ready: ReadyEvent;
|
|
476
563
|
change: ChangeEvent;
|
|
@@ -478,11 +565,55 @@ interface EventPayloadMap {
|
|
|
478
565
|
blur: BlurEvent;
|
|
479
566
|
loadError: LoadErrorEvent;
|
|
480
567
|
elementReady: ElementReadyEvent;
|
|
481
|
-
availablePaymentMethodsChange: AvailablePaymentMethodsChangeEvent;
|
|
482
568
|
expressAvailabilityChange: ExpressAvailabilityChangeEvent;
|
|
483
569
|
paymentStateChange: PaymentStateChangeEvent;
|
|
484
570
|
paymentResult: PaymentResultEvent;
|
|
485
571
|
error: ErrorEvent;
|
|
486
572
|
}
|
|
487
573
|
|
|
488
|
-
|
|
574
|
+
/**
|
|
575
|
+
* iframe layout protocol: the **direct postMessage** contract from the hosted iframe (checkout,
|
|
576
|
+
* child) → parent window (merchant SDK, parent), used for iframe auto-height.
|
|
577
|
+
*
|
|
578
|
+
* Distinct from both the outer Envelope (merchant SDK ↔ main iframe) and the inner point-to-point
|
|
579
|
+
* port (element ↔ main): this message is posted directly by each visible field / element iframe to
|
|
580
|
+
* its `window.parent` (the merchant page), and the merchant SDK's Element handle listens for it and
|
|
581
|
+
* adjusts the outer iframe height to the real content height (width stays 100%).
|
|
582
|
+
*
|
|
583
|
+
* Security constraint (AGENTS/spec): this message **never contains any card value** (plaintext or
|
|
584
|
+
* ciphertext); it only carries height and elementId. The parent-window side must validate the
|
|
585
|
+
* source (`event.source === iframe.contentWindow` and `event.origin === hostOrigin`) before
|
|
586
|
+
* trusting it, to prevent cross-origin forgery.
|
|
587
|
+
*/
|
|
588
|
+
/** Discriminant literal for the iframe auto-height message (namespaced to avoid colliding with other postMessages). */
|
|
589
|
+
declare const IFRAME_RESIZE_MESSAGE_TYPE: "sunbay:checkout:iframe-resize";
|
|
590
|
+
/**
|
|
591
|
+
* Content height change notification from the iframe (child) → parent window (SDK).
|
|
592
|
+
*
|
|
593
|
+
* The child observes content height with a `ResizeObserver` and sends on change (deduplicated); the
|
|
594
|
+
* parent sets `iframe.style.height` accordingly. Never contains card values.
|
|
595
|
+
*/
|
|
596
|
+
interface IframeResizeMessage {
|
|
597
|
+
/** Discriminant field, fixed to {@link IFRAME_RESIZE_MESSAGE_TYPE}. */
|
|
598
|
+
type: typeof IFRAME_RESIZE_MESSAGE_TYPE;
|
|
599
|
+
/**
|
|
600
|
+
* The unique id of the target Element. Passed down by the merchant SDK via the iframe src's
|
|
601
|
+
* `&elementId=`, echoed back verbatim by the child, so the parent window can dispatch by handle
|
|
602
|
+
* among multiple iframes on the same page.
|
|
603
|
+
*/
|
|
604
|
+
elementId: string;
|
|
605
|
+
/** Content height (CSS px, already `Math.ceil`-ed; finite and non-negative). */
|
|
606
|
+
height: number;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Whether the value is a valid {@link IframeResizeMessage}.
|
|
610
|
+
*
|
|
611
|
+
* Validates: non-null object + type literal match + elementId is a non-empty string + height is a
|
|
612
|
+
* finite non-negative number.
|
|
613
|
+
*
|
|
614
|
+
* @param data - Data from any source (typically `MessageEvent.data`).
|
|
615
|
+
* @returns Whether data is a valid iframe-resize message.
|
|
616
|
+
*/
|
|
617
|
+
declare function isIframeResizeMessage(data: unknown): data is IframeResizeMessage;
|
|
618
|
+
|
|
619
|
+
export { type AddressElementOptions, type AddressInfo, type Appearance, type AppearanceRuleStyle, type AppearanceRuleTarget, type AppearanceVariables, type ApplePayButtonTheme, type ApplePayButtonType, type ApplePayOptions, type AvailableWallets, type BlurEvent, COMMAND_NAMES, type CardElementOptions, type CardFieldElementOptions, type ChangeEvent, type CheckoutError, type CheckoutErrorCategory, type CommandName, type CommandRequestMap, type CommandResponseMap, type ConfirmReq, type ConfirmResp, type CreateElementReq, type CreateElementResp, type DestroyElementReq, type DestroyElementResp, type DestroyReq, type DestroyResp, EVENT_NAMES, type ElementActionReq, type ElementActionResp, type ElementOptions, type ElementReadyEvent, type ElementStatus, type ElementType, type Envelope, EnvelopeDecodeError, ErrorCode, type ErrorCodeValue, type ErrorEvent, type EventName, type EventPayloadMap, type ExpressAvailabilityChangeEvent, type ExpressCheckoutElementOptions, type FocusEvent, type GetPaymentStatusReq, type GetPaymentStatusResp, type GetSessionReq, type GetSessionResp, type GooglePayButtonTheme, type GooglePayButtonType, type GooglePayOptions, IFRAME_RESIZE_MESSAGE_TYPE, type IframeResizeMessage, type InitializeReq, type InitializeResp, type LoadErrorEvent, PROTOCOL_MAJOR, PROTOCOL_NAME, type PaymentAction, type PaymentMethod, type PaymentMethodFilter, type PaymentOutcome, type PaymentResultEvent, type PaymentStateChangeEvent, type PublicPaymentMethod, type PublicProductLine, type PublicSessionView, type ReadyEvent, type RuntimeHello, type TxnStatus, type UpdateCheckoutReq, type UpdateCheckoutResp, type UpdateElementReq, type UpdateElementResp, decodeEnvelope, encodeEnvelope, isCommandName, isEventName, isIframeResizeMessage };
|