@idonatedev/idonate-sdk 1.2.0-dev2 → 1.2.0-dev20
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/idonate-client.js +18 -8
- package/dist/esm/recaptcha.d.ts +1 -0
- package/dist/esm/recaptcha.js +26 -2
- package/dist/esm/shared.js +9 -1
- package/dist/esm/tokenize/CardConnectTokenizer.d.ts +8 -1
- package/dist/esm/tokenize/CardConnectTokenizer.js +353 -104
- package/dist/esm/tokenize/PayPalTokenizer.d.ts +6 -0
- package/dist/esm/tokenize/PayPalTokenizer.js +66 -16
- package/dist/esm/tokenize/SpreedlyTokenizer.d.ts +17 -1
- package/dist/esm/tokenize/SpreedlyTokenizer.js +270 -138
- package/dist/esm/tokenize/Tokenizer.d.ts +6 -2
- package/dist/esm/tokenize/Tokenizer.js +24 -8
- package/dist/esm/tokenize/gateway-utils.d.ts +2 -0
- package/dist/esm/tokenize/gateway-utils.js +27 -0
- package/dist/esm/tokenize/index.d.ts +3 -2
- package/dist/esm/tokenize/index.js +1 -0
- package/dist/esm/tokenize/spreedly-secure.js +6 -2
- package/dist/esm/tokenize/styles.d.ts +1 -1
- package/dist/esm/tokenize/styles.js +20 -1
- package/dist/esm/tokenize/tokenizer-constants.d.ts +1 -0
- package/dist/esm/tokenize/tokenizer-constants.js +1 -0
- package/dist/esm/tokenize/tokenizer-utils.d.ts +4 -1
- package/dist/esm/tokenize/tokenizer-utils.js +77 -4
- package/dist/esm/tokenize/types.d.ts +33 -8
- package/dist/esm/typeAdapters.js +6 -4
- package/dist/esm/types.d.ts +4 -10
- package/dist/idonate-client.js +18 -8
- package/dist/recaptcha.d.ts +1 -0
- package/dist/recaptcha.js +27 -2
- package/dist/shared.js +9 -1
- package/dist/tokenize/CardConnectTokenizer.d.ts +8 -1
- package/dist/tokenize/CardConnectTokenizer.js +351 -105
- package/dist/tokenize/PayPalTokenizer.d.ts +6 -0
- package/dist/tokenize/PayPalTokenizer.js +66 -16
- package/dist/tokenize/SpreedlyTokenizer.d.ts +17 -1
- package/dist/tokenize/SpreedlyTokenizer.js +267 -135
- package/dist/tokenize/Tokenizer.d.ts +6 -2
- package/dist/tokenize/Tokenizer.js +24 -8
- package/dist/tokenize/gateway-utils.d.ts +2 -0
- package/dist/tokenize/gateway-utils.js +30 -0
- package/dist/tokenize/index.d.ts +3 -2
- package/dist/tokenize/index.js +3 -1
- package/dist/tokenize/spreedly-secure.js +6 -2
- package/dist/tokenize/styles.d.ts +1 -1
- package/dist/tokenize/styles.js +20 -1
- package/dist/tokenize/tokenizer-constants.d.ts +1 -0
- package/dist/tokenize/tokenizer-constants.js +2 -1
- package/dist/tokenize/tokenizer-utils.d.ts +4 -1
- package/dist/tokenize/tokenizer-utils.js +80 -4
- package/dist/tokenize/types.d.ts +33 -8
- package/dist/typeAdapters.js +6 -4
- package/dist/types.d.ts +4 -10
- package/package.json +33 -2
- package/umd/idonate-sdk.js +1 -1
|
@@ -31,12 +31,17 @@ 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
42
|
private containerEl?;
|
|
39
43
|
private paypalButtonContainer?;
|
|
44
|
+
private buttonsInstance?;
|
|
40
45
|
private cachedToken?;
|
|
41
46
|
private currency;
|
|
42
47
|
private amount?;
|
|
@@ -49,6 +54,7 @@ export declare class PayPalTokenizer extends Tokenizer {
|
|
|
49
54
|
private clientConfig;
|
|
50
55
|
private paymentTransactionId?;
|
|
51
56
|
private paymentMethodId?;
|
|
57
|
+
private onCreateOrder?;
|
|
52
58
|
private constructor();
|
|
53
59
|
static create(gateway: PaymentGateway, container: TokenizerContainer, config: {
|
|
54
60
|
organizationId: string;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.PayPalTokenizer = void 0;
|
|
13
13
|
const Tokenizer_1 = require("./Tokenizer");
|
|
14
14
|
const types_1 = require("./types");
|
|
15
|
+
const constants_1 = require("../constants");
|
|
15
16
|
const PAYPAL_SDK_URL = 'https://www.paypal.com/sdk/js';
|
|
16
17
|
const PAYPAL_SCRIPT_ID = 'paypal-sdk-script';
|
|
17
18
|
const INIT_TIMEOUT = 10000;
|
|
@@ -22,7 +23,7 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
22
23
|
this.gateway = gateway;
|
|
23
24
|
this.containerId = containerId;
|
|
24
25
|
this.configContext = configContext;
|
|
25
|
-
this.mode = '
|
|
26
|
+
this.mode = 'paypal';
|
|
26
27
|
const gatewayConfig = gateway.config;
|
|
27
28
|
if (!(gatewayConfig === null || gatewayConfig === void 0 ? void 0 : gatewayConfig.client_id)) {
|
|
28
29
|
throw new Error('PayPal gateway configuration missing client_id');
|
|
@@ -33,6 +34,7 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
33
34
|
this.amount = config.amount;
|
|
34
35
|
this.enableVenmo = (_b = config.enableVenmo) !== null && _b !== void 0 ? _b : true;
|
|
35
36
|
this.locale = config.locale || 'en_US';
|
|
37
|
+
this.onCreateOrder = config.onCreateOrder;
|
|
36
38
|
this.organizationId = configContext.organizationId;
|
|
37
39
|
this.embedId = configContext.embedId;
|
|
38
40
|
this.clientConfig = configContext.clientConfig;
|
|
@@ -68,7 +70,7 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
68
70
|
})
|
|
69
71
|
.then(() => {
|
|
70
72
|
this.emit('ready');
|
|
71
|
-
this.emit('validation', { isValid: true });
|
|
73
|
+
this.emit('validation', { isValid: true, hasToken: false });
|
|
72
74
|
resolve();
|
|
73
75
|
})
|
|
74
76
|
.catch((error) => {
|
|
@@ -81,11 +83,20 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
81
83
|
}
|
|
82
84
|
loadPayPalSDK() {
|
|
83
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
const configKey = `${this.clientId}|${this.currency}`;
|
|
87
|
+
const existingScript = document.getElementById(PAYPAL_SCRIPT_ID);
|
|
88
|
+
if (existingScript) {
|
|
89
|
+
const loadedConfig = existingScript.getAttribute('data-config-key');
|
|
90
|
+
if (loadedConfig && loadedConfig !== configKey) {
|
|
91
|
+
existingScript.remove();
|
|
92
|
+
delete window.paypal;
|
|
93
|
+
}
|
|
94
|
+
else if (window.paypal) {
|
|
95
|
+
return Promise.resolve();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return this.waitForPayPalGlobal();
|
|
99
|
+
}
|
|
89
100
|
}
|
|
90
101
|
const params = new URLSearchParams({
|
|
91
102
|
'client-id': this.clientId,
|
|
@@ -104,6 +115,7 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
104
115
|
script.id = PAYPAL_SCRIPT_ID;
|
|
105
116
|
script.src = `${PAYPAL_SDK_URL}?${params.toString()}`;
|
|
106
117
|
script.async = true;
|
|
118
|
+
script.setAttribute('data-config-key', configKey);
|
|
107
119
|
return new Promise((resolve, reject) => {
|
|
108
120
|
script.onload = () => {
|
|
109
121
|
this.waitForPayPalGlobal().then(resolve).catch(reject);
|
|
@@ -147,7 +159,7 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
147
159
|
if (!window.paypal || !this.paypalButtonContainer) {
|
|
148
160
|
return;
|
|
149
161
|
}
|
|
150
|
-
|
|
162
|
+
this.buttonsInstance = window.paypal.Buttons({
|
|
151
163
|
createOrder: () => this.createOrder(),
|
|
152
164
|
onApprove: (data) => this.handleApprove(data),
|
|
153
165
|
onCancel: (data) => this.handleCancel(data),
|
|
@@ -158,23 +170,48 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
158
170
|
height: 40,
|
|
159
171
|
},
|
|
160
172
|
});
|
|
161
|
-
yield
|
|
173
|
+
yield this.buttonsInstance.render(this.paypalButtonContainer);
|
|
162
174
|
});
|
|
163
175
|
}
|
|
164
176
|
createOrder() {
|
|
165
177
|
const endpoint = `${this.clientConfig.embedApiBaseUrl}/payment/paypal/create-order`;
|
|
178
|
+
this.paymentTransactionId = undefined;
|
|
179
|
+
this.paymentMethodId = undefined;
|
|
180
|
+
let orderAmount;
|
|
181
|
+
let orderCurrency = this.currency;
|
|
182
|
+
if (this.onCreateOrder) {
|
|
183
|
+
try {
|
|
184
|
+
const orderData = this.onCreateOrder();
|
|
185
|
+
orderAmount = orderData.amount;
|
|
186
|
+
orderCurrency = orderData.currency || this.currency;
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
const error = err instanceof Error
|
|
190
|
+
? err
|
|
191
|
+
: new Error('onCreateOrder callback failed');
|
|
192
|
+
this.handleError(error, 'Order creation failed');
|
|
193
|
+
return Promise.reject(error);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
orderAmount = this.amount;
|
|
198
|
+
}
|
|
199
|
+
if (orderAmount === undefined || isNaN(orderAmount) || orderAmount <= 0) {
|
|
200
|
+
const error = new Error('Amount is required to create PayPal order');
|
|
201
|
+
this.handleError(error, 'Order creation failed');
|
|
202
|
+
return Promise.reject(error);
|
|
203
|
+
}
|
|
166
204
|
const requestBody = {
|
|
167
205
|
payment_gateway_id: this.gateway.id,
|
|
168
|
-
|
|
206
|
+
organization_id: this.organizationId,
|
|
207
|
+
embed_id: this.embedId,
|
|
208
|
+
currency: orderCurrency,
|
|
209
|
+
amount: orderAmount,
|
|
169
210
|
};
|
|
170
|
-
if (this.amount !== undefined) {
|
|
171
|
-
requestBody.amount = this.amount;
|
|
172
|
-
}
|
|
173
211
|
return fetch(endpoint, {
|
|
174
212
|
method: 'POST',
|
|
175
|
-
headers:
|
|
176
|
-
|
|
177
|
-
},
|
|
213
|
+
headers: constants_1.CLIENT_HEADERS,
|
|
214
|
+
credentials: 'include',
|
|
178
215
|
body: JSON.stringify(requestBody),
|
|
179
216
|
})
|
|
180
217
|
.then((response) => {
|
|
@@ -201,6 +238,7 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
201
238
|
const token = {
|
|
202
239
|
token: data.orderID,
|
|
203
240
|
lastFour: data.orderID.slice(-4),
|
|
241
|
+
paymentMethodType: 'paypal',
|
|
204
242
|
provider: 'paypal_checkout',
|
|
205
243
|
paymentMethodId: this.paymentMethodId,
|
|
206
244
|
paymentTransactionId: this.paymentTransactionId,
|
|
@@ -230,6 +268,9 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
230
268
|
}
|
|
231
269
|
validate() {
|
|
232
270
|
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
if (!this.isReady) {
|
|
272
|
+
throw new Error('Tokenizer not initialized');
|
|
273
|
+
}
|
|
233
274
|
return {
|
|
234
275
|
isValid: true,
|
|
235
276
|
errors: [],
|
|
@@ -243,6 +284,15 @@ class PayPalTokenizer extends Tokenizer_1.Tokenizer {
|
|
|
243
284
|
focus(field) {
|
|
244
285
|
}
|
|
245
286
|
destroy() {
|
|
287
|
+
this.markDestroyed();
|
|
288
|
+
if (this.buttonsInstance) {
|
|
289
|
+
try {
|
|
290
|
+
this.buttonsInstance.close();
|
|
291
|
+
}
|
|
292
|
+
catch (_a) {
|
|
293
|
+
}
|
|
294
|
+
this.buttonsInstance = undefined;
|
|
295
|
+
}
|
|
246
296
|
if (this.containerEl) {
|
|
247
297
|
this.containerEl.innerHTML = '';
|
|
248
298
|
}
|
|
@@ -6,6 +6,7 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
6
6
|
private environmentKey;
|
|
7
7
|
private containerId;
|
|
8
8
|
private layout;
|
|
9
|
+
private customPlaceholders?;
|
|
9
10
|
private spreedly;
|
|
10
11
|
private currentValidationState;
|
|
11
12
|
private mergedStyles;
|
|
@@ -24,6 +25,15 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
24
25
|
private institutionNumberEl?;
|
|
25
26
|
private transitNumberEl?;
|
|
26
27
|
private enableTestMode;
|
|
28
|
+
private resizeObserver?;
|
|
29
|
+
private effectiveLayout;
|
|
30
|
+
private cardNumberDiv?;
|
|
31
|
+
private cvvDiv?;
|
|
32
|
+
private responsiveBreakpoint;
|
|
33
|
+
private tokenizationPromise?;
|
|
34
|
+
private tokenizationResolve?;
|
|
35
|
+
private tokenizationReject?;
|
|
36
|
+
private tokenizationTimeout?;
|
|
27
37
|
private constructor();
|
|
28
38
|
static create(gateway: PaymentGateway, container: TokenizerContainer, config: {
|
|
29
39
|
organizationId: string;
|
|
@@ -33,6 +43,7 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
33
43
|
private init;
|
|
34
44
|
tokenize(paymentData: PaymentData): Promise<PaymentToken>;
|
|
35
45
|
private tokenizeCardInternal;
|
|
46
|
+
private executeCardTokenization;
|
|
36
47
|
private createCanadianBankAccountFields;
|
|
37
48
|
private tokenizeBankAccountInternal;
|
|
38
49
|
validate(): Promise<ValidationResult>;
|
|
@@ -42,6 +53,10 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
42
53
|
private stylesToCssString;
|
|
43
54
|
clear(): void;
|
|
44
55
|
focus(field: 'cardNumber' | 'cvv' | 'expiry' | 'routingNumber' | 'accountNumber'): void;
|
|
56
|
+
private determineLayout;
|
|
57
|
+
private setupResizeObserver;
|
|
58
|
+
private applyLayoutStyles;
|
|
59
|
+
private clearTokenizationState;
|
|
45
60
|
destroy(): void;
|
|
46
61
|
hasToken(): boolean;
|
|
47
62
|
getToken(): PaymentToken | null;
|
|
@@ -49,6 +64,7 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
49
64
|
private updateOverallValidation;
|
|
50
65
|
private handleFieldEvent;
|
|
51
66
|
private createInternalElements;
|
|
67
|
+
private appendField;
|
|
52
68
|
private createCreditCardFields;
|
|
53
69
|
private createBankAccountFields;
|
|
54
70
|
private createUSBankAccountFields;
|
|
@@ -67,7 +83,7 @@ export declare class SpreedlyTokenizer extends Tokenizer {
|
|
|
67
83
|
});
|
|
68
84
|
address: Partial<Address>;
|
|
69
85
|
account: Partial<ACHAccount> & Pick<ACHAccount, 'accountNumber' | 'routingNumber'>;
|
|
70
|
-
}, config: ConfigHandler): Promise<string>;
|
|
86
|
+
}, config: ConfigHandler, environmentKeyOverride?: string): Promise<string>;
|
|
71
87
|
static tokenizeCreditCard(data: {
|
|
72
88
|
contact: Partial<Contact> & ({
|
|
73
89
|
firstName: string;
|