@idonatedev/idonate-sdk 1.2.0-dev0 → 1.2.0-dev10
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/constants.js +11 -2
- package/dist/esm/constants.js +11 -2
- package/dist/esm/recaptcha.d.ts +1 -0
- package/dist/esm/recaptcha.js +17 -0
- package/dist/esm/tokenize/CardConnectTokenizer.d.ts +1 -1
- package/dist/esm/tokenize/CardConnectTokenizer.js +71 -28
- package/dist/esm/tokenize/PayPalTokenizer.d.ts +5 -1
- package/dist/esm/tokenize/PayPalTokenizer.js +24 -20
- package/dist/esm/tokenize/SpreedlyTokenizer.d.ts +9 -2
- package/dist/esm/tokenize/SpreedlyTokenizer.js +90 -19
- package/dist/esm/tokenize/Tokenizer.d.ts +2 -0
- package/dist/esm/tokenize/Tokenizer.js +14 -0
- package/dist/esm/tokenize/index.d.ts +1 -1
- package/dist/esm/tokenize/styles.d.ts +1 -1
- package/dist/esm/tokenize/styles.js +6 -0
- package/dist/esm/tokenize/tokenizer-constants.d.ts +1 -0
- package/dist/esm/tokenize/tokenizer-constants.js +1 -0
- package/dist/esm/tokenize/types.d.ts +13 -7
- package/dist/recaptcha.d.ts +1 -0
- package/dist/recaptcha.js +18 -0
- package/dist/tokenize/CardConnectTokenizer.d.ts +1 -1
- package/dist/tokenize/CardConnectTokenizer.js +70 -27
- package/dist/tokenize/PayPalTokenizer.d.ts +5 -1
- package/dist/tokenize/PayPalTokenizer.js +24 -20
- package/dist/tokenize/SpreedlyTokenizer.d.ts +9 -2
- package/dist/tokenize/SpreedlyTokenizer.js +89 -18
- package/dist/tokenize/Tokenizer.d.ts +2 -0
- package/dist/tokenize/Tokenizer.js +14 -0
- package/dist/tokenize/index.d.ts +1 -1
- package/dist/tokenize/styles.d.ts +1 -1
- package/dist/tokenize/styles.js +6 -0
- package/dist/tokenize/tokenizer-constants.d.ts +1 -0
- package/dist/tokenize/tokenizer-constants.js +2 -1
- package/dist/tokenize/types.d.ts +13 -7
- package/package.json +13 -2
- package/umd/idonate-sdk.js +1 -1
|
@@ -31,11 +31,14 @@ interface PayPalApproveData {
|
|
|
31
31
|
payerID?: string;
|
|
32
32
|
facilitatorAccessToken?: string;
|
|
33
33
|
}
|
|
34
|
+
export interface PayPalCreateOrderData {
|
|
35
|
+
amount: number;
|
|
36
|
+
currency?: string;
|
|
37
|
+
}
|
|
34
38
|
export declare class PayPalTokenizer extends Tokenizer {
|
|
35
39
|
private gateway;
|
|
36
40
|
private containerId;
|
|
37
41
|
private configContext;
|
|
38
|
-
private isReady;
|
|
39
42
|
private containerEl?;
|
|
40
43
|
private paypalButtonContainer?;
|
|
41
44
|
private cachedToken?;
|
|
@@ -50,6 +53,7 @@ export declare class PayPalTokenizer extends Tokenizer {
|
|
|
50
53
|
private clientConfig;
|
|
51
54
|
private paymentTransactionId?;
|
|
52
55
|
private paymentMethodId?;
|
|
56
|
+
private onCreateOrder?;
|
|
53
57
|
private constructor();
|
|
54
58
|
static create(gateway: PaymentGateway, container: TokenizerContainer, config: {
|
|
55
59
|
organizationId: string;
|
|
@@ -22,7 +22,6 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
22
22
|
this.gateway = gateway;
|
|
23
23
|
this.containerId = containerId;
|
|
24
24
|
this.configContext = configContext;
|
|
25
|
-
this.isReady = false;
|
|
26
25
|
this.mode = 'credit_card';
|
|
27
26
|
const gatewayConfig = gateway.config;
|
|
28
27
|
if (!(gatewayConfig === null || gatewayConfig === void 0 ? void 0 : gatewayConfig.client_id)) {
|
|
@@ -34,6 +33,7 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
34
33
|
this.amount = config.amount;
|
|
35
34
|
this.enableVenmo = (_b = config.enableVenmo) !== null && _b !== void 0 ? _b : true;
|
|
36
35
|
this.locale = config.locale || 'en_US';
|
|
36
|
+
this.onCreateOrder = config.onCreateOrder;
|
|
37
37
|
this.organizationId = configContext.organizationId;
|
|
38
38
|
this.embedId = configContext.embedId;
|
|
39
39
|
this.clientConfig = configContext.clientConfig;
|
|
@@ -68,17 +68,13 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
68
68
|
return this.renderButtons();
|
|
69
69
|
})
|
|
70
70
|
.then(() => {
|
|
71
|
-
this.isReady = true;
|
|
72
71
|
this.emit('ready');
|
|
72
|
+
this.emit('validation', { isValid: true });
|
|
73
73
|
resolve();
|
|
74
74
|
})
|
|
75
75
|
.catch((error) => {
|
|
76
76
|
clearTimeout(timeout);
|
|
77
|
-
this.emit('error',
|
|
78
|
-
message: 'Failed to initialize PayPal',
|
|
79
|
-
code: 'INIT_FAILED',
|
|
80
|
-
details: error,
|
|
81
|
-
});
|
|
77
|
+
this.emit('error', new types_1.TokenizationError('Failed to initialize PayPal', 'INIT_FAILED'));
|
|
82
78
|
reject(error);
|
|
83
79
|
});
|
|
84
80
|
});
|
|
@@ -168,13 +164,26 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
168
164
|
}
|
|
169
165
|
createOrder() {
|
|
170
166
|
const endpoint = `${this.clientConfig.embedApiBaseUrl}/payment/paypal/create-order`;
|
|
167
|
+
let orderAmount;
|
|
168
|
+
let orderCurrency = this.currency;
|
|
169
|
+
if (this.onCreateOrder) {
|
|
170
|
+
const orderData = this.onCreateOrder();
|
|
171
|
+
orderAmount = orderData.amount;
|
|
172
|
+
orderCurrency = orderData.currency || this.currency;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
orderAmount = this.amount;
|
|
176
|
+
}
|
|
177
|
+
if (orderAmount === undefined || orderAmount <= 0) {
|
|
178
|
+
const error = new Error('Amount is required to create PayPal order');
|
|
179
|
+
this.handleError(error, 'Order creation failed');
|
|
180
|
+
return Promise.reject(error);
|
|
181
|
+
}
|
|
171
182
|
const requestBody = {
|
|
172
183
|
payment_gateway_id: this.gateway.id,
|
|
173
|
-
currency:
|
|
184
|
+
currency: orderCurrency,
|
|
185
|
+
amount: orderAmount,
|
|
174
186
|
};
|
|
175
|
-
if (this.amount !== undefined) {
|
|
176
|
-
requestBody.amount = this.amount;
|
|
177
|
-
}
|
|
178
187
|
return fetch(endpoint, {
|
|
179
188
|
method: 'POST',
|
|
180
189
|
headers: {
|
|
@@ -211,22 +220,16 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
211
220
|
paymentTransactionId: this.paymentTransactionId,
|
|
212
221
|
};
|
|
213
222
|
this.cachedToken = token;
|
|
223
|
+
this.emit('validation', { isValid: true, hasToken: true });
|
|
214
224
|
this.emit('tokenReady', token);
|
|
215
225
|
});
|
|
216
226
|
}
|
|
217
227
|
handleCancel(data) {
|
|
218
|
-
this.emit('error',
|
|
219
|
-
message: 'Payment cancelled by user',
|
|
220
|
-
code: 'USER_CANCELLED',
|
|
221
|
-
});
|
|
228
|
+
this.emit('error', new types_1.TokenizationError('Payment cancelled by user', 'USER_CANCELLED'));
|
|
222
229
|
}
|
|
223
230
|
handleError(error, context) {
|
|
224
231
|
const errorMessage = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString()) || 'Unknown error';
|
|
225
|
-
this.emit('error', {
|
|
226
|
-
message: `${context}: ${errorMessage}`,
|
|
227
|
-
code: (error === null || error === void 0 ? void 0 : error.code) || 'PAYPAL_ERROR',
|
|
228
|
-
details: error,
|
|
229
|
-
});
|
|
232
|
+
this.emit('error', new types_1.TokenizationError(`${context}: ${errorMessage}`, (error === null || error === void 0 ? void 0 : error.code) || 'PAYPAL_ERROR'));
|
|
230
233
|
}
|
|
231
234
|
tokenize(paymentData) {
|
|
232
235
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -249,6 +252,7 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
249
252
|
}
|
|
250
253
|
clear() {
|
|
251
254
|
this.cachedToken = undefined;
|
|
255
|
+
this.emit('validation', { isValid: true, hasToken: false });
|
|
252
256
|
}
|
|
253
257
|
focus(field) {
|
|
254
258
|
}
|
|
@@ -7,7 +7,6 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
7
7
|
private containerId;
|
|
8
8
|
private layout;
|
|
9
9
|
private spreedly;
|
|
10
|
-
private isReady;
|
|
11
10
|
private currentValidationState;
|
|
12
11
|
private mergedStyles;
|
|
13
12
|
private expiryEl?;
|
|
@@ -25,6 +24,11 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
25
24
|
private institutionNumberEl?;
|
|
26
25
|
private transitNumberEl?;
|
|
27
26
|
private enableTestMode;
|
|
27
|
+
private resizeObserver?;
|
|
28
|
+
private effectiveLayout;
|
|
29
|
+
private cardNumberDiv?;
|
|
30
|
+
private cvvDiv?;
|
|
31
|
+
private responsiveBreakpoint;
|
|
28
32
|
private constructor();
|
|
29
33
|
static create(gateway: PaymentGateway, container: TokenizerContainer, config: {
|
|
30
34
|
organizationId: string;
|
|
@@ -43,6 +47,9 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
43
47
|
private stylesToCssString;
|
|
44
48
|
clear(): void;
|
|
45
49
|
focus(field: 'cardNumber' | 'cvv' | 'expiry' | 'routingNumber' | 'accountNumber'): void;
|
|
50
|
+
private determineLayout;
|
|
51
|
+
private setupResizeObserver;
|
|
52
|
+
private applyLayoutStyles;
|
|
46
53
|
destroy(): void;
|
|
47
54
|
hasToken(): boolean;
|
|
48
55
|
getToken(): PaymentToken | null;
|
|
@@ -68,7 +75,7 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
68
75
|
});
|
|
69
76
|
address: Partial<Address>;
|
|
70
77
|
account: Partial<ACHAccount> & Pick<ACHAccount, 'accountNumber' | 'routingNumber'>;
|
|
71
|
-
}, config: ConfigHandler): Promise<string>;
|
|
78
|
+
}, config: ConfigHandler, environmentKeyOverride?: string): Promise<string>;
|
|
72
79
|
static tokenizeCreditCard(data: {
|
|
73
80
|
contact: Partial<Contact> & ({
|
|
74
81
|
firstName: string;
|
|
@@ -21,17 +21,19 @@ const tokenizer_utils_1 = require("./tokenizer-utils");
|
|
|
21
21
|
const SPREEDLY_SCRIPT_URL = 'https://core.spreedly.com/iframe/iframe-v1.min.js';
|
|
22
22
|
const SPREEDLY_SCRIPT_ID = 'spreedly-iframe-script';
|
|
23
23
|
class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
24
|
-
constructor(environmentKey, containerId, styles, mode = 'credit_card', bankCountry = 'US', enableTestMode = false, layout = 'single-line') {
|
|
24
|
+
constructor(environmentKey, containerId, styles, mode = 'credit_card', bankCountry = 'US', enableTestMode = false, layout = 'single-line', responsiveBreakpoint = tokenizer_constants_1.RESPONSIVE_BREAKPOINT) {
|
|
25
25
|
super();
|
|
26
26
|
this.environmentKey = environmentKey;
|
|
27
27
|
this.containerId = containerId;
|
|
28
28
|
this.layout = layout;
|
|
29
|
-
this.isReady = false;
|
|
30
29
|
this.bankCountry = 'US';
|
|
31
30
|
this.enableTestMode = false;
|
|
31
|
+
this.effectiveLayout = 'single-line';
|
|
32
|
+
this.responsiveBreakpoint = tokenizer_constants_1.RESPONSIVE_BREAKPOINT;
|
|
32
33
|
this.mode = mode;
|
|
33
34
|
this.bankCountry = bankCountry;
|
|
34
35
|
this.enableTestMode = enableTestMode;
|
|
36
|
+
this.responsiveBreakpoint = responsiveBreakpoint;
|
|
35
37
|
if (mode === 'credit_card') {
|
|
36
38
|
const SpreedlyFrame = window.SpreedlyPaymentFrame;
|
|
37
39
|
if (SpreedlyFrame) {
|
|
@@ -78,7 +80,7 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
78
80
|
if (!environmentKey) {
|
|
79
81
|
environmentKey = '';
|
|
80
82
|
}
|
|
81
|
-
const tokenizer = new SpreedlyTokenizer(environmentKey, container.containerId, container.styling, container.mode || 'credit_card', container.bankCountry || 'US', container.enableTestMode || false, container.layout || 'single-line');
|
|
83
|
+
const tokenizer = new SpreedlyTokenizer(environmentKey, container.containerId, container.styling, container.mode || 'credit_card', container.bankCountry || 'US', container.enableTestMode || false, container.layout || 'single-line', container.responsiveBreakpoint || tokenizer_constants_1.RESPONSIVE_BREAKPOINT);
|
|
82
84
|
tokenizer.organizationId = config.organizationId;
|
|
83
85
|
tokenizer.embedId = config.embedId;
|
|
84
86
|
tokenizer.clientConfig = config.clientConfig;
|
|
@@ -104,7 +106,6 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
104
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
107
|
this.containerEl = document.getElementById(this.containerId);
|
|
106
108
|
if (this.mode === 'bank_account') {
|
|
107
|
-
this.isReady = true;
|
|
108
109
|
if (this.enableTestMode) {
|
|
109
110
|
setTimeout(() => {
|
|
110
111
|
if (this.bankCountry === 'CA') {
|
|
@@ -146,7 +147,6 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
146
147
|
}, tokenizer_constants_1.INIT_TIMEOUT);
|
|
147
148
|
this.spreedly.on('ready', () => {
|
|
148
149
|
clearTimeout(timeout);
|
|
149
|
-
this.isReady = true;
|
|
150
150
|
this.spreedly.setPlaceholder('number', tokenizer_constants_1.PLACEHOLDERS.cardNumber);
|
|
151
151
|
this.spreedly.setFieldType('number', 'text');
|
|
152
152
|
this.spreedly.setNumberFormat('prettyFormat');
|
|
@@ -247,11 +247,11 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
247
247
|
year: expiryYear,
|
|
248
248
|
email: cardData.email,
|
|
249
249
|
phone_number: cardData.phone,
|
|
250
|
-
address1: (_a = cardData.address) === null || _a === void 0 ? void 0 : _a.
|
|
251
|
-
address2: (_b = cardData.address) === null || _b === void 0 ? void 0 : _b.
|
|
250
|
+
address1: (_a = cardData.address) === null || _a === void 0 ? void 0 : _a.address1,
|
|
251
|
+
address2: (_b = cardData.address) === null || _b === void 0 ? void 0 : _b.address2,
|
|
252
252
|
city: (_c = cardData.address) === null || _c === void 0 ? void 0 : _c.city,
|
|
253
253
|
state: (_d = cardData.address) === null || _d === void 0 ? void 0 : _d.state,
|
|
254
|
-
zip: (_e = cardData.address) === null || _e === void 0 ? void 0 : _e.
|
|
254
|
+
zip: (_e = cardData.address) === null || _e === void 0 ? void 0 : _e.zip,
|
|
255
255
|
country: (_f = cardData.address) === null || _f === void 0 ? void 0 : _f.country,
|
|
256
256
|
});
|
|
257
257
|
});
|
|
@@ -432,11 +432,11 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
432
432
|
primaryPhone: bankData.phone,
|
|
433
433
|
},
|
|
434
434
|
address: {
|
|
435
|
-
address1: (_g = bankData.address) === null || _g === void 0 ? void 0 : _g.
|
|
436
|
-
address2: (_h = bankData.address) === null || _h === void 0 ? void 0 : _h.
|
|
435
|
+
address1: (_g = bankData.address) === null || _g === void 0 ? void 0 : _g.address1,
|
|
436
|
+
address2: (_h = bankData.address) === null || _h === void 0 ? void 0 : _h.address2,
|
|
437
437
|
city: (_j = bankData.address) === null || _j === void 0 ? void 0 : _j.city,
|
|
438
438
|
state: (_k = bankData.address) === null || _k === void 0 ? void 0 : _k.state,
|
|
439
|
-
zip: (_l = bankData.address) === null || _l === void 0 ? void 0 : _l.
|
|
439
|
+
zip: (_l = bankData.address) === null || _l === void 0 ? void 0 : _l.zip,
|
|
440
440
|
country: (_m = bankData.address) === null || _m === void 0 ? void 0 : _m.country,
|
|
441
441
|
},
|
|
442
442
|
account: {
|
|
@@ -445,7 +445,7 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
445
445
|
accountType: accountType,
|
|
446
446
|
accountHolderType: accountHolderType,
|
|
447
447
|
},
|
|
448
|
-
}, this.clientConfig);
|
|
448
|
+
}, this.clientConfig, this.environmentKey);
|
|
449
449
|
return {
|
|
450
450
|
token: result,
|
|
451
451
|
lastFour: accountNumber.slice(-4),
|
|
@@ -588,8 +588,6 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
588
588
|
}
|
|
589
589
|
applyUnifiedStyles() {
|
|
590
590
|
var _a;
|
|
591
|
-
if (!this.isReady)
|
|
592
|
-
return;
|
|
593
591
|
const isConnected = ((_a = this.mergedStyles.container) === null || _a === void 0 ? void 0 : _a.gap) === '0';
|
|
594
592
|
if (this.mergedStyles.input) {
|
|
595
593
|
if (isConnected) {
|
|
@@ -688,7 +686,64 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
688
686
|
element === null || element === void 0 ? void 0 : element.focus();
|
|
689
687
|
}
|
|
690
688
|
}
|
|
689
|
+
determineLayout(width) {
|
|
690
|
+
return width < this.responsiveBreakpoint ? 'two-line' : 'single-line';
|
|
691
|
+
}
|
|
692
|
+
setupResizeObserver() {
|
|
693
|
+
if (this.layout !== 'responsive')
|
|
694
|
+
return;
|
|
695
|
+
const container = document.getElementById(this.containerId);
|
|
696
|
+
if (!container)
|
|
697
|
+
return;
|
|
698
|
+
let debounceTimer;
|
|
699
|
+
this.resizeObserver = new ResizeObserver((entries) => {
|
|
700
|
+
clearTimeout(debounceTimer);
|
|
701
|
+
debounceTimer = setTimeout(() => {
|
|
702
|
+
const newWidth = entries[0].contentRect.width;
|
|
703
|
+
const newLayout = this.determineLayout(newWidth);
|
|
704
|
+
if (newLayout !== this.effectiveLayout) {
|
|
705
|
+
this.applyLayoutStyles(newLayout);
|
|
706
|
+
}
|
|
707
|
+
}, 100);
|
|
708
|
+
});
|
|
709
|
+
this.resizeObserver.observe(container);
|
|
710
|
+
}
|
|
711
|
+
applyLayoutStyles(newLayout) {
|
|
712
|
+
this.effectiveLayout = newLayout;
|
|
713
|
+
const container = document.getElementById(this.containerId);
|
|
714
|
+
if (!container)
|
|
715
|
+
return;
|
|
716
|
+
if (newLayout === 'two-line') {
|
|
717
|
+
container.style.flexWrap = 'wrap';
|
|
718
|
+
if (this.cardNumberDiv) {
|
|
719
|
+
this.cardNumberDiv.style.flex = '1';
|
|
720
|
+
this.cardNumberDiv.style.flexBasis = '100%';
|
|
721
|
+
}
|
|
722
|
+
if (this.expiryEl) {
|
|
723
|
+
this.expiryEl.style.flex = '1';
|
|
724
|
+
this.expiryEl.style.flexBasis = 'auto';
|
|
725
|
+
}
|
|
726
|
+
if (this.cvvDiv) {
|
|
727
|
+
this.cvvDiv.style.flex = '1';
|
|
728
|
+
this.cvvDiv.style.flexBasis = 'auto';
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
container.style.flexWrap = 'nowrap';
|
|
733
|
+
if (this.cardNumberDiv) {
|
|
734
|
+
this.cardNumberDiv.style.flex = tokenizer_constants_1.FIELD_FLEX.cardNumber.flex;
|
|
735
|
+
}
|
|
736
|
+
if (this.expiryEl) {
|
|
737
|
+
this.expiryEl.style.flex = tokenizer_constants_1.FIELD_FLEX.expiry.flex;
|
|
738
|
+
}
|
|
739
|
+
if (this.cvvDiv) {
|
|
740
|
+
this.cvvDiv.style.flex = tokenizer_constants_1.FIELD_FLEX.cvv.flex;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
691
744
|
destroy() {
|
|
745
|
+
var _a;
|
|
746
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
692
747
|
if (this.spreedly && this.spreedly.removeHandlers) {
|
|
693
748
|
this.spreedly.removeHandlers();
|
|
694
749
|
}
|
|
@@ -765,10 +820,18 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
765
820
|
}
|
|
766
821
|
}
|
|
767
822
|
createCreditCardFields(container) {
|
|
768
|
-
if (this.layout === '
|
|
823
|
+
if (this.layout === 'responsive') {
|
|
824
|
+
this.effectiveLayout = this.determineLayout(container.offsetWidth);
|
|
825
|
+
}
|
|
826
|
+
else {
|
|
827
|
+
this.effectiveLayout =
|
|
828
|
+
this.layout === 'two-line' ? 'two-line' : 'single-line';
|
|
829
|
+
}
|
|
830
|
+
if (this.effectiveLayout === 'two-line' && this.layout !== 'responsive') {
|
|
769
831
|
const cardNumberDiv = (0, tokenizer_utils_1.createFieldContainer)(this.numberEl, '1', tokenizer_constants_1.FIELD_FLEX.cardNumber.minWidth);
|
|
770
832
|
cardNumberDiv.style.height = this.mergedStyles.input.height;
|
|
771
833
|
cardNumberDiv.style.flexBasis = '100%';
|
|
834
|
+
this.cardNumberDiv = cardNumberDiv;
|
|
772
835
|
container.appendChild(cardNumberDiv);
|
|
773
836
|
this.expiryEl = (0, tokenizer_utils_1.createInputElement)(this.expiryId, 'text', tokenizer_constants_1.PLACEHOLDERS.expiry, tokenizer_constants_1.FIELD_CONSTRAINTS.expiry.maxLength);
|
|
774
837
|
Object.assign(this.expiryEl.style, {
|
|
@@ -789,11 +852,13 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
789
852
|
container.appendChild(this.expiryEl);
|
|
790
853
|
const cvvDiv = (0, tokenizer_utils_1.createFieldContainer)(this.cvvEl, '1', tokenizer_constants_1.FIELD_FLEX.cvv.minWidth);
|
|
791
854
|
cvvDiv.style.height = this.mergedStyles.input.height;
|
|
855
|
+
this.cvvDiv = cvvDiv;
|
|
792
856
|
container.appendChild(cvvDiv);
|
|
793
857
|
}
|
|
794
858
|
else {
|
|
795
859
|
const cardNumberDiv = (0, tokenizer_utils_1.createFieldContainer)(this.numberEl, tokenizer_constants_1.FIELD_FLEX.cardNumber.flex, tokenizer_constants_1.FIELD_FLEX.cardNumber.minWidth);
|
|
796
860
|
cardNumberDiv.style.height = this.mergedStyles.input.height;
|
|
861
|
+
this.cardNumberDiv = cardNumberDiv;
|
|
797
862
|
container.appendChild(cardNumberDiv);
|
|
798
863
|
this.expiryEl = (0, tokenizer_utils_1.createInputElement)(this.expiryId, 'text', tokenizer_constants_1.PLACEHOLDERS.expiry, tokenizer_constants_1.FIELD_CONSTRAINTS.expiry.maxLength);
|
|
799
864
|
Object.assign(this.expiryEl.style, {
|
|
@@ -814,7 +879,12 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
814
879
|
container.appendChild(this.expiryEl);
|
|
815
880
|
const cvvDiv = (0, tokenizer_utils_1.createFieldContainer)(this.cvvEl, tokenizer_constants_1.FIELD_FLEX.cvv.flex, tokenizer_constants_1.FIELD_FLEX.cvv.minWidth);
|
|
816
881
|
cvvDiv.style.height = this.mergedStyles.input.height;
|
|
882
|
+
this.cvvDiv = cvvDiv;
|
|
817
883
|
container.appendChild(cvvDiv);
|
|
884
|
+
if (this.layout === 'responsive') {
|
|
885
|
+
this.applyLayoutStyles(this.effectiveLayout);
|
|
886
|
+
this.setupResizeObserver();
|
|
887
|
+
}
|
|
818
888
|
}
|
|
819
889
|
}
|
|
820
890
|
createBankAccountFields(container) {
|
|
@@ -1038,13 +1108,14 @@ class SpreedlyTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
1038
1108
|
throw new Error(`Timeout waiting for global: ${globalName}`);
|
|
1039
1109
|
});
|
|
1040
1110
|
}
|
|
1041
|
-
static tokenizeBankAccount(data, config) {
|
|
1042
|
-
|
|
1111
|
+
static tokenizeBankAccount(data, config, environmentKeyOverride) {
|
|
1112
|
+
const environmentKey = environmentKeyOverride || config.spreedlyEnvironmentKey;
|
|
1113
|
+
if (!environmentKey) {
|
|
1043
1114
|
return Promise.reject(new Error('Spreedly is not configured.'));
|
|
1044
1115
|
}
|
|
1045
1116
|
return fetch(constants_1.SPREEDLY_TOKENIZER_URL +
|
|
1046
1117
|
'?' +
|
|
1047
|
-
new URLSearchParams({ environment_key:
|
|
1118
|
+
new URLSearchParams({ environment_key: environmentKey }), {
|
|
1048
1119
|
method: 'POST',
|
|
1049
1120
|
headers: {
|
|
1050
1121
|
'Content-Type': 'application/json',
|
|
@@ -3,6 +3,8 @@ import ConfigHandler from '../config-handler';
|
|
|
3
3
|
export declare abstract class Tokenizer {
|
|
4
4
|
protected mode: PaymentMethodMode;
|
|
5
5
|
protected eventHandlers: Map<TokenizerEvent, Set<(data?: any) => void>>;
|
|
6
|
+
private _isReady;
|
|
7
|
+
get isReady(): boolean;
|
|
6
8
|
abstract tokenize(paymentData: PaymentData): Promise<PaymentToken>;
|
|
7
9
|
abstract validate(): Promise<ValidationResult>;
|
|
8
10
|
abstract clear(): void;
|
|
@@ -48,6 +48,10 @@ class Tokenizer {
|
|
|
48
48
|
constructor() {
|
|
49
49
|
this.mode = 'credit_card';
|
|
50
50
|
this.eventHandlers = new Map();
|
|
51
|
+
this._isReady = false;
|
|
52
|
+
}
|
|
53
|
+
get isReady() {
|
|
54
|
+
return this._isReady;
|
|
51
55
|
}
|
|
52
56
|
getMode() {
|
|
53
57
|
return this.mode;
|
|
@@ -57,6 +61,13 @@ class Tokenizer {
|
|
|
57
61
|
this.eventHandlers.set(event, new Set());
|
|
58
62
|
}
|
|
59
63
|
this.eventHandlers.get(event).add(handler);
|
|
64
|
+
if (event === 'ready' && this._isReady) {
|
|
65
|
+
try {
|
|
66
|
+
handler();
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
}
|
|
70
|
+
}
|
|
60
71
|
}
|
|
61
72
|
off(event, handler) {
|
|
62
73
|
const handlers = this.eventHandlers.get(event);
|
|
@@ -65,6 +76,9 @@ class Tokenizer {
|
|
|
65
76
|
}
|
|
66
77
|
}
|
|
67
78
|
emit(event, data) {
|
|
79
|
+
if (event === 'ready') {
|
|
80
|
+
this._isReady = true;
|
|
81
|
+
}
|
|
68
82
|
const handlers = this.eventHandlers.get(event);
|
|
69
83
|
if (handlers) {
|
|
70
84
|
handlers.forEach((handler) => {
|
package/dist/tokenize/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import * as iats from './iats';
|
|
|
2
2
|
export { Tokenizer } from './Tokenizer';
|
|
3
3
|
export { SpreedlyTokenizer } from './SpreedlyTokenizer';
|
|
4
4
|
export { CardConnectTokenizer } from './CardConnectTokenizer';
|
|
5
|
-
export { PayPalTokenizer } from './PayPalTokenizer';
|
|
5
|
+
export { PayPalTokenizer, PayPalCreateOrderData } from './PayPalTokenizer';
|
|
6
6
|
export { PaymentMethodType, PaymentGateway, TokenizerContainer, TokenizerStyling, CardData, PaymentData, PaymentToken, CardType, TokenizerEvent, ValidationState, ValidationResult, ValidationError, TokenizationError, } from './types';
|
|
7
7
|
export { iats };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TokenizerStyling, TokenizerStylingComplete } from './types';
|
|
2
2
|
export declare const DEFAULT_UNIFIED_STYLES: TokenizerStylingComplete;
|
|
3
3
|
export declare function mergeStyles(defaults: TokenizerStylingComplete, userStyles?: TokenizerStyling): TokenizerStylingComplete;
|
|
4
|
-
export declare function getContainerStylesForLayout(baseStyles: TokenizerStylingComplete, layout?: 'single-line' | 'two-line'): TokenizerStylingComplete;
|
|
4
|
+
export declare function getContainerStylesForLayout(baseStyles: TokenizerStylingComplete, layout?: 'single-line' | 'two-line' | 'responsive'): TokenizerStylingComplete;
|
package/dist/tokenize/styles.js
CHANGED
|
@@ -32,6 +32,11 @@ exports.DEFAULT_UNIFIED_STYLES = {
|
|
|
32
32
|
flexWrap: 'nowrap',
|
|
33
33
|
rowGap: '1rem',
|
|
34
34
|
},
|
|
35
|
+
twoLine: {
|
|
36
|
+
padding: '',
|
|
37
|
+
fontSize: '',
|
|
38
|
+
textAlign: '',
|
|
39
|
+
},
|
|
35
40
|
};
|
|
36
41
|
function mergeStyles(defaults, userStyles) {
|
|
37
42
|
if (!userStyles)
|
|
@@ -41,6 +46,7 @@ function mergeStyles(defaults, userStyles) {
|
|
|
41
46
|
focus: Object.assign(Object.assign({}, defaults.focus), userStyles.focus),
|
|
42
47
|
error: Object.assign(Object.assign({}, defaults.error), userStyles.error),
|
|
43
48
|
container: Object.assign(Object.assign({}, defaults.container), userStyles.container),
|
|
49
|
+
twoLine: Object.assign(Object.assign({}, defaults.twoLine), userStyles.twoLine),
|
|
44
50
|
};
|
|
45
51
|
}
|
|
46
52
|
function getContainerStylesForLayout(baseStyles, layout = 'single-line') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIELD_CONSTRAINTS = exports.PLACEHOLDERS = exports.CANADIAN_BANK_FIELD_FLEX = exports.BANK_FIELD_FLEX = exports.FIELD_FLEX = exports.TOKENIZE_TIMEOUT = exports.INIT_TIMEOUT = void 0;
|
|
3
|
+
exports.RESPONSIVE_BREAKPOINT = exports.FIELD_CONSTRAINTS = exports.PLACEHOLDERS = exports.CANADIAN_BANK_FIELD_FLEX = exports.BANK_FIELD_FLEX = exports.FIELD_FLEX = exports.TOKENIZE_TIMEOUT = exports.INIT_TIMEOUT = void 0;
|
|
4
4
|
exports.INIT_TIMEOUT = 10000;
|
|
5
5
|
exports.TOKENIZE_TIMEOUT = 30000;
|
|
6
6
|
exports.FIELD_FLEX = {
|
|
@@ -63,3 +63,4 @@ exports.FIELD_CONSTRAINTS = {
|
|
|
63
63
|
maxLength: 4,
|
|
64
64
|
},
|
|
65
65
|
};
|
|
66
|
+
exports.RESPONSIVE_BREAKPOINT = 400;
|
package/dist/tokenize/types.d.ts
CHANGED
|
@@ -18,7 +18,8 @@ export interface TokenizerContainer {
|
|
|
18
18
|
mode?: PaymentMethodMode;
|
|
19
19
|
bankCountry?: 'US' | 'CA';
|
|
20
20
|
enableTestMode?: boolean;
|
|
21
|
-
layout?: 'single-line' | 'two-line';
|
|
21
|
+
layout?: 'single-line' | 'two-line' | 'responsive';
|
|
22
|
+
responsiveBreakpoint?: number;
|
|
22
23
|
}
|
|
23
24
|
export interface TokenizerStylingComplete {
|
|
24
25
|
input: {
|
|
@@ -52,6 +53,11 @@ export interface TokenizerStylingComplete {
|
|
|
52
53
|
flexWrap?: string;
|
|
53
54
|
rowGap?: string;
|
|
54
55
|
};
|
|
56
|
+
twoLine: {
|
|
57
|
+
padding: string;
|
|
58
|
+
fontSize: string;
|
|
59
|
+
textAlign: string;
|
|
60
|
+
};
|
|
55
61
|
}
|
|
56
62
|
type DeepPartial<T> = T extends object ? {
|
|
57
63
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
@@ -63,11 +69,11 @@ export interface CardData {
|
|
|
63
69
|
email?: string;
|
|
64
70
|
phone?: string;
|
|
65
71
|
address?: {
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
address1?: string;
|
|
73
|
+
address2?: string;
|
|
68
74
|
city?: string;
|
|
69
75
|
state?: string;
|
|
70
|
-
|
|
76
|
+
zip?: string;
|
|
71
77
|
country?: string;
|
|
72
78
|
};
|
|
73
79
|
}
|
|
@@ -77,11 +83,11 @@ export interface BankAccountData {
|
|
|
77
83
|
email?: string;
|
|
78
84
|
phone?: string;
|
|
79
85
|
address?: {
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
address1?: string;
|
|
87
|
+
address2?: string;
|
|
82
88
|
city?: string;
|
|
83
89
|
state?: string;
|
|
84
|
-
|
|
90
|
+
zip?: string;
|
|
85
91
|
country?: string;
|
|
86
92
|
};
|
|
87
93
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idonatedev/idonate-sdk",
|
|
3
3
|
"author": "iDonate",
|
|
4
|
-
"version": "1.2.0-
|
|
4
|
+
"version": "1.2.0-dev10",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "iDonate Web SDK",
|
|
7
7
|
"engines": {
|
|
@@ -16,6 +16,16 @@
|
|
|
16
16
|
"import": "./dist/esm/index.js",
|
|
17
17
|
"require": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./dist/cloudflare-challenge-handler": {
|
|
21
|
+
"import": "./dist/esm/cloudflare-challenge-handler.js",
|
|
22
|
+
"require": "./dist/cloudflare-challenge-handler.js",
|
|
23
|
+
"types": "./dist/cloudflare-challenge-handler.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./dist/idonate-client": {
|
|
26
|
+
"import": "./dist/esm/idonate-client.js",
|
|
27
|
+
"require": "./dist/idonate-client.js",
|
|
28
|
+
"types": "./dist/idonate-client.d.ts"
|
|
19
29
|
}
|
|
20
30
|
},
|
|
21
31
|
"files": [
|
|
@@ -79,5 +89,6 @@
|
|
|
79
89
|
"@types/spreedly-iframe-browser": "^1.0.3",
|
|
80
90
|
"@types/uuid": "^8.3.1",
|
|
81
91
|
"uuid": "^8.3.2"
|
|
82
|
-
}
|
|
92
|
+
},
|
|
93
|
+
"packageManager": "pnpm@10.15.1+sha512.34e538c329b5553014ca8e8f4535997f96180a1d0f614339357449935350d924e22f8614682191264ec33d1462ac21561aff97f6bb18065351c162c7e8f6de67"
|
|
83
94
|
}
|