@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.
Files changed (56) hide show
  1. package/dist/constants.js +11 -2
  2. package/dist/esm/constants.js +11 -2
  3. package/dist/esm/idonate-client.js +18 -8
  4. package/dist/esm/recaptcha.d.ts +1 -0
  5. package/dist/esm/recaptcha.js +26 -2
  6. package/dist/esm/shared.js +9 -1
  7. package/dist/esm/tokenize/CardConnectTokenizer.d.ts +8 -1
  8. package/dist/esm/tokenize/CardConnectTokenizer.js +353 -104
  9. package/dist/esm/tokenize/PayPalTokenizer.d.ts +6 -0
  10. package/dist/esm/tokenize/PayPalTokenizer.js +66 -16
  11. package/dist/esm/tokenize/SpreedlyTokenizer.d.ts +17 -1
  12. package/dist/esm/tokenize/SpreedlyTokenizer.js +270 -138
  13. package/dist/esm/tokenize/Tokenizer.d.ts +6 -2
  14. package/dist/esm/tokenize/Tokenizer.js +24 -8
  15. package/dist/esm/tokenize/gateway-utils.d.ts +2 -0
  16. package/dist/esm/tokenize/gateway-utils.js +27 -0
  17. package/dist/esm/tokenize/index.d.ts +3 -2
  18. package/dist/esm/tokenize/index.js +1 -0
  19. package/dist/esm/tokenize/spreedly-secure.js +6 -2
  20. package/dist/esm/tokenize/styles.d.ts +1 -1
  21. package/dist/esm/tokenize/styles.js +20 -1
  22. package/dist/esm/tokenize/tokenizer-constants.d.ts +1 -0
  23. package/dist/esm/tokenize/tokenizer-constants.js +1 -0
  24. package/dist/esm/tokenize/tokenizer-utils.d.ts +4 -1
  25. package/dist/esm/tokenize/tokenizer-utils.js +77 -4
  26. package/dist/esm/tokenize/types.d.ts +33 -8
  27. package/dist/esm/typeAdapters.js +6 -4
  28. package/dist/esm/types.d.ts +4 -10
  29. package/dist/idonate-client.js +18 -8
  30. package/dist/recaptcha.d.ts +1 -0
  31. package/dist/recaptcha.js +27 -2
  32. package/dist/shared.js +9 -1
  33. package/dist/tokenize/CardConnectTokenizer.d.ts +8 -1
  34. package/dist/tokenize/CardConnectTokenizer.js +351 -105
  35. package/dist/tokenize/PayPalTokenizer.d.ts +6 -0
  36. package/dist/tokenize/PayPalTokenizer.js +66 -16
  37. package/dist/tokenize/SpreedlyTokenizer.d.ts +17 -1
  38. package/dist/tokenize/SpreedlyTokenizer.js +267 -135
  39. package/dist/tokenize/Tokenizer.d.ts +6 -2
  40. package/dist/tokenize/Tokenizer.js +24 -8
  41. package/dist/tokenize/gateway-utils.d.ts +2 -0
  42. package/dist/tokenize/gateway-utils.js +30 -0
  43. package/dist/tokenize/index.d.ts +3 -2
  44. package/dist/tokenize/index.js +3 -1
  45. package/dist/tokenize/spreedly-secure.js +6 -2
  46. package/dist/tokenize/styles.d.ts +1 -1
  47. package/dist/tokenize/styles.js +20 -1
  48. package/dist/tokenize/tokenizer-constants.d.ts +1 -0
  49. package/dist/tokenize/tokenizer-constants.js +2 -1
  50. package/dist/tokenize/tokenizer-utils.d.ts +4 -1
  51. package/dist/tokenize/tokenizer-utils.js +80 -4
  52. package/dist/tokenize/types.d.ts +33 -8
  53. package/dist/typeAdapters.js +6 -4
  54. package/dist/types.d.ts +4 -10
  55. package/package.json +33 -2
  56. 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;
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { Tokenizer } from './Tokenizer';
11
11
  import { TokenizationError, } from './types';
12
+ import { CLIENT_HEADERS } from '../constants';
12
13
  const PAYPAL_SDK_URL = 'https://www.paypal.com/sdk/js';
13
14
  const PAYPAL_SCRIPT_ID = 'paypal-sdk-script';
14
15
  const INIT_TIMEOUT = 10000;
@@ -19,7 +20,7 @@ export class PayPalTokenizer extends Tokenizer {
19
20
  this.gateway = gateway;
20
21
  this.containerId = containerId;
21
22
  this.configContext = configContext;
22
- this.mode = 'credit_card';
23
+ this.mode = 'paypal';
23
24
  const gatewayConfig = gateway.config;
24
25
  if (!(gatewayConfig === null || gatewayConfig === void 0 ? void 0 : gatewayConfig.client_id)) {
25
26
  throw new Error('PayPal gateway configuration missing client_id');
@@ -30,6 +31,7 @@ export class PayPalTokenizer extends Tokenizer {
30
31
  this.amount = config.amount;
31
32
  this.enableVenmo = (_b = config.enableVenmo) !== null && _b !== void 0 ? _b : true;
32
33
  this.locale = config.locale || 'en_US';
34
+ this.onCreateOrder = config.onCreateOrder;
33
35
  this.organizationId = configContext.organizationId;
34
36
  this.embedId = configContext.embedId;
35
37
  this.clientConfig = configContext.clientConfig;
@@ -65,7 +67,7 @@ export class PayPalTokenizer extends Tokenizer {
65
67
  })
66
68
  .then(() => {
67
69
  this.emit('ready');
68
- this.emit('validation', { isValid: true });
70
+ this.emit('validation', { isValid: true, hasToken: false });
69
71
  resolve();
70
72
  })
71
73
  .catch((error) => {
@@ -78,11 +80,20 @@ export class PayPalTokenizer extends Tokenizer {
78
80
  }
79
81
  loadPayPalSDK() {
80
82
  return __awaiter(this, void 0, void 0, function* () {
81
- if (window.paypal) {
82
- return Promise.resolve();
83
- }
84
- if (document.getElementById(PAYPAL_SCRIPT_ID)) {
85
- return this.waitForPayPalGlobal();
83
+ const configKey = `${this.clientId}|${this.currency}`;
84
+ const existingScript = document.getElementById(PAYPAL_SCRIPT_ID);
85
+ if (existingScript) {
86
+ const loadedConfig = existingScript.getAttribute('data-config-key');
87
+ if (loadedConfig && loadedConfig !== configKey) {
88
+ existingScript.remove();
89
+ delete window.paypal;
90
+ }
91
+ else if (window.paypal) {
92
+ return Promise.resolve();
93
+ }
94
+ else {
95
+ return this.waitForPayPalGlobal();
96
+ }
86
97
  }
87
98
  const params = new URLSearchParams({
88
99
  'client-id': this.clientId,
@@ -101,6 +112,7 @@ export class PayPalTokenizer extends Tokenizer {
101
112
  script.id = PAYPAL_SCRIPT_ID;
102
113
  script.src = `${PAYPAL_SDK_URL}?${params.toString()}`;
103
114
  script.async = true;
115
+ script.setAttribute('data-config-key', configKey);
104
116
  return new Promise((resolve, reject) => {
105
117
  script.onload = () => {
106
118
  this.waitForPayPalGlobal().then(resolve).catch(reject);
@@ -144,7 +156,7 @@ export class PayPalTokenizer extends Tokenizer {
144
156
  if (!window.paypal || !this.paypalButtonContainer) {
145
157
  return;
146
158
  }
147
- const button = window.paypal.Buttons({
159
+ this.buttonsInstance = window.paypal.Buttons({
148
160
  createOrder: () => this.createOrder(),
149
161
  onApprove: (data) => this.handleApprove(data),
150
162
  onCancel: (data) => this.handleCancel(data),
@@ -155,23 +167,48 @@ export class PayPalTokenizer extends Tokenizer {
155
167
  height: 40,
156
168
  },
157
169
  });
158
- yield button.render(this.paypalButtonContainer);
170
+ yield this.buttonsInstance.render(this.paypalButtonContainer);
159
171
  });
160
172
  }
161
173
  createOrder() {
162
174
  const endpoint = `${this.clientConfig.embedApiBaseUrl}/payment/paypal/create-order`;
175
+ this.paymentTransactionId = undefined;
176
+ this.paymentMethodId = undefined;
177
+ let orderAmount;
178
+ let orderCurrency = this.currency;
179
+ if (this.onCreateOrder) {
180
+ try {
181
+ const orderData = this.onCreateOrder();
182
+ orderAmount = orderData.amount;
183
+ orderCurrency = orderData.currency || this.currency;
184
+ }
185
+ catch (err) {
186
+ const error = err instanceof Error
187
+ ? err
188
+ : new Error('onCreateOrder callback failed');
189
+ this.handleError(error, 'Order creation failed');
190
+ return Promise.reject(error);
191
+ }
192
+ }
193
+ else {
194
+ orderAmount = this.amount;
195
+ }
196
+ if (orderAmount === undefined || isNaN(orderAmount) || orderAmount <= 0) {
197
+ const error = new Error('Amount is required to create PayPal order');
198
+ this.handleError(error, 'Order creation failed');
199
+ return Promise.reject(error);
200
+ }
163
201
  const requestBody = {
164
202
  payment_gateway_id: this.gateway.id,
165
- currency: this.currency,
203
+ organization_id: this.organizationId,
204
+ embed_id: this.embedId,
205
+ currency: orderCurrency,
206
+ amount: orderAmount,
166
207
  };
167
- if (this.amount !== undefined) {
168
- requestBody.amount = this.amount;
169
- }
170
208
  return fetch(endpoint, {
171
209
  method: 'POST',
172
- headers: {
173
- 'Content-Type': 'application/json',
174
- },
210
+ headers: CLIENT_HEADERS,
211
+ credentials: 'include',
175
212
  body: JSON.stringify(requestBody),
176
213
  })
177
214
  .then((response) => {
@@ -198,6 +235,7 @@ export class PayPalTokenizer extends Tokenizer {
198
235
  const token = {
199
236
  token: data.orderID,
200
237
  lastFour: data.orderID.slice(-4),
238
+ paymentMethodType: 'paypal',
201
239
  provider: 'paypal_checkout',
202
240
  paymentMethodId: this.paymentMethodId,
203
241
  paymentTransactionId: this.paymentTransactionId,
@@ -227,6 +265,9 @@ export class PayPalTokenizer extends Tokenizer {
227
265
  }
228
266
  validate() {
229
267
  return __awaiter(this, void 0, void 0, function* () {
268
+ if (!this.isReady) {
269
+ throw new Error('Tokenizer not initialized');
270
+ }
230
271
  return {
231
272
  isValid: true,
232
273
  errors: [],
@@ -240,6 +281,15 @@ export class PayPalTokenizer extends Tokenizer {
240
281
  focus(field) {
241
282
  }
242
283
  destroy() {
284
+ this.markDestroyed();
285
+ if (this.buttonsInstance) {
286
+ try {
287
+ this.buttonsInstance.close();
288
+ }
289
+ catch (_a) {
290
+ }
291
+ this.buttonsInstance = undefined;
292
+ }
243
293
  if (this.containerEl) {
244
294
  this.containerEl.innerHTML = '';
245
295
  }
@@ -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;