@idonatedev/idonate-sdk 1.1.0-dev8 → 1.2.0-dev0

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 (72) hide show
  1. package/README.md +308 -7
  2. package/dist/constants.d.ts +1 -1
  3. package/dist/constants.js +2 -6
  4. package/dist/esm/apple-pay.d.ts +12 -0
  5. package/dist/esm/apple-pay.js +74 -0
  6. package/dist/esm/cloudflare-challenge-handler.d.ts +5 -0
  7. package/dist/esm/cloudflare-challenge-handler.js +77 -0
  8. package/dist/esm/config-handler.d.ts +22 -0
  9. package/dist/esm/config-handler.js +47 -0
  10. package/dist/esm/constants.d.ts +18 -0
  11. package/dist/esm/constants.js +81 -0
  12. package/dist/esm/google-pay.d.ts +18 -0
  13. package/dist/esm/google-pay.js +140 -0
  14. package/dist/esm/idonate-client.d.ts +32 -0
  15. package/dist/esm/idonate-client.js +294 -0
  16. package/dist/esm/index.d.ts +11 -0
  17. package/dist/esm/index.js +11 -0
  18. package/dist/esm/recaptcha.d.ts +12 -0
  19. package/dist/esm/recaptcha.js +89 -0
  20. package/dist/esm/shared.d.ts +4 -0
  21. package/dist/esm/shared.js +21 -0
  22. package/dist/esm/test-utils.d.ts +81 -0
  23. package/dist/esm/test-utils.js +94 -0
  24. package/dist/esm/tokenize/CardConnectTokenizer.d.ts +51 -0
  25. package/dist/esm/tokenize/CardConnectTokenizer.js +712 -0
  26. package/dist/esm/tokenize/PayPalTokenizer.d.ts +77 -0
  27. package/dist/esm/tokenize/PayPalTokenizer.js +268 -0
  28. package/dist/esm/tokenize/SpreedlyTokenizer.d.ts +92 -0
  29. package/dist/esm/tokenize/SpreedlyTokenizer.js +1140 -0
  30. package/dist/esm/tokenize/Tokenizer.d.ts +37 -0
  31. package/dist/esm/tokenize/Tokenizer.js +150 -0
  32. package/dist/esm/tokenize/iats.d.ts +3 -0
  33. package/dist/esm/tokenize/iats.js +48 -0
  34. package/dist/esm/tokenize/index.d.ts +7 -0
  35. package/dist/esm/tokenize/index.js +7 -0
  36. package/dist/esm/tokenize/spreedly-secure.d.ts +8 -0
  37. package/dist/esm/tokenize/spreedly-secure.js +40 -0
  38. package/dist/esm/tokenize/styles.d.ts +4 -0
  39. package/dist/esm/tokenize/styles.js +46 -0
  40. package/dist/esm/tokenize/tokenizer-constants.d.ts +62 -0
  41. package/dist/esm/tokenize/tokenizer-constants.js +62 -0
  42. package/dist/esm/tokenize/tokenizer-utils.d.ts +19 -0
  43. package/dist/esm/tokenize/tokenizer-utils.js +139 -0
  44. package/dist/esm/tokenize/types.d.ts +146 -0
  45. package/dist/esm/tokenize/types.js +26 -0
  46. package/dist/esm/typeAdapters.d.ts +29 -0
  47. package/dist/esm/typeAdapters.js +189 -0
  48. package/dist/esm/types.d.ts +378 -0
  49. package/dist/esm/types.js +14 -0
  50. package/dist/esm/util.d.ts +17 -0
  51. package/dist/esm/util.js +113 -0
  52. package/dist/idonate-client.d.ts +6 -2
  53. package/dist/idonate-client.js +40 -2
  54. package/dist/shared.d.ts +2 -1
  55. package/dist/shared.js +9 -0
  56. package/dist/tokenize/CardConnectTokenizer.d.ts +1 -0
  57. package/dist/tokenize/CardConnectTokenizer.js +127 -104
  58. package/dist/tokenize/PayPalTokenizer.d.ts +77 -0
  59. package/dist/tokenize/PayPalTokenizer.js +272 -0
  60. package/dist/tokenize/SpreedlyTokenizer.d.ts +1 -0
  61. package/dist/tokenize/SpreedlyTokenizer.js +276 -135
  62. package/dist/tokenize/Tokenizer.js +6 -2
  63. package/dist/tokenize/index.d.ts +1 -0
  64. package/dist/tokenize/index.js +3 -1
  65. package/dist/tokenize/styles.d.ts +1 -0
  66. package/dist/tokenize/styles.js +9 -0
  67. package/dist/tokenize/tokenizer-utils.js +1 -1
  68. package/dist/tokenize/types.d.ts +6 -7
  69. package/dist/typeAdapters.js +3 -2
  70. package/dist/types.d.ts +16 -5
  71. package/package.json +14 -3
  72. package/umd/idonate-sdk.js +1 -1
@@ -0,0 +1,89 @@
1
+ function resolveLib() {
2
+ const startWait = new Date();
3
+ return new Promise((resolve, reject) => {
4
+ function poll() {
5
+ if (window.grecaptcha !== undefined &&
6
+ window.grecaptcha.render !== undefined) {
7
+ resolve(window.grecaptcha);
8
+ }
9
+ else {
10
+ const elapsedMs = new Date().valueOf() - startWait.valueOf();
11
+ if (elapsedMs > 15000) {
12
+ reject(new Error('grecaptcha not loaded after 15 seconds'));
13
+ }
14
+ else {
15
+ setTimeout(poll, 250);
16
+ }
17
+ }
18
+ }
19
+ poll();
20
+ });
21
+ }
22
+ export function injectScript(callback) {
23
+ if (window.grecaptcha !== undefined) {
24
+ throw new Error('grecaptcha is already defined');
25
+ }
26
+ const script = document.createElement('script');
27
+ script.src = 'https://www.google.com/recaptcha/api.js?render=explicit';
28
+ script.async = true;
29
+ script.defer = true;
30
+ script.onload = callback || null;
31
+ if (document.readyState === 'interactive' ||
32
+ document.readyState === 'complete') {
33
+ document.body.appendChild(script);
34
+ }
35
+ else {
36
+ window.addEventListener('DOMContentLoaded', () => {
37
+ document.body.appendChild(script);
38
+ });
39
+ }
40
+ }
41
+ export class RecaptchaElement {
42
+ constructor(container, params) {
43
+ this.container = container;
44
+ this.params = params;
45
+ this.executeResolveQueue = [];
46
+ }
47
+ render() {
48
+ if (this.widgetId !== undefined) {
49
+ console.warn('rendering an already-rendered widget');
50
+ }
51
+ return resolveLib().then((lib) => {
52
+ this.widgetId = lib.render(this.container, Object.assign(Object.assign({}, this.params), { callback: (token) => {
53
+ var _a;
54
+ this.resolvedToken = token;
55
+ (_a = this.executeResolveQueue.pop()) === null || _a === void 0 ? void 0 : _a(token);
56
+ }, 'expired-callback': () => {
57
+ this.resolvedToken = undefined;
58
+ } }));
59
+ });
60
+ }
61
+ resolveToken() {
62
+ return new Promise((resolve, reject) => {
63
+ resolveLib()
64
+ .then((lib) => {
65
+ if (this.params.size !== 'invisible') {
66
+ const response = lib.getResponse();
67
+ return response
68
+ ? resolve(response)
69
+ : reject(new Error('checkbox recaptcha is not checked'));
70
+ }
71
+ this.executeResolveQueue.push(resolve);
72
+ if (this.resolvedToken !== undefined) {
73
+ this.resolvedToken = undefined;
74
+ lib.reset(this.widgetId);
75
+ }
76
+ lib.execute(this.widgetId);
77
+ })
78
+ .catch((e) => {
79
+ reject(e);
80
+ });
81
+ });
82
+ }
83
+ }
84
+ export function wrapElement(container, sitekey, extraParams) {
85
+ const params = Object.assign(Object.assign({}, (extraParams || {})), { sitekey });
86
+ const captcha = new RecaptchaElement(container, params);
87
+ captcha.render();
88
+ return captcha;
89
+ }
@@ -0,0 +1,4 @@
1
+ import { CreatePaymentMethodRequest, CreatePaymentMethodResult, EmbedConfig } from './types';
2
+ import ConfigHandler from './config-handler';
3
+ export declare function createPaymentMethod(paymentMethod: CreatePaymentMethodRequest, config: ConfigHandler): Promise<CreatePaymentMethodResult>;
4
+ export declare function fetchEmbedConfig(embedId: string, config: ConfigHandler): Promise<EmbedConfig>;
@@ -0,0 +1,21 @@
1
+ import { buildCreatePaymentMethodPayload, buildCreatePaymentMethodResult, } from './typeAdapters';
2
+ import { CLIENT_HEADERS } from './constants';
3
+ import { parseResponse } from './util';
4
+ export function createPaymentMethod(paymentMethod, config) {
5
+ const payload = buildCreatePaymentMethodPayload(paymentMethod);
6
+ return fetch(`${config.embedApiBaseUrl}/payment/payment-methods`, {
7
+ method: 'POST',
8
+ headers: CLIENT_HEADERS,
9
+ body: JSON.stringify(payload),
10
+ })
11
+ .then((response) => parseResponse(response, { throwErrors: true }))
12
+ .then((response) => buildCreatePaymentMethodResult(response));
13
+ }
14
+ export function fetchEmbedConfig(embedId, config) {
15
+ return fetch(`${config.embedApiBaseUrl}/config/${embedId}`, {
16
+ method: 'GET',
17
+ headers: CLIENT_HEADERS,
18
+ })
19
+ .then((response) => parseResponse(response, { throwErrors: true }))
20
+ .then((response) => response._raw_response.result);
21
+ }
@@ -0,0 +1,81 @@
1
+ export declare const createMockFetch: (response: any, options?: {
2
+ ok?: boolean;
3
+ status?: number;
4
+ }) => jest.Mock<any, any, any>;
5
+ export declare const createMockFetchError: (message: string) => jest.Mock<any, any, any>;
6
+ export declare const createMockFetchWithImplementation: (implementation: (url: string, options?: any) => Promise<any>) => jest.Mock<any, any, any>;
7
+ export declare const setupFetchMock: () => jest.Mock<any, any, any>;
8
+ export declare const setupDocumentMock: () => {
9
+ mockScript: {
10
+ src: string;
11
+ async: boolean;
12
+ defer: boolean;
13
+ };
14
+ mockAppendChild: jest.Mock<any, any, any>;
15
+ mockCreateElement: jest.Mock<any, [], any>;
16
+ };
17
+ export declare const setupApplePayEnvironment: (options?: {
18
+ canMakePayments?: boolean;
19
+ supportsVersion?: boolean;
20
+ }) => {
21
+ mockSession: {
22
+ begin: jest.Mock<any, any, any>;
23
+ abort: jest.Mock<any, any, any>;
24
+ completeMerchantValidation: jest.Mock<any, any, any>;
25
+ completePayment: jest.Mock<any, any, any>;
26
+ };
27
+ ApplePaySessionMock: any;
28
+ };
29
+ export declare const setupGooglePayEnvironment: (options?: {
30
+ autoLoad?: boolean;
31
+ }) => {
32
+ mockPaymentsClient: {
33
+ isReadyToPay: jest.Mock<any, any, any>;
34
+ loadPaymentData: jest.Mock<any, any, any>;
35
+ };
36
+ googlePayMock: {
37
+ payments: {
38
+ api: {
39
+ PaymentsClient: jest.Mock<{
40
+ isReadyToPay: jest.Mock<any, any, any>;
41
+ loadPaymentData: jest.Mock<any, any, any>;
42
+ }, [], any>;
43
+ };
44
+ };
45
+ };
46
+ };
47
+ export declare const setupRecaptchaEnvironment: () => {
48
+ render: jest.Mock<any, any, any>;
49
+ reset: jest.Mock<any, any, any>;
50
+ execute: jest.Mock<any, any, any>;
51
+ getResponse: jest.Mock<any, any, any>;
52
+ };
53
+ export declare const createTestContact: (overrides?: {}) => {
54
+ salutation: string;
55
+ firstName: string;
56
+ lastName: string;
57
+ company: string;
58
+ email: string;
59
+ primaryPhone: string;
60
+ };
61
+ export declare const createTestAddress: (overrides?: {}) => {
62
+ address1: string;
63
+ address2: string;
64
+ city: string;
65
+ state: string;
66
+ zip: string;
67
+ country: string;
68
+ };
69
+ export declare const createTestCreditCard: (overrides?: {}) => {
70
+ cardNumber: string;
71
+ expirationMonth: string;
72
+ expirationYear: string;
73
+ verificationValue: string;
74
+ };
75
+ export declare const createTestBankAccount: (overrides?: {}) => {
76
+ accountNumber: string;
77
+ routingNumber: string;
78
+ accountType: "checking";
79
+ accountHolderType: "personal";
80
+ };
81
+ export declare const cleanupWindowMocks: () => void;
@@ -0,0 +1,94 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export const createMockFetch = (response, options = {}) => {
11
+ return jest.fn().mockResolvedValue({
12
+ ok: options.ok !== false,
13
+ status: options.status || 200,
14
+ json: () => __awaiter(void 0, void 0, void 0, function* () { return response; }),
15
+ text: () => __awaiter(void 0, void 0, void 0, function* () { return JSON.stringify(response); }),
16
+ });
17
+ };
18
+ export const createMockFetchError = (message) => {
19
+ return jest.fn().mockRejectedValue(new Error(message));
20
+ };
21
+ export const createMockFetchWithImplementation = (implementation) => {
22
+ return jest.fn().mockImplementation(implementation);
23
+ };
24
+ export const setupFetchMock = () => {
25
+ const mockFetch = jest.fn();
26
+ global.fetch = mockFetch;
27
+ return mockFetch;
28
+ };
29
+ export const setupDocumentMock = () => {
30
+ const mockScript = {
31
+ src: '',
32
+ async: false,
33
+ defer: false,
34
+ };
35
+ const mockAppendChild = jest.fn();
36
+ const mockCreateElement = jest.fn(() => mockScript);
37
+ Object.defineProperty(document, 'createElement', {
38
+ value: mockCreateElement,
39
+ writable: true,
40
+ });
41
+ Object.defineProperty(document.body, 'appendChild', {
42
+ value: mockAppendChild,
43
+ writable: true,
44
+ });
45
+ return { mockScript, mockAppendChild, mockCreateElement };
46
+ };
47
+ export const setupApplePayEnvironment = (options = {}) => {
48
+ const mockSession = {
49
+ begin: jest.fn(),
50
+ abort: jest.fn(),
51
+ completeMerchantValidation: jest.fn(),
52
+ completePayment: jest.fn(),
53
+ };
54
+ const ApplePaySessionMock = jest.fn(() => mockSession);
55
+ ApplePaySessionMock.canMakePayments = jest.fn(() => options.canMakePayments !== false);
56
+ ApplePaySessionMock.supportsVersion = jest.fn(() => options.supportsVersion !== false);
57
+ window.ApplePaySession = ApplePaySessionMock;
58
+ return { mockSession, ApplePaySessionMock };
59
+ };
60
+ export const setupGooglePayEnvironment = (options = {}) => {
61
+ const mockPaymentsClient = {
62
+ isReadyToPay: jest.fn(),
63
+ loadPaymentData: jest.fn(),
64
+ };
65
+ const googlePayMock = {
66
+ payments: {
67
+ api: {
68
+ PaymentsClient: jest.fn(() => mockPaymentsClient),
69
+ },
70
+ },
71
+ };
72
+ if (options.autoLoad) {
73
+ window.google = googlePayMock;
74
+ }
75
+ return { mockPaymentsClient, googlePayMock };
76
+ };
77
+ export const setupRecaptchaEnvironment = () => {
78
+ const mockGrecaptcha = {
79
+ render: jest.fn().mockReturnValue(123),
80
+ reset: jest.fn(),
81
+ execute: jest.fn(),
82
+ getResponse: jest.fn().mockReturnValue(null),
83
+ };
84
+ return mockGrecaptcha;
85
+ };
86
+ export const createTestContact = (overrides = {}) => (Object.assign({ salutation: 'Mr', firstName: 'John', lastName: 'Doe', company: 'Test Corp', email: 'test@example.com', primaryPhone: '555-1234' }, overrides));
87
+ export const createTestAddress = (overrides = {}) => (Object.assign({ address1: '123 Test St', address2: 'Suite 100', city: 'Test City', state: 'NY', zip: '10001', country: 'US' }, overrides));
88
+ export const createTestCreditCard = (overrides = {}) => (Object.assign({ cardNumber: '4111111111111111', expirationMonth: '12', expirationYear: '2025', verificationValue: '123' }, overrides));
89
+ export const createTestBankAccount = (overrides = {}) => (Object.assign({ accountNumber: '1234567890', routingNumber: '021000021', accountType: 'checking', accountHolderType: 'personal' }, overrides));
90
+ export const cleanupWindowMocks = () => {
91
+ delete window.ApplePaySession;
92
+ delete window.google;
93
+ delete window.grecaptcha;
94
+ };
@@ -0,0 +1,51 @@
1
+ import { Tokenizer } from './Tokenizer';
2
+ import { PaymentData, PaymentToken, ValidationResult, PaymentGateway, TokenizerContainer } from './types';
3
+ import { TokenizeCardConnectBankAccountResult } from '../types';
4
+ import ConfigHandler from '../config-handler';
5
+ export declare class CardConnectTokenizer extends Tokenizer {
6
+ private iframeUrl;
7
+ private containerId;
8
+ private layout;
9
+ private iframe;
10
+ private messageHandler?;
11
+ private expectedOrigin;
12
+ private isReady;
13
+ private currentValidationState;
14
+ private containerEl?;
15
+ private routingNumberEl?;
16
+ private accountNumberEl?;
17
+ private accountTypeEl?;
18
+ private enableTestMode;
19
+ private cachedTokenResult?;
20
+ private tokenizationPromise?;
21
+ private tokenizationResolve?;
22
+ private tokenizationReject?;
23
+ private constructor();
24
+ static create(gateway: PaymentGateway, container: TokenizerContainer, config: {
25
+ organizationId: string;
26
+ embedId: string;
27
+ clientConfig: ConfigHandler;
28
+ }): Promise<CardConnectTokenizer>;
29
+ private createInternalElements;
30
+ private createCreditCardFields;
31
+ private createBankAccountFields;
32
+ private init;
33
+ tokenize(paymentData: PaymentData): Promise<PaymentToken>;
34
+ private tokenizeCardInternal;
35
+ private tokenizeBankAccountInternal;
36
+ validate(): Promise<ValidationResult>;
37
+ private validateCardInternal;
38
+ private validateBankAccountInternal;
39
+ clear(): void;
40
+ focus(field: 'cardNumber' | 'cvv' | 'expiry' | 'routingNumber' | 'accountNumber'): void;
41
+ destroy(): void;
42
+ hasToken(): boolean;
43
+ getToken(): PaymentToken | null;
44
+ get tokenizationMode(): 'auto' | 'manual';
45
+ private handleMessage;
46
+ private handleValidationMessage;
47
+ private static generateIframeUrl;
48
+ private static createIframe;
49
+ private static generateCardConnectCss;
50
+ static tokenizeBankAccount(routingNumber: string, accountNumber: string, config: ConfigHandler): Promise<TokenizeCardConnectBankAccountResult>;
51
+ }