-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.d.ts
582 lines (563 loc) · 12.9 KB
/
index.d.ts
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
// Type definitions for lyra/embedded-form-glue
// Project: https://github.com/lyra/embedded-form-glue
// TypeScript Version: 4.5.2
declare module '@lyracom/embedded-form-glue' {
const KRGlue: KRGlue
export default KRGlue
}
declare interface KRGlue {
/**
* Load kr-payment-form library
* @param endpoint - API endpoint (only the base domain, e.g. https://domain.name)
* @param publicKey - Public key
* @param formToken? - Form token
*
* @example
* const {KR} = await KRGlue.loadLibrary('https://domain.name', '12345678:publickey_abcdefghi...')
*/
loadLibrary: (
endpoint: string,
publicKey: string,
formToken?: string
) => Promise<{ KR: KR }>
}
declare interface KR {
/**
* Set form configuration
* @param config - Form configuration
*/
setFormConfig: (config: KRConfig) => Promise<{ KR: KR }>
/**
* Set form token.
* @param formToken - Form token
*/
setFormToken: (formToken: string) => Promise<{ KR: KR }>
/**
* Set shop name.
* @param shopName - Shop name
*/
setShopName: (shopName: string) => Promise<{ KR: KR }>
/**
* Set help buttons visibility.
* @param formId - Form id
* @param visibility - Visibility
*/
setHelpVisibility: (
formId: string,
visibility: boolean
) => Promise<{ KR: KR }>
/**
* Add a form.
* @param formSelector - Form selector
* @param formType? - Form type
*/
addForm: (
formSelector: string,
formType?: FormType
) => Promise<{ KR: KR; result: { formId: string } }>
/**
* Attach a form to the given selector.
* @param formSelector - Form selector
*
* @deprecated Use renderElements instead
*/
attachForm: (
formSelector: string
) => Promise<{ KR: KR; result: { formId: string } }>
/**
* Renders the KR supported elements in the given selector or HTML element.
* @param $elements - Form query selector or HTML element or array of HTML elements or undefined
*/
renderElements: (
$elements: string | HTMLElement | Array<HTMLElement> | undefined
) => Promise<{ KR: KR; result: { formId: string } }>
/**
* Show form.
* @param formId - Form id
*/
showForm: (formId?: string) => Promise<{ KR: KR }>
/**
* Hide form.
* @param formId - Form id
*/
hideForm: (formId?: string) => Promise<{ KR: KR }>
/**
* Open popin form.
* @param formId - Form id
*/
openPopin: (formId?: string) => Promise<{ KR: KR }>
/**
* Close popin form.
* @param formId - Form id
*/
closePopin: (formId?: string) => Promise<{ KR: KR }>
/**
* Validate form.
* @param formId - Form id
*/
validateForm: (formId?: string) => Promise<{ KR: KR; result: KRError }>
/**
* Remove all forms.
*/
removeForms: () => Promise<{ KR: KR }>
/**
* Submit a form.
*/
submit: () => Promise<{ KR: KR }>
/**
* Error event listener.
* @param callback - Callback
*/
onError: (callback: (error: KRError) => void) => Promise<{ KR: KR }>
/**
* Focus event listener.
* @param callback - Callback
*/
onFocus: (callback: (field: KRField) => void) => Promise<{ KR: KR }>
/**
* Blur event listener.
* @param callback - Callback
*/
onBlur: (callback: (field: KRField) => void) => Promise<{ KR: KR }>
/**
* Callback called when the payment form DOM elements are created.
* @param callback - Callback
*/
onFormCreated: (callback: () => void) => Promise<{ KR: KR }>
/**
* Callback called when the payment form application is loaded.
* @param callback - Callback
*/
onLoaded: (callback: () => void) => Promise<{ KR: KR }>
/**
* Callback called when the payment form is ready to be submitted.
* @param callback - Callback
*/
onFormReady: (callback: () => void) => Promise<{ KR: KR }>
/**
* Form valid event listener.
* @param callback - Callback
*/
onFormValid: (
callback: (data: FormValidCallBackProps) => void
) => Promise<{ KR: KR }>
/**
* Form submitted event listener.
* @param callback - Callback
*/
onSubmit: (
callback: (response: KRPaymentResponse) => void | boolean | Promise<boolean>
) => Promise<{ KR: KR }>
/**
* Brand changed event listener
* @param callback - Callback
*/
onBrandChanged: (
callback: (data: BrandChangeCallBackProps) => void
) => Promise<{ KR: KR }>
/**
* Transaction created event listener
* @param callback - Callback
*/
onTransactionCreated: (
callback: (response: KRPaymentResponse) => void | boolean | Promise<boolean>
) => Promise<{ KR: KR }>
/**
* 3ds secure abortion event listener
* @param callback - Callback
*/
on3dSecureAbort: (callback: () => void) => Promise<{ KR: KR }>
/**
* Popin closed event listener
* @param callback - Callback
*/
onPopinClosed: (callback: () => void) => Promise<{ KR: KR }>
/**
* Installment change event listener
* @param callback - Callback
*/
onInstallmentChanged: (
callback: (props: InstallmentChangeCallbackProps) => void
) => Promise<{ KR: KR }> // TODO installmentInfo
/**
* Remove event callbacks
* @param event - Event name
*/
removeEventCallbacks: (event: string) => void
/**
* Sets brand
* @param brand - Brand name
*/
setBrand: (brand: string | null) => void
/**
* Force the form validation
*/
validate: () => void
/**
* Open the specified payment method
* @param paymentMethod - Payment method name
*/
openPaymentMethod: (paymentMethod: string) => void
/**
* Payment button.
*/
button: KRButton
smartForm: KRSmartForm
wallet: KRWallet
}
/**
* Payment button
*/
declare interface KRButton {
/**
* Payment button click event listener.
* @param callback - Callback
* @deprecated Use KR.smartForm.onClick
*/
onClick: (
callback: () => void | boolean | Promise<boolean>
) => Promise<{ KR: KR }>
/**
* Set payment button label.
* @param label - Template : Your label %amount-and-currency% for button
*/
setLabel: (label: string) => Promise<{ KR: KR }>
/**
* Show payment button spinner.
*/
showSpinner: () => Promise<{ KR: KR }>
/**
* Hide payment button spinner.
*/
hideSpinner: () => Promise<{ KR: KR }>
/**
* Disable payment button.
*/
disable: () => Promise<{ KR: KR }>
/**
* Enable payment buttons.
*/
enable: () => Promise<{ KR: KR }>
}
/**
* Smart form
*/
declare interface KRSmartForm {
/**
* Payment button click event listener.
* @param callback - Callback
*/
onClick: (
callback: () => void | boolean | Promise<boolean>
) => Promise<{ KR: KR }>
}
/**
* Form wallet
*/
declare interface KRWallet {
/**
* Tab changed form button event listener.
* @param callback - Callback
*/
onTabChange: (callback: (tabName: string) => void) => Promise<{ KR: KR }>
}
/**
* Form configuration
*/
declare interface KRConfig {
/**
* Form token.
*/
formToken?: string
/**
* Public key.
*/
'kr-public-key'?: string
/**
* Language used to display the form in Culture format (en-US).
*/
'kr-language'?: string
/**
* URL to which the form is submitted (POST method) in case of success.
*/
'kr-post-url-success'?: string
/**
* URL to which the form is submitted (GET method) in case of success.
*/
'kr-get-url-success'?: string
/**
* URL called when there are no attempts left (POST method).
*/
'kr-post-url-refused'?: string
/**
* URL called when there are no attempts left (GET method).
*/
'kr-get-url-refused'?: string
/**
* CVV clean in case of rejected transaction.
*/
'kr-clear-on-error'?: boolean
/**
* Hide the debug toolbar.
*/
'kr-hide-debug-toolbar'?: boolean
/**
* Form's read only mode.
*/
'kr-read-only'?: boolean
/**
* Disables auto initialization for SPA mode.
*/
'kr-spa-mode'?: boolean
/**
* Form's z-index style.
*/
'kr-z-index'?: string
/**
* Installments field content label (singular)
* @param label - Template : Your label [COUNT] for singular installment with [CURRENCY] [AMOUNT]
*
*/
'kr-installments-label-singular'?: string
/**
* Installments field content label (plural)
* @param label - Template : Your label [COUNT] for plural installment with [CURRENCY] [AMOUNT]
*/
'kr-installments-label-plural'?: string
/**
* First installment delay field content label (singular)
* @param label - Template : Your label [COUNT] for singular installment delay
*/
'kr-first-installment-delay-label-singular'?: string
/**
* First installment delay field content label (plural)
* @param label - Template : Your label [COUNT] for plural installment delay
*/
'kr-first-installment-delay-label-plural'?: string
/**
* First installment delay field content label (without)
*/
'kr-first-installment-delay-label-without'?: string
/**
* Pan field placeholder (card number).
*/
'kr-placeholder-pan'?: string
/**
* Expiry field placeholder (expiry date).
*/
'kr-placeholder-expiry'?: string
/**
* Security code field placeholder (CVV).
*/
'kr-placeholder-security-code'?: string
/**
* ID document type field placeholder.
*/
'kr-placeholder-identity-document-type'?: string
/**
* ID document number field placeholder.
*/
'kr-placeholder-identity-document-number'?: string
/**
* Installments field placeholder (default).
*/
'kr-placeholder-installments-default'?: string
/**
* Installments field placeholder (single payment).
*/
'kr-placeholder-installments-single-payment'?: string
/**
* Installments field placeholder (single payment and credit card).
*/
'kr-placeholder-installments-single-payment-credit'?: string
/**
* First installment delay field placeholder.
*/
'kr-placeholder-first-installment-delay'?: string
/**
* Card holder email field placeholder.
*/
'kr-placeholder-card-holder-mail'?: string
/**
* Card holder name field placeholder.
*/
'kr-placeholder-card-holder-name'?: string
/**
* Pan field label (card number).
*/
'kr-label-pan'?: string
/**
* Expiry field label (expiry date).
*/
'kr-label-expiry'?: string
/**
* Security code field label (CVV).
*/
'kr-label-security-code'?: string
/**
* ID document type field label.
*/
'kr-label-identity-document-type'?: string
/**
* ID document number field label.
*/
'kr-label-identity-document-number'?: string
/**
* Installments field label.
*/
'kr-label-installment-number'?: string
/**
* Card holder email field label.
*/
'kr-label-card-holder-mail'?: string
/**
* Card holder name field label.
*/
'kr-label-card-holder-name'?: string
/**
* Card register checkbox field label.
*/
'kr-label-register'?: string
}
/**
* Form error
*/
declare interface KRError {
/**
* Error code.
*/
errorCode: string
/**
* Error message.
*/
errorMessage: string
/**
* Detailed error code.
*/
detailedErrorCode?: string
/**
* Detailed error message.
*/
detailedErrorMessage?: string
/**
* Field with the error.
*/
field?: string
/**
* Child errors.
*/
children?: Array<KRError>
/**
* Error metadata.
*/
metadata?: Record<string, any>
}
/**
* Field.
*/
declare interface KRField {
formId: string
field: string
}
/**
* Payment response object.
*/
declare interface KRPaymentResponse {
/**
* Response type.
*/
_type: string
/**
* Hash of the JSON object stored in kr-answer. It allows to verify the authenticity of the response.
*/
hash: string
/**
* Algorithm used to calculate the hash.
*/
hashAlgorithm: string
/**
* Type of key used to sign kr-answer. Can be set to sha256_hmac (browser return) or password (IPN).
*/
hashKey: string
/**
* Server date.
*/
serverDate: string
/**
* Object containing the payment result in JSON format.
*/
clientAnswer: KRClientAnswer
/**
* Object containing the payment result in JSON format.
*/
post: () => KRPaymentIPNResponse
}
/**
* Client answer object.
*/
declare interface KRClientAnswer {
/**
* Shop identifier.
*/
shopId: string
/**
* Payment cycle (CLOSED or OPEN).
*/
orderCycle: string
/**
* Payment status (PAID, UNPAID... ).
*/
orderStatus: string
/**
* Server date.
*/
serverDate: string
}
/**
* Payment object in IPN format.
*/
declare interface KRPaymentIPNResponse {
/**
* Hash of the response object.
*/
'kr-hash': string
/**
* Hash algorithm of the response object.
*/
'kr-hash-algorithm': string
/**
* Answer type.
*/
'kr-answer-type': string
/**
* Answer data.
*/
'kr-answer': string
}
declare enum FormType {
Cards = 'cards',
All = 'all'
}
declare interface FormValidCallBackProps {
KR: KR
cardInfo: {
bin: string
brand: string
}
}
declare interface BrandChangeCallBackProps {
KR: KR
cardInfo: {
bin: string
brand: string
}
}
declare interface InstallmentChangeCallbackProps {
KR: KR
installmentInfo: {
installmentCount: number
totalAmount: number
hasInterests: boolean
brand: string
}
}