@pay-com/js 1.1.6 → 1.1.8
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/lib/dts/index.d.ts +9 -0
- package/lib/dts/types/index.d.ts +459 -0
- package/lib/dts/types/script-options.d.ts +10 -0
- package/lib/dts/utils.d.ts +19 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CheckoutToggles, PaypalOpts, RenderOpts, UniversalToggles, LanguageLocalizationOverride, DividerStyles, ExpandablePaymentMethods, ApmStyle, UniversalOpts, SubmitOpts, FailureError, CheckoutOpts, EVENT_TYPES, ListenerFn, ValidationResponse, ELEMENT_TYPES, SubmitResponse, UpdateTransactionDetailsOpts, PayOpts, PayFn, UpdateTransactionDetailsFn, CheckoutObject, CheckoutFunction, PayComFunction, PayComNamespace } from './types';
|
|
2
|
+
import { PayComScriptOptions } from './types/script-options';
|
|
3
|
+
export type { CheckoutToggles, PaypalOpts, RenderOpts, UniversalToggles, LanguageLocalizationOverride, DividerStyles, ExpandablePaymentMethods, ApmStyle, UniversalOpts, SubmitOpts, FailureError, CheckoutOpts, EVENT_TYPES, ListenerFn, ValidationResponse, ELEMENT_TYPES, SubmitResponse, UpdateTransactionDetailsOpts, PayOpts, PayFn, UpdateTransactionDetailsFn, CheckoutObject, CheckoutFunction, PayComFunction, PayComNamespace };
|
|
4
|
+
declare const _default: {
|
|
5
|
+
com: (options: PayComScriptOptions, PromisePonyfill?: PromiseConstructor) => Promise<{
|
|
6
|
+
checkout: CheckoutFunction;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import EventEmitter from 'events'
|
|
2
|
+
import * as CSS from 'csstype'
|
|
3
|
+
import type { PayComScriptOptions } from './script-options'
|
|
4
|
+
|
|
5
|
+
type PayCustomPseudos = ':error'
|
|
6
|
+
|
|
7
|
+
type PayCssConfig = Partial<
|
|
8
|
+
Record<CSS.SimplePseudos | PayCustomPseudos, CSS.Properties>
|
|
9
|
+
> &
|
|
10
|
+
CSS.Properties
|
|
11
|
+
|
|
12
|
+
interface InitData {
|
|
13
|
+
sandbox: boolean
|
|
14
|
+
debug: boolean
|
|
15
|
+
}
|
|
16
|
+
interface CheckoutStyles {
|
|
17
|
+
base?: PayCssConfig
|
|
18
|
+
number?: PayCssConfig
|
|
19
|
+
cvv?: PayCssConfig
|
|
20
|
+
expiry?: PayCssConfig
|
|
21
|
+
name?: PayCssConfig
|
|
22
|
+
checkboxes?: {
|
|
23
|
+
buttonBackground?: string
|
|
24
|
+
labelColor?: string
|
|
25
|
+
}
|
|
26
|
+
submit?: PayCssConfig
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface CheckoutFieldConfig {
|
|
30
|
+
label?: string
|
|
31
|
+
labelStyle?: PayCssConfig
|
|
32
|
+
errorMessageStyle?: PayCssConfig
|
|
33
|
+
inputSize?: 'small' | 'medium' | 'large'
|
|
34
|
+
placeholder?: string
|
|
35
|
+
style?: PayCssConfig
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface CheckoutFormConfig {
|
|
39
|
+
base?: {
|
|
40
|
+
inputSpacing?: string
|
|
41
|
+
formTitle?: string
|
|
42
|
+
titleStyles?: PayCssConfig
|
|
43
|
+
style?: PayCssConfig
|
|
44
|
+
}
|
|
45
|
+
number?: CheckoutFieldConfig
|
|
46
|
+
cvv?: CheckoutFieldConfig
|
|
47
|
+
expiry?: CheckoutFieldConfig
|
|
48
|
+
name?: CheckoutFieldConfig
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface CheckoutToggles {
|
|
52
|
+
/**
|
|
53
|
+
* If false, the form will render without a submission button.
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
submitButton?: boolean
|
|
57
|
+
/**
|
|
58
|
+
* If false, the form will render without a title.
|
|
59
|
+
* @default true
|
|
60
|
+
*/
|
|
61
|
+
withTitle?: boolean
|
|
62
|
+
/**
|
|
63
|
+
* If false, the form will render without a card holder name.
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
withCardHolderName?: boolean
|
|
67
|
+
/**
|
|
68
|
+
* If false, the wrapping element of the form will be a div instead of a form.
|
|
69
|
+
* Good for when the form is embedded inside a larger form.
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
formWrapper?: boolean
|
|
73
|
+
/**
|
|
74
|
+
* If true, will display save for future use checkbox under the form.
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
77
|
+
saveSourceForFutureUseCheckbox?: boolean
|
|
78
|
+
/**
|
|
79
|
+
* If true, will display our accept T&A checkbox under the form.
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
acceptTermsAndConditionsCheckbox?: boolean
|
|
83
|
+
/**
|
|
84
|
+
* If true, won't display required additional fields, such as email for EU 3ds.
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
disableAdditionalFields?: boolean
|
|
88
|
+
/**
|
|
89
|
+
* If true, will render native browser checkboxes instead of ours.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
nativeCheckboxes?: boolean
|
|
93
|
+
/**
|
|
94
|
+
* If true, on mobile view all fields will be in one column.
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
mobileColumn?: boolean
|
|
98
|
+
/**
|
|
99
|
+
* If true, will render credit card brand on number input
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
withCardNumberBrand?: boolean
|
|
103
|
+
/**
|
|
104
|
+
* If true, will render a tooltip on the card CVV input
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
withCvvTooltip?: boolean
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface PaypalOpts {
|
|
111
|
+
container: string
|
|
112
|
+
onClickValidation: () => Promise<boolean>
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface RenderOpts {
|
|
116
|
+
container: string
|
|
117
|
+
button?: boolean
|
|
118
|
+
toggles?: CheckoutToggles
|
|
119
|
+
formConfig?: CheckoutFormConfig
|
|
120
|
+
localizations?: {
|
|
121
|
+
[language: string]: LanguageLocalizationOverride
|
|
122
|
+
}
|
|
123
|
+
style?: CheckoutStyles
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface UniversalToggles {
|
|
127
|
+
/**
|
|
128
|
+
* If false, the form will render without a submission button.
|
|
129
|
+
* @default true
|
|
130
|
+
*/
|
|
131
|
+
submitButton?: boolean
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* If true, displays the card bin as well as last 4.
|
|
135
|
+
* @default false
|
|
136
|
+
*/
|
|
137
|
+
savedCardsBins?: boolean | 2 | 3 | 4 | 5 | 6
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* If true, the CVV in saved payment method will be inline
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
|
+
savedPaymentMethodInlineCvv?: boolean
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A title to display above the Universal form.
|
|
147
|
+
*/
|
|
148
|
+
title?: string
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type LanguageLocalizationOverride = {
|
|
152
|
+
cardForm?: {
|
|
153
|
+
nameOnCard?: string
|
|
154
|
+
cardNumber?: string
|
|
155
|
+
cvv?: string
|
|
156
|
+
expiryDate?: string
|
|
157
|
+
title?: string
|
|
158
|
+
checkboxes?: {
|
|
159
|
+
saveCardForFutureUse?: string
|
|
160
|
+
agreeToTermsAndConditions?: string
|
|
161
|
+
}
|
|
162
|
+
submit?: {
|
|
163
|
+
pay?: string
|
|
164
|
+
save_card?: string
|
|
165
|
+
DEPOSIT?: string
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
existingSource?: {
|
|
169
|
+
delete?: string
|
|
170
|
+
}
|
|
171
|
+
dividers?: {
|
|
172
|
+
myPaymentMethods?: string
|
|
173
|
+
otherPaymentMethods?: string
|
|
174
|
+
showOtherWaysToPay?: string
|
|
175
|
+
payWithCard?: string
|
|
176
|
+
payWith?: string
|
|
177
|
+
savedPaymentMethods?: string
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface DividerStyles {
|
|
182
|
+
text?: PayCssConfig
|
|
183
|
+
divider?: {
|
|
184
|
+
marginBottom?: PayCssConfig['marginBottom']
|
|
185
|
+
color?: PayCssConfig['color']
|
|
186
|
+
height?: PayCssConfig['height']
|
|
187
|
+
':disabled'?: {
|
|
188
|
+
color?: PayCssConfig['color']
|
|
189
|
+
height?: PayCssConfig['height']
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export type ExpandablePaymentMethods = 'upi' | 'netbanking'
|
|
195
|
+
export interface ApmStyle {
|
|
196
|
+
divider?: DividerStyles
|
|
197
|
+
input?: PayCssConfig
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface UniversalOpts {
|
|
201
|
+
container: string
|
|
202
|
+
cardForm?: Omit<RenderOpts, 'container' | 'style'>
|
|
203
|
+
toggles?: UniversalToggles
|
|
204
|
+
apmsOnClickValidation?: () => Promise<boolean>
|
|
205
|
+
localizations?: {
|
|
206
|
+
[language: string]: LanguageLocalizationOverride
|
|
207
|
+
}
|
|
208
|
+
style?: {
|
|
209
|
+
cardForm?: CheckoutStyles
|
|
210
|
+
base?: PayCssConfig
|
|
211
|
+
submit?: PayCssConfig
|
|
212
|
+
savedPaymentMethods?: PayCssConfig
|
|
213
|
+
expressCheckout?: PayCssConfig
|
|
214
|
+
apmButtons?: PayCssConfig
|
|
215
|
+
apms?: Partial<Record<ExpandablePaymentMethods, ApmStyle>>
|
|
216
|
+
dividers?: {
|
|
217
|
+
showOtherWaysToPay?: DividerStyles
|
|
218
|
+
payWith?: DividerStyles
|
|
219
|
+
savedPaymentMethods?: DividerStyles
|
|
220
|
+
}
|
|
221
|
+
existingSource?: {
|
|
222
|
+
deleteText?: PayCssConfig
|
|
223
|
+
cvv?: {
|
|
224
|
+
style?: PayCssConfig
|
|
225
|
+
labelStyle?: PayCssConfig
|
|
226
|
+
errorMessageStyle?: PayCssConfig
|
|
227
|
+
}
|
|
228
|
+
icons?: {
|
|
229
|
+
delete?: PayCssConfig
|
|
230
|
+
confirmDeletion?: PayCssConfig
|
|
231
|
+
cancelDeletion?: PayCssConfig
|
|
232
|
+
}
|
|
233
|
+
base?: PayCssConfig & { ':selected'?: PayCssConfig }
|
|
234
|
+
radioButton?: {
|
|
235
|
+
color?: PayCssConfig['color']
|
|
236
|
+
':selected'?: {
|
|
237
|
+
color?: PayCssConfig['color']
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
paymentMethods?: Array<string>
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface SubmitOpts {
|
|
246
|
+
token?: string
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export type FailureError = {
|
|
250
|
+
message: string
|
|
251
|
+
data?: Record<string, unknown>
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface CheckoutOpts {
|
|
255
|
+
/**
|
|
256
|
+
* @deprecated Got replaced by clientSecret
|
|
257
|
+
*/
|
|
258
|
+
token?: string | (() => Promise<string>)
|
|
259
|
+
clientSecret?: string | (() => Promise<string>)
|
|
260
|
+
currency?: string
|
|
261
|
+
onSuccess?: (payment: Record<string, unknown>) => void
|
|
262
|
+
onFailure?: (error: FailureError) => void
|
|
263
|
+
mode?: modeOpts
|
|
264
|
+
throwOnSubmitFailure?: boolean
|
|
265
|
+
paymentFailurePopupConfig?: {
|
|
266
|
+
sessionExpiredPopupText?: string
|
|
267
|
+
maxAttemptsReachedPopupText?: string
|
|
268
|
+
style?: PayCssConfig
|
|
269
|
+
}
|
|
270
|
+
toggles?: {
|
|
271
|
+
displayFailureMessages: boolean
|
|
272
|
+
displayEndOfSessionFailureMessages?: boolean
|
|
273
|
+
disableAdditionalFields?: boolean
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
interface PayComI {
|
|
278
|
+
identifier: string
|
|
279
|
+
sandbox: boolean
|
|
280
|
+
debug: boolean
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface PayComOpts {
|
|
284
|
+
identifier?: string
|
|
285
|
+
riskIdentifier?: string
|
|
286
|
+
sandbox?: boolean
|
|
287
|
+
debug?: boolean
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export enum EVENT_TYPES {
|
|
291
|
+
THREE_DS_INIT = 'three_ds_init',
|
|
292
|
+
THREE_DS_CHALLENGE = 'three_ds_challenge',
|
|
293
|
+
THREE_DS_DONE = 'three_ds_done',
|
|
294
|
+
CONTENT_READY = 'content_ready',
|
|
295
|
+
PAYMENT_SUCCESS = 'payment_success',
|
|
296
|
+
SETUP_SUCCESS = 'setup_success',
|
|
297
|
+
PAYMENT_FAILURE = 'payment_failure',
|
|
298
|
+
SETUP_FAILURE = 'setup_failure',
|
|
299
|
+
PAYMENT_PROCESSING = 'payment_processing',
|
|
300
|
+
SETUP_PROCESSING = 'setup_processing',
|
|
301
|
+
SESSION_EXPIRED = 'session_expired',
|
|
302
|
+
MAX_ATTEMPTS_REACHED = 'max_attempts_reached'
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export type ListenerFn = (
|
|
306
|
+
eventName: EVENT_TYPES,
|
|
307
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
308
|
+
callback: (...params: any[]) => void
|
|
309
|
+
) => EventEmitter
|
|
310
|
+
|
|
311
|
+
export type ValidationResponse = {
|
|
312
|
+
valid: boolean
|
|
313
|
+
invalidFields: string[]
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export enum ELEMENT_TYPES {
|
|
317
|
+
CHECKOUT = 'checkout',
|
|
318
|
+
UNIVERSAL = 'universal',
|
|
319
|
+
PAYPAL = 'paypal'
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
enum TransactionStatusEnum {
|
|
323
|
+
APPROVED = 'APPROVED',
|
|
324
|
+
PENDING = 'PENDING',
|
|
325
|
+
DECLINED = 'DECLINED',
|
|
326
|
+
ERROR = 'ERROR',
|
|
327
|
+
EXPIRED = 'EXPIRED',
|
|
328
|
+
CANCELLED = 'CANCELLED',
|
|
329
|
+
CREATED = 'CREATED'
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export type SubmitResponse = {
|
|
333
|
+
transactionStatus: TransactionStatusEnum
|
|
334
|
+
transactionId: string
|
|
335
|
+
transactionDateTime: string
|
|
336
|
+
sourceId: string
|
|
337
|
+
consumerId: string
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export type ValidateResponse = {
|
|
341
|
+
valid: boolean
|
|
342
|
+
invalidFields: string[]
|
|
343
|
+
paymentMethodDetails?: {
|
|
344
|
+
type: string
|
|
345
|
+
card?: {
|
|
346
|
+
bin: string
|
|
347
|
+
last4: string
|
|
348
|
+
name: string
|
|
349
|
+
expirationMonth: string
|
|
350
|
+
expirationYear: string
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
type RenderFn = (renderOpts: RenderOpts) => Promise<void>
|
|
356
|
+
type PaypalFn = (paypalOpts: PaypalOpts) => Promise<void>
|
|
357
|
+
type BlurFn = () => void
|
|
358
|
+
type UniversalFn = (universalOpts: UniversalOpts) => Promise<void>
|
|
359
|
+
type SubmitFn = (
|
|
360
|
+
opts?: SubmitOpts,
|
|
361
|
+
frameType?: ELEMENT_TYPES
|
|
362
|
+
) => Promise<void | Record<string, unknown>>
|
|
363
|
+
|
|
364
|
+
interface UpdateOpts {
|
|
365
|
+
amount: number
|
|
366
|
+
currency?: string
|
|
367
|
+
}
|
|
368
|
+
type UpdateFn = (updateOpts: UpdateOpts) => Promise<void>
|
|
369
|
+
|
|
370
|
+
type ValidateFn = (
|
|
371
|
+
frameType?: ELEMENT_TYPES
|
|
372
|
+
) => Promise<ValidateResponse | void>
|
|
373
|
+
type ResetFn = (frameType?: ELEMENT_TYPES) => Promise<void>
|
|
374
|
+
|
|
375
|
+
export type UpdateTransactionDetailsOpts = {
|
|
376
|
+
successUrl?: string
|
|
377
|
+
failureUrl?: string
|
|
378
|
+
consumer?: {
|
|
379
|
+
firstName?: string
|
|
380
|
+
lastName?: string
|
|
381
|
+
email?: string
|
|
382
|
+
phone?: string
|
|
383
|
+
}
|
|
384
|
+
billing?: {
|
|
385
|
+
addressLine: string
|
|
386
|
+
addressLine2?: string
|
|
387
|
+
zip: string
|
|
388
|
+
city: string
|
|
389
|
+
state?: string
|
|
390
|
+
countryAlpha2: string
|
|
391
|
+
}
|
|
392
|
+
shipping?: {
|
|
393
|
+
addressLine: string
|
|
394
|
+
addressLine2?: string
|
|
395
|
+
zip: string
|
|
396
|
+
city: string
|
|
397
|
+
state?: string
|
|
398
|
+
countryAlpha2: string
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export type PayOpts = {
|
|
403
|
+
source: string
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export type PayFn = (Opts: PayOpts) => Promise<unknown>
|
|
407
|
+
|
|
408
|
+
export type UpdateTransactionDetailsFn = (
|
|
409
|
+
config: UpdateTransactionDetailsOpts
|
|
410
|
+
) => Promise<unknown>
|
|
411
|
+
|
|
412
|
+
export type CheckoutObject = {
|
|
413
|
+
on: ListenerFn
|
|
414
|
+
once: ListenerFn
|
|
415
|
+
removeListener: ListenerFn
|
|
416
|
+
EVENT_TYPES: typeof EVENT_TYPES
|
|
417
|
+
render: RenderFn
|
|
418
|
+
paypal: PaypalFn
|
|
419
|
+
universal: UniversalFn
|
|
420
|
+
update: UpdateFn
|
|
421
|
+
updateTransactionDetails: UpdateTransactionDetailsFn
|
|
422
|
+
submit: SubmitFn
|
|
423
|
+
blur: BlurFn
|
|
424
|
+
validate: ValidateFn
|
|
425
|
+
reset: ResetFn
|
|
426
|
+
pay: PayFn
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export type CheckoutFunction = (opts: CheckoutOpts) => CheckoutObject
|
|
430
|
+
|
|
431
|
+
export type PayComFunction = (opts: PayComOpts) => Promise<{
|
|
432
|
+
checkout: CheckoutFunction
|
|
433
|
+
}>
|
|
434
|
+
|
|
435
|
+
export interface PayComNamespace {
|
|
436
|
+
com: PayComFunction
|
|
437
|
+
riskIdentifier: string
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
declare module '@pay-com/js' {
|
|
441
|
+
export function loadScript(
|
|
442
|
+
options: PayComScriptOptions,
|
|
443
|
+
PromisePonyfill?: PromiseConstructor
|
|
444
|
+
): Promise<PayComNamespace>
|
|
445
|
+
|
|
446
|
+
export function loadCustomScript(options: {
|
|
447
|
+
url: string
|
|
448
|
+
attributes?: Record<string, string>
|
|
449
|
+
PromisePonyfill?: PromiseConstructor
|
|
450
|
+
}): Promise<void>
|
|
451
|
+
|
|
452
|
+
export const version: string
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
declare global {
|
|
456
|
+
interface Window {
|
|
457
|
+
Pay?: PayComNamespace
|
|
458
|
+
}
|
|
459
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type StringMap = Record<string, string>;
|
|
2
|
+
export declare const findScript: (url: string, attributes?: StringMap) => HTMLScriptElement | null;
|
|
3
|
+
export interface ScriptElement {
|
|
4
|
+
url: string;
|
|
5
|
+
attributes?: StringMap;
|
|
6
|
+
onSuccess: () => void;
|
|
7
|
+
onError: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const insertScriptElement: ({ url, attributes, onSuccess, onError }: ScriptElement) => void;
|
|
10
|
+
export declare const getDefaultPromiseImplementation: () => PromiseConstructor;
|
|
11
|
+
export declare const validateArguments: (options: unknown, PromisePonyfill?: unknown) => void;
|
|
12
|
+
export declare const objectToQueryString: (params: StringMap) => string;
|
|
13
|
+
export interface AttachScriptListenersI {
|
|
14
|
+
script: HTMLScriptElement;
|
|
15
|
+
onSuccess: () => void;
|
|
16
|
+
onError: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare const attachScriptListeners: ({ script, onSuccess, onError }: AttachScriptListenersI) => void;
|
|
19
|
+
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -440,7 +440,7 @@ declare module '@pay-com/js' {
|
|
|
440
440
|
export function loadScript(
|
|
441
441
|
options: PayComScriptOptions,
|
|
442
442
|
PromisePonyfill?: PromiseConstructor
|
|
443
|
-
): Promise<PayComNamespace
|
|
443
|
+
): Promise<PayComNamespace>
|
|
444
444
|
|
|
445
445
|
export function loadCustomScript(options: {
|
|
446
446
|
url: string
|
package/lib/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=function(){return e=Object.assign||function(e){for(var t
|
|
1
|
+
var e=function(){return e=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},e.apply(this,arguments)};function r(e,r,t,n){return new(t||(t=Promise))((function(o,i){function c(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(c,u)}a((n=n.apply(e,r||[])).next())}))}function t(e,r){var t,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(a){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(c=0)),c;)try{if(t=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return c.label++,{value:u[1],done:!1};case 5:c.label++,n=u[1],u=[0];continue;case 7:u=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){c=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){c.label=u[1];break}if(6===u[0]&&c.label<o[1]){c.label=o[1],o=u;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(u);break}o[2]&&c.ops.pop(),c.trys.pop();continue}u=r.call(e,c)}catch(e){u=[6,e],n=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}"function"==typeof SuppressedError&&SuppressedError;var n=function(e,r){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==r&&"function"!=typeof r)throw new Error("Expected PromisePonyfill to be a function.")},o=function(e){var r=e.script,t=e.onSuccess,n=e.onError;r.addEventListener("load",t,!1),r.addEventListener("error",n,!1)},i=function(e,r){void 0===r&&(r={});var t=document.createElement("script");return t.src=e,Object.keys(r).forEach((function(e){t.setAttribute(e,r[e]),"data-csp-nonce"===e&&t.setAttribute("nonce",r["data-csp-nonce"])})),t},c=function(r,t){n(r,t);var c=r.live,a=r.sdkUrlOverride,s=c?"https://js.pay.com/v1.js":"https://js.staging.pay.com/v1.js";a&&(s=a);var l=window.Pay,f=function(r,t){var n=document.querySelector('script[src="'.concat(r,'"]'));if(!n)return null;var o=i(r,t),c=e({},n.dataset);return delete c.uidAuto,Object.keys(c).length!==Object.keys(o.dataset).length?null:Object.entries(c).every((function(e){var r=e[0];return e[1]===o.dataset[r]}))?n:null}(s);return f&&l?t.resolve(l):f?new t((function(e,r){o({script:f,onSuccess:function(){var t=window.Pay;if(t)return e(t);r(new Error("The script failed to load."))},onError:function(){return r(new Error("The script failed to load."))}})})):u({url:s},t).then((function(){var e=window.Pay;if(e)return e;throw new Error("The window.Pay global variable is not available.")}))},u=function(e,r){n(e,r);var t=e.url,c=e.attributes;if("string"!=typeof t||0===t.length)throw new Error("Invalid url.");if(void 0!==c&&"object"!=typeof c)throw new Error("Expected attributes to be an object.");return new r((function(e,r){return function(e){var r=e.url,t=e.attributes,n=e.onSuccess,c=e.onError,u=i(r,t);o({script:u,onSuccess:n,onError:c}),document.head.insertBefore(u,document.head.firstElementChild)}({url:t,attributes:c,onSuccess:function(){return e()},onError:function(){return r(new Error('The script "'.concat(t,'" failed to load.')))}})}))},a={com:function(e,n){return void 0===n&&(n=function(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}()),r(void 0,void 0,void 0,(function(){return t(this,(function(r){switch(r.label){case 0:return[4,c(e,n)];case 1:return[2,r.sent().com(e)]}}))}))}};export{a as default};
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Pay=t()}(this,(function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}a((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function r(e,t){void 0===t&&(t={});var n=document.createElement("script");return n.src=e,Object.keys(t).forEach((function(e){n.setAttribute(e,t[e]),"data-csp-nonce"===e&&n.setAttribute("nonce",t["data-csp-nonce"])})),n}function
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Pay=t()}(this,(function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}a((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError;var r=function(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")},o=function(e){var t=e.script,n=e.onSuccess,r=e.onError;t.addEventListener("load",n,!1),t.addEventListener("error",r,!1)},i=function(e,t){void 0===t&&(t={});var n=document.createElement("script");return n.src=e,Object.keys(t).forEach((function(e){n.setAttribute(e,t[e]),"data-csp-nonce"===e&&n.setAttribute("nonce",t["data-csp-nonce"])})),n},u=function(t,n){r(t,n);var u=t.live,a=t.sdkUrlOverride,s=u?"https://js.pay.com/v1.js":"https://js.staging.pay.com/v1.js";a&&(s=a);var l=window.Pay,f=function(t,n){var r=document.querySelector('script[src="'.concat(t,'"]'));if(!r)return null;var o=i(t,n),u=e({},r.dataset);return delete u.uidAuto,Object.keys(u).length!==Object.keys(o.dataset).length?null:Object.entries(u).every((function(e){var t=e[0];return e[1]===o.dataset[t]}))?r:null}(s);return f&&l?n.resolve(l):f?new n((function(e,t){o({script:f,onSuccess:function(){var n=window.Pay;if(n)return e(n);t(new Error("The script failed to load."))},onError:function(){return t(new Error("The script failed to load."))}})})):c({url:s},n).then((function(){var e=window.Pay;if(e)return e;throw new Error("The window.Pay global variable is not available.")}))},c=function(e,t){r(e,t);var n=e.url,u=e.attributes;if("string"!=typeof n||0===n.length)throw new Error("Invalid url.");if(void 0!==u&&"object"!=typeof u)throw new Error("Expected attributes to be an object.");return new t((function(e,t){return function(e){var t=e.url,n=e.attributes,r=e.onSuccess,u=e.onError,c=i(t,n);o({script:c,onSuccess:r,onError:u}),document.head.insertBefore(c,document.head.firstElementChild)}({url:n,attributes:u,onSuccess:function(){return e()},onError:function(){return t(new Error('The script "'.concat(n,'" failed to load.')))}})}))};return{com:function(e,r){return void 0===r&&(r=function(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}()),t(void 0,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,u(e,r)];case 1:return[2,t.sent().com(e)]}}))}))}}}));
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pay-com/js",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.1.8",
|
|
4
|
+
"description": "Pay.com JS loading utility",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"Pay.com",
|
|
7
|
+
"Pay.com js",
|
|
8
|
+
"Pay Components"
|
|
7
9
|
],
|
|
8
10
|
"license": "MIT",
|
|
9
11
|
"author": "Pay.com",
|
|
@@ -20,7 +22,7 @@
|
|
|
20
22
|
},
|
|
21
23
|
"files": [
|
|
22
24
|
"lib/*.js",
|
|
23
|
-
"lib
|
|
25
|
+
"lib/**/*.d.ts"
|
|
24
26
|
],
|
|
25
27
|
"scripts": {
|
|
26
28
|
"build:watch": "rollup -c --watch",
|