@pay-com/js 1.1.6 → 1.1.7

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,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 | null>
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,10 @@
1
+ interface PayComScriptQueryParameters {
2
+ identifier: string
3
+ sandbox?: boolean
4
+ debug?: boolean
5
+ }
6
+
7
+ export interface PayComScriptOptions extends PayComScriptQueryParameters {
8
+ sdkUrlOverride?: string
9
+ live?: boolean
10
+ }
@@ -0,0 +1,11 @@
1
+ type StringMap = Record<string, string>;
2
+ export declare function findScript(url: string, attributes?: StringMap): HTMLScriptElement | null;
3
+ export interface ScriptElement {
4
+ url: string;
5
+ attributes?: StringMap;
6
+ onSuccess: () => void;
7
+ onError: OnErrorEventHandler;
8
+ }
9
+ export declare function insertScriptElement({ url, attributes, onSuccess, onError }: ScriptElement): void;
10
+ export declare function objectToQueryString(params: StringMap): string;
11
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pay-com/js",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "payments"
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "files": [
22
22
  "lib/*.js",
23
- "lib/*.d.ts"
23
+ "lib/**/*.d.ts"
24
24
  ],
25
25
  "scripts": {
26
26
  "build:watch": "rollup -c --watch",