@sunbay/checkout-sdk-protocol 0.0.0-stage → 0.0.1
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/dist/index.cjs +189 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +488 -0
- package/dist/index.d.ts +488 -0
- package/dist/index.mjs +153 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -5
- package/README.md +0 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 协议公开类型(真源)。
|
|
3
|
+
*
|
|
4
|
+
* 这些类型对外公开,供商户侧 SDK(transport/CheckoutInstance/Element)与
|
|
5
|
+
* checkout 托管侧同步副本共同引用。字段与 checkout 后端现有类型对齐,但
|
|
6
|
+
* 对外视图(PublicSessionView)**不含** rsaPublicKey 等敏感/内部字段。
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 交易状态(直接复用 checkout 后端 TxnStatus,不转义)。
|
|
10
|
+
* - `I` = 未支付 / 已创建(非终态)
|
|
11
|
+
* - `S` = 成功(终态)
|
|
12
|
+
* - `F` = 失败(终态)
|
|
13
|
+
* - `R` = 需跳转 / 处理中(非终态)
|
|
14
|
+
*/
|
|
15
|
+
type TxnStatus = 'I' | 'S' | 'F' | 'R';
|
|
16
|
+
/**
|
|
17
|
+
* 地址信息(对齐 checkout 后端 AddressInfo 字段)。
|
|
18
|
+
* 非敏感数据,允许经公共协议传输。
|
|
19
|
+
*/
|
|
20
|
+
interface AddressInfo {
|
|
21
|
+
country: string;
|
|
22
|
+
state?: string;
|
|
23
|
+
city: string;
|
|
24
|
+
line1: string;
|
|
25
|
+
line2?: string;
|
|
26
|
+
postalCode: string;
|
|
27
|
+
district?: string;
|
|
28
|
+
firstName?: string;
|
|
29
|
+
lastName?: string;
|
|
30
|
+
recipientName?: string;
|
|
31
|
+
phone?: string;
|
|
32
|
+
}
|
|
33
|
+
/** 首期支持的支付方式。 */
|
|
34
|
+
type PaymentMethod = 'card' | 'applePay' | 'googlePay';
|
|
35
|
+
/**
|
|
36
|
+
* 公开支付方式视图(对外只暴露 method/type/name/logoUrl,不含内部配置)。
|
|
37
|
+
*/
|
|
38
|
+
interface PublicPaymentMethod {
|
|
39
|
+
method: string;
|
|
40
|
+
type: string;
|
|
41
|
+
name: string;
|
|
42
|
+
logoUrl: string;
|
|
43
|
+
}
|
|
44
|
+
/** 公开商品行。 */
|
|
45
|
+
interface PublicProductLine {
|
|
46
|
+
amount: number;
|
|
47
|
+
name: string;
|
|
48
|
+
num: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 公开 Session 视图:金额 / 币种 / 商品 / collect 标记 / 可用支付方式 / 商户信息。
|
|
52
|
+
* **不含** rsaPublicKey 等敏感或内部字段。
|
|
53
|
+
*/
|
|
54
|
+
interface PublicSessionView {
|
|
55
|
+
sessionId: string;
|
|
56
|
+
sessionType: string;
|
|
57
|
+
currency: string;
|
|
58
|
+
totalAmount: number;
|
|
59
|
+
productList: PublicProductLine[];
|
|
60
|
+
taxAmount: number;
|
|
61
|
+
productAmount: number;
|
|
62
|
+
description: string;
|
|
63
|
+
expiresAt: string;
|
|
64
|
+
collectBillingAddress: boolean;
|
|
65
|
+
collectShippingAddress: boolean;
|
|
66
|
+
paymentMethods: PublicPaymentMethod[];
|
|
67
|
+
merchantName: string;
|
|
68
|
+
merchantLogoUrl: string;
|
|
69
|
+
merchantReturnUrl?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 支付结果四态(spec 8.2)。
|
|
73
|
+
* `pending` 非终态,消费者不得只接受首条结果。
|
|
74
|
+
*/
|
|
75
|
+
type PaymentOutcome = {
|
|
76
|
+
status: 'succeeded';
|
|
77
|
+
operationId: string;
|
|
78
|
+
txnId: string;
|
|
79
|
+
} | {
|
|
80
|
+
status: 'failed';
|
|
81
|
+
operationId: string;
|
|
82
|
+
txnId?: string;
|
|
83
|
+
error: CheckoutError;
|
|
84
|
+
} | {
|
|
85
|
+
status: 'canceled';
|
|
86
|
+
operationId: string;
|
|
87
|
+
} | {
|
|
88
|
+
status: 'pending';
|
|
89
|
+
operationId: string;
|
|
90
|
+
txnId?: string;
|
|
91
|
+
};
|
|
92
|
+
/** 错误分类(spec 5.4)。 */
|
|
93
|
+
type CheckoutErrorCategory = 'configuration' | 'validation' | 'network' | 'runtime' | 'payment';
|
|
94
|
+
/**
|
|
95
|
+
* 结构化错误(spec 5.4)。
|
|
96
|
+
*/
|
|
97
|
+
interface CheckoutError {
|
|
98
|
+
code: string;
|
|
99
|
+
/** 展示用消息。 */
|
|
100
|
+
message: string;
|
|
101
|
+
category: CheckoutErrorCategory;
|
|
102
|
+
errorId: string;
|
|
103
|
+
elementId?: string;
|
|
104
|
+
field?: string;
|
|
105
|
+
traceId?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 外观定制(appearance)。首期为开放映射,交由托管侧解释。
|
|
109
|
+
*/
|
|
110
|
+
interface Appearance {
|
|
111
|
+
theme?: string;
|
|
112
|
+
variables?: Record<string, string>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 支付方式过滤配置(spec 9:只做减法/排序,禁止前端增开)。
|
|
116
|
+
*/
|
|
117
|
+
interface PaymentMethodFilter {
|
|
118
|
+
/** 要隐藏的支付方式(method 标识)。 */
|
|
119
|
+
hide?: string[];
|
|
120
|
+
/** 展示顺序(method 标识)。 */
|
|
121
|
+
order?: string[];
|
|
122
|
+
}
|
|
123
|
+
/** 可挂载 Element 类型(spec 6)。 */
|
|
124
|
+
type ElementType = 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address' | 'expressCheckout';
|
|
125
|
+
/** card Element 配置(spec 6)。 */
|
|
126
|
+
interface CardElementOptions {
|
|
127
|
+
showBillingAddress?: boolean;
|
|
128
|
+
showShippingAddress?: boolean;
|
|
129
|
+
showPostalCode?: boolean;
|
|
130
|
+
appearance?: Appearance;
|
|
131
|
+
}
|
|
132
|
+
/** 拆分卡字段配置(spec 6)。 */
|
|
133
|
+
interface CardFieldElementOptions {
|
|
134
|
+
appearance?: Appearance;
|
|
135
|
+
}
|
|
136
|
+
/** address Element 配置(spec 6)。 */
|
|
137
|
+
interface AddressElementOptions {
|
|
138
|
+
mode: 'billing' | 'shipping';
|
|
139
|
+
appearance?: Appearance;
|
|
140
|
+
}
|
|
141
|
+
/** expressCheckout Element 配置(spec 6)。 */
|
|
142
|
+
interface ExpressCheckoutElementOptions {
|
|
143
|
+
/**
|
|
144
|
+
* 各钱包开关(商户显式控制):
|
|
145
|
+
* - `false`:强制隐藏该钱包;
|
|
146
|
+
* - `true` 或缺省:自动模式,按后端业务允许 ∩ 环境可用展示。
|
|
147
|
+
*/
|
|
148
|
+
paymentMethods?: {
|
|
149
|
+
applePay?: boolean;
|
|
150
|
+
googlePay?: boolean;
|
|
151
|
+
};
|
|
152
|
+
/** 布局约束(首期仅最大列数)。 */
|
|
153
|
+
layout?: {
|
|
154
|
+
maxColumns?: number;
|
|
155
|
+
};
|
|
156
|
+
/** 按钮主题(按钱包区分)。 */
|
|
157
|
+
buttonTheme?: {
|
|
158
|
+
applePay?: string;
|
|
159
|
+
googlePay?: string;
|
|
160
|
+
};
|
|
161
|
+
/** 按钮高度(像素)。 */
|
|
162
|
+
buttonHeight?: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* express 可用钱包视图(spec 6)。
|
|
166
|
+
* 表示各钱包在当前环境下是否可用,用于 express 可用性事件载荷。
|
|
167
|
+
*/
|
|
168
|
+
interface AvailableWallets {
|
|
169
|
+
applePay: boolean;
|
|
170
|
+
googlePay: boolean;
|
|
171
|
+
}
|
|
172
|
+
/** Element 配置联合(按 type 区分)。 */
|
|
173
|
+
type ElementOptions = CardElementOptions | CardFieldElementOptions | AddressElementOptions | ExpressCheckoutElementOptions;
|
|
174
|
+
/** Element 运行状态机(spec 6)。 */
|
|
175
|
+
type ElementStatus = 'created' | 'loading' | 'ready' | 'destroyed' | 'loadError';
|
|
176
|
+
/** action 载荷(spec 8.3;qrCode/showContent 首期预留)。 */
|
|
177
|
+
interface PaymentAction {
|
|
178
|
+
type: 'qrCode' | 'redirect' | 'showContent';
|
|
179
|
+
redirectUrl?: string;
|
|
180
|
+
qrData?: string;
|
|
181
|
+
content?: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 信封与握手契约(spec 5.1,真源)。
|
|
186
|
+
*
|
|
187
|
+
* 协议名 `sunbay-checkout`,`major = 1`。与现有 Native Bridge `{v:1,type,...}`
|
|
188
|
+
* 是不同协议,数字相同不代表兼容。
|
|
189
|
+
*
|
|
190
|
+
* `encodeEnvelope`/`decodeEnvelope`:JSON 序列化 + 最小运行时结构校验
|
|
191
|
+
* (校验 protocol/major/kind/必填字段),非法抛错。解码器**不**校验 request.name
|
|
192
|
+
* 是否为已知 CommandName —— 未知 name 仍解为 kind==='request',由调用方拒绝。
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
/** 协议名常量。 */
|
|
196
|
+
declare const PROTOCOL_NAME: "sunbay-checkout";
|
|
197
|
+
/** 当前主版本。 */
|
|
198
|
+
declare const PROTOCOL_MAJOR: 1;
|
|
199
|
+
/**
|
|
200
|
+
* 握手消息(spec 5.1)。main iframe 加载后先广播,此时尚无 checkoutId。
|
|
201
|
+
*/
|
|
202
|
+
type RuntimeHello = {
|
|
203
|
+
protocol: 'sunbay-checkout';
|
|
204
|
+
kind: 'hello';
|
|
205
|
+
runtimeId: string;
|
|
206
|
+
supportedMajorVersions: number[];
|
|
207
|
+
/** 首期:['card','splitCard','address','express','paymentMethodFilter']。 */
|
|
208
|
+
capabilities: string[];
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* 初始化后的公共信封(spec 5.1)。
|
|
212
|
+
*/
|
|
213
|
+
type Envelope = {
|
|
214
|
+
protocol: 'sunbay-checkout';
|
|
215
|
+
major: 1;
|
|
216
|
+
runtimeId: string;
|
|
217
|
+
checkoutId: string;
|
|
218
|
+
elementId?: string;
|
|
219
|
+
} & ({
|
|
220
|
+
kind: 'request';
|
|
221
|
+
requestId: string;
|
|
222
|
+
name: string;
|
|
223
|
+
payload: unknown;
|
|
224
|
+
} | {
|
|
225
|
+
kind: 'response';
|
|
226
|
+
requestId: string;
|
|
227
|
+
ok: true;
|
|
228
|
+
data: unknown;
|
|
229
|
+
} | {
|
|
230
|
+
kind: 'response';
|
|
231
|
+
requestId: string;
|
|
232
|
+
ok: false;
|
|
233
|
+
error: CheckoutError;
|
|
234
|
+
} | {
|
|
235
|
+
kind: 'event';
|
|
236
|
+
eventId: string;
|
|
237
|
+
name: string;
|
|
238
|
+
operationId?: string;
|
|
239
|
+
payload: unknown;
|
|
240
|
+
});
|
|
241
|
+
/** 协议校验失败错误。 */
|
|
242
|
+
declare class EnvelopeDecodeError extends Error {
|
|
243
|
+
constructor(message: string);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* 将信封序列化为线缆字符串(JSON)。
|
|
247
|
+
*
|
|
248
|
+
* @param envelope 待发送的信封
|
|
249
|
+
* @returns JSON 字符串
|
|
250
|
+
* @example
|
|
251
|
+
* const wire = encodeEnvelope({ protocol: 'sunbay-checkout', major: 1, ... });
|
|
252
|
+
*/
|
|
253
|
+
declare function encodeEnvelope(envelope: Envelope): string;
|
|
254
|
+
/**
|
|
255
|
+
* 解析并最小结构校验信封。非法(缺 protocol、错 major、非法 kind、缺必填字段、
|
|
256
|
+
* 非 JSON)一律抛 {@link EnvelopeDecodeError}。
|
|
257
|
+
*
|
|
258
|
+
* 注意:解码器不校验 request.name 是否为已知命令 —— 未知 name 仍解为
|
|
259
|
+
* kind==='request',交由调用方(如 Orchestrator)拒绝。
|
|
260
|
+
*
|
|
261
|
+
* @param wire 线缆字符串
|
|
262
|
+
* @returns 已校验结构的信封
|
|
263
|
+
* @example
|
|
264
|
+
* const env = decodeEnvelope(wire);
|
|
265
|
+
* if (env.kind === 'request') { ... }
|
|
266
|
+
*/
|
|
267
|
+
declare function decodeEnvelope(wire: string): Envelope;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* 协议错误码常量(单一真源,spec 5.4)。
|
|
271
|
+
*
|
|
272
|
+
* 不提供可能误导重复付款的通用 `retryable` 布尔。
|
|
273
|
+
* 仅保留实际会被产出的错误码;新增码须同时有产出点。
|
|
274
|
+
*/
|
|
275
|
+
declare const ErrorCode: {
|
|
276
|
+
readonly INVALID_OPTIONS: "INVALID_OPTIONS";
|
|
277
|
+
readonly ELEMENT_CONFLICT: "ELEMENT_CONFLICT";
|
|
278
|
+
readonly INSTANCE_DESTROYED: "INSTANCE_DESTROYED";
|
|
279
|
+
readonly CHECKOUT_BUSY: "CHECKOUT_BUSY";
|
|
280
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
281
|
+
readonly SESSION_LOAD_FAILED: "SESSION_LOAD_FAILED";
|
|
282
|
+
readonly RUNTIME_LOAD_FAILED: "RUNTIME_LOAD_FAILED";
|
|
283
|
+
readonly PROTOCOL_UNSUPPORTED: "PROTOCOL_UNSUPPORTED";
|
|
284
|
+
readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
|
|
285
|
+
readonly PAYMENT_FLOW_ERROR: "PAYMENT_FLOW_ERROR";
|
|
286
|
+
readonly UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY";
|
|
287
|
+
};
|
|
288
|
+
/** 错误码字面量联合类型。 */
|
|
289
|
+
type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 命令契约(商户 SDK → main,spec 5.2 表,真源)。
|
|
293
|
+
*
|
|
294
|
+
* 每命令的请求/响应类型在此定义;跨通道只传 JSON 可序列化数据。
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
/** 全部命令名(spec 5.2)。 */
|
|
298
|
+
type CommandName = 'initialize' | 'createElement' | 'updateElement' | 'destroyElement' | 'focus' | 'blur' | 'clear' | 'updateCheckout' | 'getSession' | 'refresh' | 'getPaymentStatus' | 'confirm' | 'destroy';
|
|
299
|
+
/** 已知命令名集合(供调用方校验 request.name 是否受支持)。 */
|
|
300
|
+
declare const COMMAND_NAMES: readonly CommandName[];
|
|
301
|
+
/** 判断字符串是否为已知命令名。 */
|
|
302
|
+
declare function isCommandName(name: string): name is CommandName;
|
|
303
|
+
interface InitializeReq {
|
|
304
|
+
sessionId: string;
|
|
305
|
+
locale?: string;
|
|
306
|
+
appearance?: Appearance;
|
|
307
|
+
paymentMethods?: PaymentMethodFilter;
|
|
308
|
+
}
|
|
309
|
+
interface InitializeResp {
|
|
310
|
+
capabilities: string[];
|
|
311
|
+
session: PublicSessionView;
|
|
312
|
+
}
|
|
313
|
+
interface CreateElementReq {
|
|
314
|
+
elementId: string;
|
|
315
|
+
type: ElementType;
|
|
316
|
+
options?: ElementOptions;
|
|
317
|
+
}
|
|
318
|
+
interface CreateElementResp {
|
|
319
|
+
elementId: string;
|
|
320
|
+
registered: true;
|
|
321
|
+
}
|
|
322
|
+
interface UpdateElementReq {
|
|
323
|
+
elementId: string;
|
|
324
|
+
patch: Partial<ElementOptions>;
|
|
325
|
+
}
|
|
326
|
+
interface UpdateElementResp {
|
|
327
|
+
elementId: string;
|
|
328
|
+
options: ElementOptions;
|
|
329
|
+
}
|
|
330
|
+
interface DestroyElementReq {
|
|
331
|
+
elementId: string;
|
|
332
|
+
}
|
|
333
|
+
interface DestroyElementResp {
|
|
334
|
+
elementId: string;
|
|
335
|
+
released: true;
|
|
336
|
+
}
|
|
337
|
+
interface ElementActionReq {
|
|
338
|
+
elementId: string;
|
|
339
|
+
}
|
|
340
|
+
interface ElementActionResp {
|
|
341
|
+
elementId: string;
|
|
342
|
+
done: true;
|
|
343
|
+
}
|
|
344
|
+
interface UpdateCheckoutReq {
|
|
345
|
+
locale?: string;
|
|
346
|
+
appearance?: Appearance;
|
|
347
|
+
}
|
|
348
|
+
interface UpdateCheckoutResp {
|
|
349
|
+
updated: true;
|
|
350
|
+
}
|
|
351
|
+
type GetSessionReq = Record<string, never>;
|
|
352
|
+
type GetSessionResp = PublicSessionView;
|
|
353
|
+
type GetPaymentStatusReq = Record<string, never>;
|
|
354
|
+
interface GetPaymentStatusResp {
|
|
355
|
+
txnStatus: TxnStatus;
|
|
356
|
+
txnId?: string;
|
|
357
|
+
}
|
|
358
|
+
interface ConfirmReq {
|
|
359
|
+
operationId: string;
|
|
360
|
+
billingAddress?: AddressInfo;
|
|
361
|
+
shippingAddress?: AddressInfo;
|
|
362
|
+
customerName?: string;
|
|
363
|
+
email?: string;
|
|
364
|
+
returnUrl?: string;
|
|
365
|
+
}
|
|
366
|
+
interface ConfirmResp {
|
|
367
|
+
accepted: true;
|
|
368
|
+
}
|
|
369
|
+
type DestroyReq = Record<string, never>;
|
|
370
|
+
interface DestroyResp {
|
|
371
|
+
released: true;
|
|
372
|
+
}
|
|
373
|
+
/** 命令名 → 请求载荷映射。 */
|
|
374
|
+
interface CommandRequestMap {
|
|
375
|
+
initialize: InitializeReq;
|
|
376
|
+
createElement: CreateElementReq;
|
|
377
|
+
updateElement: UpdateElementReq;
|
|
378
|
+
destroyElement: DestroyElementReq;
|
|
379
|
+
focus: ElementActionReq;
|
|
380
|
+
blur: ElementActionReq;
|
|
381
|
+
clear: ElementActionReq;
|
|
382
|
+
updateCheckout: UpdateCheckoutReq;
|
|
383
|
+
getSession: GetSessionReq;
|
|
384
|
+
refresh: GetSessionReq;
|
|
385
|
+
getPaymentStatus: GetPaymentStatusReq;
|
|
386
|
+
confirm: ConfirmReq;
|
|
387
|
+
destroy: DestroyReq;
|
|
388
|
+
}
|
|
389
|
+
/** 命令名 → 成功响应载荷映射。 */
|
|
390
|
+
interface CommandResponseMap {
|
|
391
|
+
initialize: InitializeResp;
|
|
392
|
+
createElement: CreateElementResp;
|
|
393
|
+
updateElement: UpdateElementResp;
|
|
394
|
+
destroyElement: DestroyElementResp;
|
|
395
|
+
focus: ElementActionResp;
|
|
396
|
+
blur: ElementActionResp;
|
|
397
|
+
clear: ElementActionResp;
|
|
398
|
+
updateCheckout: UpdateCheckoutResp;
|
|
399
|
+
getSession: GetSessionResp;
|
|
400
|
+
refresh: GetSessionResp;
|
|
401
|
+
getPaymentStatus: GetPaymentStatusResp;
|
|
402
|
+
confirm: ConfirmResp;
|
|
403
|
+
destroy: DestroyResp;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 事件契约(main → 商户 SDK,spec 5.3 表,真源)。
|
|
408
|
+
*
|
|
409
|
+
* 公开事件仅暴露 empty/complete/brand/error 等允许状态,**绝不含卡值**,
|
|
410
|
+
* 不提供卡数据 getValue。`on` 注册后不重放历史事件。
|
|
411
|
+
*/
|
|
412
|
+
|
|
413
|
+
/** 全部事件名(spec 5.3)。 */
|
|
414
|
+
type EventName = 'ready' | 'change' | 'focus' | 'blur' | 'loadError' | 'elementReady' | 'availablePaymentMethodsChange' | 'expressAvailabilityChange' | 'paymentStateChange' | 'paymentResult' | 'error';
|
|
415
|
+
/** 已知事件名集合。 */
|
|
416
|
+
declare const EVENT_NAMES: readonly EventName[];
|
|
417
|
+
/** 判断字符串是否为已知事件名。 */
|
|
418
|
+
declare function isEventName(name: string): name is EventName;
|
|
419
|
+
interface ReadyEvent {
|
|
420
|
+
elementId: string;
|
|
421
|
+
}
|
|
422
|
+
interface ElementReadyEvent {
|
|
423
|
+
elementId: string;
|
|
424
|
+
/** 仅 expressCheckout Element ready 时携带:各钱包可用性。 */
|
|
425
|
+
availableWallets?: AvailableWallets;
|
|
426
|
+
}
|
|
427
|
+
interface ChangeEvent {
|
|
428
|
+
elementId: string;
|
|
429
|
+
empty: boolean;
|
|
430
|
+
complete: boolean;
|
|
431
|
+
error?: CheckoutError;
|
|
432
|
+
/** 仅卡号字段允许携带 brand;绝不含卡值。 */
|
|
433
|
+
brand?: string;
|
|
434
|
+
}
|
|
435
|
+
interface FocusEvent {
|
|
436
|
+
elementId: string;
|
|
437
|
+
}
|
|
438
|
+
interface BlurEvent {
|
|
439
|
+
elementId: string;
|
|
440
|
+
}
|
|
441
|
+
interface LoadErrorEvent {
|
|
442
|
+
elementId: string;
|
|
443
|
+
error: CheckoutError;
|
|
444
|
+
}
|
|
445
|
+
interface AvailablePaymentMethodsChangeEvent {
|
|
446
|
+
availablePaymentMethods: PublicPaymentMethod[];
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* express 可用钱包变化事件(spec 6)。
|
|
450
|
+
* 专用于 expressCheckout:以 AvailableWallets 表达各钱包可用性,
|
|
451
|
+
* 与 AvailablePaymentMethodsChangeEvent(PublicPaymentMethod[])并存,互不破坏。
|
|
452
|
+
*/
|
|
453
|
+
interface ExpressAvailabilityChangeEvent {
|
|
454
|
+
availableWallets: AvailableWallets;
|
|
455
|
+
}
|
|
456
|
+
interface PaymentStateChangeEvent {
|
|
457
|
+
operationId: string;
|
|
458
|
+
method: PaymentMethod;
|
|
459
|
+
/** 过程状态;requiresAction 时携带 action 信息。 */
|
|
460
|
+
state: string;
|
|
461
|
+
action?: PaymentAction;
|
|
462
|
+
}
|
|
463
|
+
interface PaymentResultEvent {
|
|
464
|
+
operationId: string;
|
|
465
|
+
method: PaymentMethod;
|
|
466
|
+
outcome: PaymentOutcome;
|
|
467
|
+
}
|
|
468
|
+
interface ErrorEvent {
|
|
469
|
+
/** 异步主动流程错误;可含 operationId(如已创建)。 */
|
|
470
|
+
operationId?: string;
|
|
471
|
+
error: CheckoutError;
|
|
472
|
+
}
|
|
473
|
+
/** 事件名 → 载荷映射。 */
|
|
474
|
+
interface EventPayloadMap {
|
|
475
|
+
ready: ReadyEvent;
|
|
476
|
+
change: ChangeEvent;
|
|
477
|
+
focus: FocusEvent;
|
|
478
|
+
blur: BlurEvent;
|
|
479
|
+
loadError: LoadErrorEvent;
|
|
480
|
+
elementReady: ElementReadyEvent;
|
|
481
|
+
availablePaymentMethodsChange: AvailablePaymentMethodsChangeEvent;
|
|
482
|
+
expressAvailabilityChange: ExpressAvailabilityChangeEvent;
|
|
483
|
+
paymentStateChange: PaymentStateChangeEvent;
|
|
484
|
+
paymentResult: PaymentResultEvent;
|
|
485
|
+
error: ErrorEvent;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export { type AddressElementOptions, type AddressInfo, type Appearance, type AvailablePaymentMethodsChangeEvent, 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 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 };
|