airwallex-payment-elements 1.104.0 → 1.122.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.
@@ -0,0 +1,742 @@
1
+ import { Consent } from './airwallex';
2
+ import { Intent } from './cardNumber';
3
+ import { PaymentMethodType } from './element';
4
+ // Elements events
5
+ export type DropInElementEventCode =
6
+ | 'ready'
7
+ | 'success'
8
+ | 'error'
9
+ | 'cancel'
10
+ | 'clickConfirmButton'
11
+ | 'switchMethod'
12
+ | 'pendingVerifyAccount';
13
+
14
+ export type ApplePayButtonEventCode =
15
+ | 'ready'
16
+ | 'success'
17
+ | 'error'
18
+ | 'cancel'
19
+ | 'shippingMethodChange'
20
+ | 'shippingAddressChange'
21
+ | 'click'
22
+ | 'validateMerchant'
23
+ | 'authorized';
24
+
25
+ export type GooglePayButtonEventCode =
26
+ | 'ready'
27
+ | 'success'
28
+ | 'error'
29
+ | 'cancel'
30
+ | 'shippingMethodChange'
31
+ | 'shippingAddressChange'
32
+ | 'click'
33
+ | 'authorized';
34
+
35
+ /**
36
+ * CardNumberElement, CvcElement and ExpiryElement event codes
37
+ */
38
+ export type SplitElementEventCode = 'ready' | 'change' | 'focus' | 'blur' | 'pressArrowKey' | 'submit';
39
+
40
+ export type CardElementEventCode = 'ready' | 'change' | 'focus' | 'blur' | 'submit';
41
+
42
+ type PressArrowKeyEvent = {
43
+ detail: {
44
+ arrowKey: string;
45
+ };
46
+ };
47
+
48
+ type InputEvent = {
49
+ detail: {
50
+ /**
51
+ * The form data
52
+ */
53
+ completed: boolean;
54
+ empty: boolean;
55
+ error: {
56
+ /**
57
+ * The unexpected error code, for example: UNKNOWN_ERROR.
58
+ */
59
+ code: string;
60
+ /**
61
+ * The Error message
62
+ */
63
+ message: string;
64
+ };
65
+ };
66
+ };
67
+
68
+ type ErrorEvent = {
69
+ detail: {
70
+ error: {
71
+ /**
72
+ * The unexpected error code, for example: UNKNOWN_ERROR.
73
+ */
74
+ code: string;
75
+ /**
76
+ * The Error details
77
+ */
78
+ details?: Record<string, unknown>;
79
+ /**
80
+ * The Error message
81
+ */
82
+ message?: string;
83
+ };
84
+ };
85
+ };
86
+
87
+ export type SuccessEvent = {
88
+ detail: {
89
+ /**
90
+ * The intent of the payment
91
+ */
92
+ intent?: Intent;
93
+ /**
94
+ * The consent of the payment
95
+ */
96
+ consent?: Consent;
97
+ };
98
+ };
99
+
100
+ export type SwitchMethodEvent = {
101
+ detail: {
102
+ /**
103
+ * The method of the payment
104
+ */
105
+ method: PaymentMethodType;
106
+ /**
107
+ * The name of the method
108
+ */
109
+ methodName: string;
110
+ /**
111
+ * The surcharge fee of the method
112
+ */
113
+ surchargeFee: number;
114
+ };
115
+ };
116
+
117
+ export type PendingVerifyAccountEvent = {
118
+ detail: {
119
+ /**
120
+ * The intent of the payment
121
+ */
122
+ intent: Intent;
123
+ /**
124
+ * The url of the payment
125
+ */
126
+ url: string;
127
+ };
128
+ };
129
+
130
+ export type DropInElementEventHandler<T extends DropInElementEventCode> = (eventData: DropInElementEvent[T]) => void;
131
+
132
+ /**
133
+ * The event object you can listen to.
134
+ */
135
+ type DropInElementEvent = {
136
+ /**
137
+ * This event will be fired when the element is ready to interact with the user.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * element.on('ready', () => void);
142
+ * ```
143
+ */
144
+ ready: undefined;
145
+ /**
146
+ * This event will be fired when the form encounters an unexpected error.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * element.on('error', (e) => {
151
+ * const { error } = e.detail;
152
+ * console.error('There is an error', error);
153
+ * });
154
+ * ```
155
+ */
156
+ error: ErrorEvent;
157
+ /**
158
+ * This event will be fired when the payment is successful.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * element.on('success', (e) => {
163
+ * const { intent, consent } = e.detail;
164
+ * console.log('Payment is successful', { intent, consent });
165
+ * });
166
+ * ```
167
+ */
168
+ success: SuccessEvent;
169
+ /**
170
+ * This event will be fired when the payment is cancelled.
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * element.on('cancel', () => void);
175
+ * ```
176
+ */
177
+ cancel: undefined;
178
+ /**
179
+ * This event will be fired when the user clicks the confirm button.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * element.on('clickConfirmButton', () => void);
184
+ * ```
185
+ */
186
+ clickConfirmButton: undefined;
187
+ /**
188
+ * This event will be fired when the user switches the payment method.
189
+ *
190
+ * @example
191
+ * ```ts
192
+ * element.on('switchMethod', (e) => {
193
+ * const { method, methodName, surchargeFee } = e.detail;
194
+ * console.log('User switched to', { method, methodName, surchargeFee });
195
+ * });
196
+ * ```
197
+ */
198
+ switchMethod: SwitchMethodEvent;
199
+ /**
200
+ * This event will be fired when the user is pending to verify their account. It is only used in the direct debit payment method.
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * element.on('pendingVerifyAccount', (e) => {
205
+ * const { intent, url } = e.detail;
206
+ * console.log('User is pending to verify their account', { intent, url });
207
+ * });
208
+ * ```
209
+ */
210
+ pendingVerifyAccount: PendingVerifyAccountEvent;
211
+ };
212
+
213
+ interface ApplePayDateComponents {
214
+ /**
215
+ * A number that represents a day.
216
+ */
217
+ days: number;
218
+
219
+ /**
220
+ * A number between 1 and 12 that represents a month.
221
+ */
222
+ months: number;
223
+
224
+ /**
225
+ * A number that represents a year.
226
+ */
227
+ years: number;
228
+
229
+ /**
230
+ * A number that represents an hour.
231
+ */
232
+ hours: number;
233
+ }
234
+
235
+ type ApplePayButtonShippingMethodChangeEvent = {
236
+ detail: {
237
+ shippingMethod: {
238
+ /**
239
+ * A short description of the shipping method.
240
+ */
241
+ label: string;
242
+
243
+ /**
244
+ * A further description of the shipping method.
245
+ */
246
+ detail: string;
247
+
248
+ /**
249
+ * The amount associated with this shipping method.
250
+ */
251
+ amount: string;
252
+
253
+ /**
254
+ * A client-defined identifier.
255
+ */
256
+ identifier: string;
257
+
258
+ /**
259
+ * A dictionary that specifies the start and end dates for a range of time.
260
+ */
261
+ dateComponentsRange?: {
262
+ /**
263
+ * The start date and time of the range.
264
+ */
265
+ startDateComponents: ApplePayDateComponents;
266
+ /**
267
+ * The end date and time of the range.
268
+ */
269
+ endDateComponents: ApplePayDateComponents;
270
+ };
271
+ };
272
+ };
273
+ };
274
+
275
+ type ApplePayPaymentContact = {
276
+ /**
277
+ * An email address for the contact.
278
+ */
279
+ emailAddress?: string | undefined;
280
+
281
+ /**
282
+ * The contact's family name.
283
+ */
284
+ familyName?: string | undefined;
285
+
286
+ /**
287
+ * The contact's given name.
288
+ */
289
+ givenName?: string | undefined;
290
+
291
+ /**
292
+ * A phone number for the contact.
293
+ */
294
+ phoneNumber?: string | undefined;
295
+
296
+ /**
297
+ * The phonetic spelling of the contact's family name.
298
+ */
299
+ phoneticFamilyName?: string | undefined;
300
+
301
+ /**
302
+ * The phonetic spelling of the contact's given name.
303
+ */
304
+ phoneticGivenName?: string | undefined;
305
+
306
+ /**
307
+ * The street portion of the address for the contact.
308
+ */
309
+ addressLines?: string[] | undefined;
310
+
311
+ /**
312
+ * The city for the contact.
313
+ */
314
+ locality?: string | undefined;
315
+
316
+ /**
317
+ * Additional information associated with the location, typically defined at the city or town level (such as district or neighborhood), in a postal address.
318
+ */
319
+ subLocality?: string | undefined;
320
+
321
+ /**
322
+ * The state for the contact.
323
+ */
324
+ administrativeArea?: string | undefined;
325
+
326
+ /**
327
+ * The subadministrative area (such as a county or other region) in a postal address.
328
+ */
329
+ subAdministrativeArea?: string | undefined;
330
+
331
+ /**
332
+ * The zip code or postal code, where applicable, for the contact.
333
+ */
334
+ postalCode?: string | undefined;
335
+
336
+ /**
337
+ * The name of the country for the contact.
338
+ */
339
+ country?: string | undefined;
340
+
341
+ /**
342
+ * The contact's two-letter ISO 3166 country code.
343
+ */
344
+ countryCode?: string | undefined;
345
+ };
346
+
347
+ type ApplePayButtonShippingAddressChangeEvent = {
348
+ detail: {
349
+ shippingAddress: ApplePayPaymentContact;
350
+ };
351
+ };
352
+
353
+ type ApplePayPaymentToken = {
354
+ /**
355
+ * An object containing the encrypted payment data.
356
+ */
357
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
358
+ paymentData: any;
359
+
360
+ /**
361
+ * Information about the card used in the transaction.
362
+ */
363
+ paymentMethod: Record<string, unknown>;
364
+
365
+ /**
366
+ * A unique identifier for this payment.
367
+ */
368
+ transactionIdentifier: string;
369
+ };
370
+
371
+ type ApplePayAuthorizedEvent = {
372
+ detail: {
373
+ paymentData: {
374
+ /**
375
+ * The encrypted information for an authorized payment.
376
+ */
377
+ token: ApplePayPaymentToken;
378
+
379
+ /**
380
+ * The billing contact selected by the user for this transaction.
381
+ */
382
+ billingContact?: ApplePayPaymentContact | undefined;
383
+
384
+ /**
385
+ * The shipping contact selected by the user for this transaction.
386
+ */
387
+ shippingContact?: ApplePayPaymentContact | undefined;
388
+ };
389
+ };
390
+ };
391
+
392
+ type ApplePayValidateMerchantEvent = {
393
+ detail: {
394
+ validationURL: string;
395
+ };
396
+ };
397
+
398
+ export type ApplePayButtonEventHandler<T extends ApplePayButtonEventCode> = (eventData: ApplePayButtonEvent[T]) => void;
399
+
400
+ export type ApplePayButtonEvent = {
401
+ /**
402
+ * This event will be fired when form is ready to interact with the user.
403
+ *
404
+ * @example
405
+ * ```ts
406
+ * element.on('ready',( ) => void);
407
+ * ```
408
+ */
409
+
410
+ ready: undefined;
411
+ /**
412
+ * This event will be fired when form encounters an unexpected error.
413
+ *
414
+ * @example
415
+ * ```ts
416
+ * element.on('error', (e) => {
417
+ * const { error } = e.detail;
418
+ * console.error('There is an error', error);
419
+ * });
420
+ * ```
421
+ */
422
+ error: ErrorEvent;
423
+ /**
424
+ * This event will be fired when payment is successful.
425
+ *
426
+ * @example
427
+ * ```ts
428
+ * element.on('success', (e) => {
429
+ * const { intent, consent } = e.detail;
430
+ * console.log('Payment is successful', { intent, consent });
431
+ * });
432
+ * ```
433
+ */
434
+ success: SuccessEvent;
435
+ /**
436
+ * This event will be fired when payment is cancelled.
437
+ *
438
+ * @example
439
+ * ```ts
440
+ * element.on('cancel', ( ) => void);
441
+ * ```
442
+ */
443
+ cancel: undefined;
444
+ /**
445
+ * This event will be fired when the shipping method changes.
446
+ *
447
+ * @example
448
+ * ```ts
449
+ * element.on('shippingMethodChange', (e) => {
450
+ * const { shippingMethod } = e.detail;
451
+ * console.log('Shipping method changed', shippingMethod);
452
+ * });
453
+ * ```
454
+ */
455
+ shippingMethodChange: ApplePayButtonShippingMethodChangeEvent;
456
+ /**
457
+ * This event will be fired when the shipping address changes.
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * element.on('shippingAddressChange', (e) => {
462
+ * const { shippingAddress } = e.detail;
463
+ * console.log('Shipping address changed', shippingAddress);
464
+ * });
465
+ * ```
466
+ */
467
+ shippingAddressChange: ApplePayButtonShippingAddressChangeEvent;
468
+ /**
469
+ * This event will be fired when the user clicks the button.
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * element.on('click', () => void);
474
+ * ```
475
+ */
476
+ click: undefined;
477
+ /**
478
+ * This event will be fired when the user validates the merchant.
479
+ *
480
+ * @example
481
+ * ```ts
482
+ * element.on('validateMerchant', (e) => {
483
+ * const { validationURL } = e.detail;
484
+ * console.log('Validation URL', validationURL);
485
+ * });
486
+ * ```
487
+ */
488
+ validateMerchant: ApplePayValidateMerchantEvent;
489
+ /**
490
+ * This event will be fired when the user authorizes the payment.
491
+ *
492
+ * @example
493
+ * ```ts
494
+ * element.on('authorized', (e) => {
495
+ * const { paymentData } = e.detail;
496
+ * console.log('Payment authorized', paymentData);
497
+ * });
498
+ * ```
499
+ */
500
+ authorized: ApplePayAuthorizedEvent;
501
+ };
502
+
503
+ type GooglePayAuthorizedEvent = {
504
+ detail: {
505
+ paymentData: google.payments.api.PaymentData;
506
+ };
507
+ };
508
+
509
+ type GooglePayShippingAddressChangeEvent = {
510
+ detail: {
511
+ shippingAddress: google.payments.api.Address;
512
+ };
513
+ };
514
+
515
+ type GooglePayIntermediatePaymentData = {
516
+ detail: {
517
+ intermediatePaymentData: google.payments.api.IntermediatePaymentData;
518
+ };
519
+ };
520
+
521
+ export type GooglePayButtonEventHandler<T extends GooglePayButtonEventCode> = (
522
+ eventData: GooglePayButtonEvent[T],
523
+ ) => void;
524
+
525
+ export type GooglePayButtonEvent = {
526
+ /**
527
+ * This event will be fired when form is ready to interact with the user.
528
+ *
529
+ * @example
530
+ * ```ts
531
+ * element.on('ready',( ) => void);
532
+ * ```
533
+ */
534
+ ready: undefined;
535
+ /**
536
+ * This event will be fired when form encounters an unexpected error.
537
+ *
538
+ * @example
539
+ * ```ts
540
+ * element.on('error', (e) => {
541
+ * const { error } = e.detail;
542
+ * console.error('There is an error', error);
543
+ * });
544
+ * ```
545
+ */
546
+ error: ErrorEvent;
547
+ /**
548
+ * This event will be fired when payment is successful. It can be used to redirect the user to the success page.
549
+ *
550
+ * @example
551
+ * ```ts
552
+ * element.on('success', (e) => {
553
+ * const { intent, consent } = e.detail;
554
+ * console.log('Payment is successful', { intent, consent });
555
+ * });
556
+ * ```
557
+ */
558
+ success: SuccessEvent;
559
+ /**
560
+ * This event will be fired when payment is cancelled.
561
+ *
562
+ * @example
563
+ * ```ts
564
+ * element.on('cancel', ( ) => void);
565
+ * ```
566
+ */
567
+ cancel: undefined;
568
+ /**
569
+ * This event will be fired when the user clicks the button.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * element.on('click', () => void);
574
+ * ```
575
+ */
576
+ click: undefined;
577
+ /**
578
+ * This event will be fired when the user authorizes the payment.
579
+ *
580
+ * @example
581
+ * ```ts
582
+ * element.on('authorized', (e) => {
583
+ * const { paymentData } = e.detail;
584
+ * console.log('Payment authorized', paymentData);
585
+ * });
586
+ * ```
587
+ */
588
+ authorized: GooglePayAuthorizedEvent;
589
+ /**
590
+ * This event will be fired when the shipping method changes.
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * element.on('shippingMethodChange', (e) => {
595
+ * const { intermediatePaymentData } = e.detail;
596
+ * console.log('Shipping method changed', intermediatePaymentData);
597
+ * });
598
+ * ```
599
+ */
600
+ shippingMethodChange: GooglePayIntermediatePaymentData;
601
+ /**
602
+ * This event will be fired when the shipping address changes.
603
+ *
604
+ * @example
605
+ * ```ts
606
+ * element.on('shippingAddressChange', (e) => {
607
+ * const { intermediatePaymentData } = e.detail;
608
+ * console.log('Shipping address changed', intermediatePaymentData);
609
+ * });
610
+ * ```
611
+ */
612
+ shippingAddressChange: GooglePayIntermediatePaymentData;
613
+ };
614
+
615
+ export type SplitElementEventHandler<T extends SplitElementEventCode> = (eventData: SplitElementEvent[T]) => void;
616
+
617
+ type SplitElementEvent = {
618
+ /**
619
+ * This event will be fired when form is ready to interact with the user.
620
+ *
621
+ * @example
622
+ * ```ts
623
+ * element.on('ready',( ) => void);
624
+ * ```
625
+ */
626
+ ready: undefined;
627
+ /**
628
+ * This event will be fired when form is ready to interact with the user.
629
+ *
630
+ * @example
631
+ * ```ts
632
+ * element.on('change',( ) => {
633
+ * const { completed, empty, error } = e.detail;
634
+ * console.log('Form changed', { completed, empty, error });
635
+ * });
636
+ * ```
637
+ */
638
+ change: InputEvent;
639
+ /**
640
+ * This event will be fired when form is ready to interact with the user.
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * element.on('blur',( ) => {
645
+ * const { completed, empty, error } = e.detail;
646
+ * console.log('Form blurred', { completed, empty, error });
647
+ * });
648
+ * ```
649
+ */
650
+ blur: InputEvent;
651
+ /**
652
+ * This event will be fired when form is ready to interact with the user.
653
+ *
654
+ * @example
655
+ * ```ts
656
+ * element.on('focus',( ) => void);
657
+ * ```
658
+ */
659
+ focus: InputEvent;
660
+ /**
661
+ * This event will be fired when form is ready to interact with the user.
662
+ *
663
+ * @example
664
+ * ```ts
665
+ * element.on('pressArrowKey',( ) => {
666
+ * const { arrowKey } = e.detail;
667
+ * console.log('Arrow key pressed', arrowKey);
668
+ * });
669
+ * ```
670
+ */
671
+ pressArrowKey: PressArrowKeyEvent;
672
+ /**
673
+ * This event will be fired when form is ready to interact with the user.
674
+ *
675
+ * @example
676
+ * ```ts
677
+ * element.on('submit',( ) => {
678
+ * console.log('Form submitted');
679
+ * });
680
+ * ```
681
+ */
682
+ submit: undefined;
683
+ };
684
+
685
+ export type CardElementEventHandler<T extends CardElementEventCode> = (eventData: CardElementEvent[T]) => void;
686
+
687
+ type CardElementEvent = {
688
+ /**
689
+ * This event will be fired when form is ready to interact with the user.
690
+ *
691
+ * @example
692
+ * ```ts
693
+ * element.on('ready',( ) => void);
694
+ * ```
695
+ */
696
+ ready: undefined;
697
+ /**
698
+ * This event will be fired when form is ready to interact with the user.
699
+ *
700
+ * @example
701
+ * ```ts
702
+ * element.on('change',(e) => {
703
+ * const { completed, empty, error } = e.detail;
704
+ * console.log('Form changed', { completed, empty, error });
705
+ * });
706
+ * ```
707
+ */
708
+ change: InputEvent;
709
+ /**
710
+ * This event will be fired when form is ready to interact with the user.
711
+ *
712
+ * @example
713
+ * ```ts
714
+ * element.on('focus',(e) => {
715
+ * const { completed, empty, error } = e.detail;
716
+ * console.log('Form focused', { completed, empty, error });
717
+ * });
718
+ * ```
719
+ */
720
+ focus: InputEvent;
721
+ /**
722
+ * This event will be fired when form is ready to interact with the user.
723
+ *
724
+ * @example
725
+ * ```ts
726
+ * element.on('blur',( ) =&gt; {
727
+ * const { completed, empty, error } = e.detail;
728
+ * console.log('Form blurred', { completed, empty, error });
729
+ * });
730
+ * ```
731
+ */
732
+ blur: InputEvent;
733
+ /**
734
+ * This event will be fired when form is ready to interact with the user.
735
+ *
736
+ * @example
737
+ * ```ts
738
+ * element.on('submit',( ) => void);
739
+ * ```
740
+ */
741
+ submit: undefined;
742
+ };