@idonatedev/idonate-sdk 1.1.0-dev1 → 1.1.0-dev11

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.
@@ -26,6 +26,9 @@ class ConfigHandler {
26
26
  if (options.overrideApplePayUrl) {
27
27
  this.applePayUrl = options.overrideApplePayUrl;
28
28
  }
29
+ if (options.overrideCardConnectBaseUrl) {
30
+ this.cardConnectBaseUrl = options.overrideCardConnectBaseUrl;
31
+ }
29
32
  this.pcScriptBase = options.pcScriptBase || constants_1.FALLBACK_PC_SCRIPT_URL;
30
33
  this.pcScriptId = options.pcScriptId || constants_1.FALLBACK_PC_SCRIPT_ID;
31
34
  this.turnstileCdnUrl =
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "1.1.0";
1
+ export declare const SDK_VERSION: string;
2
2
  export declare const PRODUCTION_BASE_URL = "https://secure-api.idonate.com";
3
3
  export declare const SANDBOX_BASE_URL = "https://api.qa-idonate.com";
4
4
  export declare const PRODUCTION_CARD_CONNECT_BASE_URL = "https://boltgw.cardconnect.com:8443";
package/dist/constants.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.CLIENT_HEADERS = exports.CARD_CONNECT_DEFAULT_STYLE = exports.DEFAULT_APP_NAME = exports.DEFAULT_CF_TURNSTILE_CDN_EXPLICIT_URL = exports.FALLBACK_CF_TURNSTILE_SITE_KEY = exports.FALLBACK_PC_SCRIPT_ID = exports.FALLBACK_PC_SCRIPT_URL = exports.SANDBOX_APPLE_PAY_URL = exports.APPLE_PAY_URL = exports.SPREEDLY_TOKENIZER_URL = exports.SANDBOX_CARD_CONNECT_BASE_URL = exports.PRODUCTION_CARD_CONNECT_BASE_URL = exports.SANDBOX_BASE_URL = exports.PRODUCTION_BASE_URL = exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '1.1.0';
7
+ const package_json_1 = __importDefault(require("../package.json"));
8
+ exports.SDK_VERSION = package_json_1.default.version;
5
9
  exports.PRODUCTION_BASE_URL = 'https://secure-api.idonate.com';
6
10
  exports.SANDBOX_BASE_URL = 'https://api.qa-idonate.com';
7
11
  exports.PRODUCTION_CARD_CONNECT_BASE_URL = 'https://boltgw.cardconnect.com:8443';
@@ -79,6 +83,6 @@ input#cccvvfield {
79
83
  }
80
84
  `.replace(/\s+/gi, ' ');
81
85
  exports.CLIENT_HEADERS = {
82
- 'User-Agent': navigator.userAgent + ' idonate-sdk@1.0.16',
86
+ 'User-Agent': navigator.userAgent + ` idonate-sdk@${package_json_1.default.version}`,
83
87
  'Content-Type': 'application/json',
84
88
  };
@@ -1,4 +1,4 @@
1
- import { ClientOptions, CreatePaymentMethodRequest, CreatePaymentMethodResult, CreateDonationRequest, CreateDonationResult, TokenizeApplePayResult } from './types';
1
+ import { ClientOptions, Contact, Address, CreatePaymentMethodRequest, CreatePaymentMethodResult, CreateDonationRequest, CreateDonationResult, TokenizeApplePayResult } from './types';
2
2
  import ConfigHandler from './config-handler';
3
3
  import { Tokenizer, PaymentMethodType, PaymentGateway, TokenizerContainer } from './tokenize';
4
4
  export default class iDonateClient {
@@ -20,5 +20,9 @@ export default class iDonateClient {
20
20
  waitForDonationResult(donationId: string, afterEachCheck?: () => void): Promise<any>;
21
21
  tokenizeCardConnectApplePay(applePayRequest: Partial<ApplePayJS.ApplePayPaymentRequest>): Promise<TokenizeApplePayResult>;
22
22
  createTokenizer(gateway: PaymentGateway, container: TokenizerContainer): Promise<Tokenizer>;
23
+ tokenizeSpreedlyPayPal(data: {
24
+ contact: Contact;
25
+ address: Address;
26
+ }): Promise<string>;
23
27
  selectGateway(availableGateways: PaymentGateway[], paymentType: PaymentMethodType, preferredGatewayId?: string): PaymentGateway | undefined;
24
28
  }
@@ -51,6 +51,7 @@ const constants_1 = require("./constants");
51
51
  const util_1 = require("./util");
52
52
  const apple_pay_1 = __importDefault(require("./apple-pay"));
53
53
  const config_handler_1 = __importDefault(require("./config-handler"));
54
+ const SpreedlyTokenizer_1 = require("./tokenize/SpreedlyTokenizer");
54
55
  const shared = __importStar(require("./shared"));
55
56
  const uuid_1 = require("uuid");
56
57
  const cloudflare_challenge_handler_1 = require("./cloudflare-challenge-handler");
@@ -275,9 +276,13 @@ class iDonateClient {
275
276
  return tokenize_1.Tokenizer.create(gateway, container, {
276
277
  organizationId: this.organizationId,
277
278
  embedId: this.embedId,
279
+ clientConfig: this.config,
278
280
  });
279
281
  });
280
282
  }
283
+ tokenizeSpreedlyPayPal(data) {
284
+ return SpreedlyTokenizer_1.SpreedlyTokenizer.tokenizePayPal(data, this.config);
285
+ }
281
286
  selectGateway(availableGateways, paymentType, preferredGatewayId) {
282
287
  if (preferredGatewayId) {
283
288
  const preferred = availableGateways.find((g) => g.id === preferredGatewayId);
@@ -0,0 +1,36 @@
1
+ import ConfigHandler from './config-handler';
2
+ import { TokenizeCardConnectBankAccountResult } from './types';
3
+ export declare class ClientError extends Error {
4
+ _rawPayload?: any;
5
+ constructor(message: string, payload?: any);
6
+ }
7
+ interface ACHAccount {
8
+ routingNumber: string;
9
+ accountNumber: string;
10
+ accountType?: 'checking' | 'savings';
11
+ accountHolderType?: 'personal' | 'business';
12
+ }
13
+ interface Contact {
14
+ firstName: string;
15
+ lastName: string;
16
+ email?: string;
17
+ }
18
+ interface Address {
19
+ address1: string;
20
+ address2?: string;
21
+ city: string;
22
+ state: string;
23
+ zip: string;
24
+ country?: string;
25
+ }
26
+ export declare function tokenizeCardConnectBankAccountInternal(routingNumber: string, accountNumber: string, config: ConfigHandler): Promise<TokenizeCardConnectBankAccountResult>;
27
+ export declare function tokenizeCardConnectBankAccount(account: ACHAccount | {
28
+ routingNumber: string;
29
+ accountNumber: string;
30
+ }, config: ConfigHandler): Promise<string>;
31
+ export declare function tokenizeSpreedlyBankAccount(data: {
32
+ contact?: Contact;
33
+ address?: Address;
34
+ account: ACHAccount;
35
+ }, config: ConfigHandler): Promise<string>;
36
+ export {};
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ClientError = void 0;
13
+ exports.tokenizeCardConnectBankAccountInternal = tokenizeCardConnectBankAccountInternal;
14
+ exports.tokenizeCardConnectBankAccount = tokenizeCardConnectBankAccount;
15
+ exports.tokenizeSpreedlyBankAccount = tokenizeSpreedlyBankAccount;
16
+ const SPREEDLY_TOKENIZER_URL = 'https://core.spreedly.com/v1/payment_methods.json';
17
+ class ClientError extends Error {
18
+ constructor(message, payload) {
19
+ super(message);
20
+ this.name = 'ClientError';
21
+ this._rawPayload = payload;
22
+ }
23
+ }
24
+ exports.ClientError = ClientError;
25
+ function unpackSpreedlyResponse(response) {
26
+ return response.json().then((data) => {
27
+ if (data.errors) {
28
+ throw new ClientError(data.errors.map((spreedlyError) => spreedlyError.message).join('<br />'), data);
29
+ }
30
+ return data;
31
+ });
32
+ }
33
+ function extractSpreedlyToken(spreedlyData) {
34
+ if (!spreedlyData.transaction || !spreedlyData.transaction.payment_method) {
35
+ throw new ClientError('Payment Method not tokenized.');
36
+ }
37
+ return spreedlyData.transaction.payment_method.token;
38
+ }
39
+ function tokenizeCardConnectBankAccountInternal(routingNumber, accountNumber, config) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const baseUrl = config.cardConnectBaseUrl;
42
+ if (!baseUrl) {
43
+ throw new Error('CardConnect base URL not configured');
44
+ }
45
+ return fetch(`${baseUrl}/cardsecure/api/v1/ccn/tokenize`, {
46
+ method: 'POST',
47
+ headers: {
48
+ 'Content-Type': 'application/json',
49
+ },
50
+ body: JSON.stringify({
51
+ account: `${routingNumber}/${accountNumber}`,
52
+ unique: true,
53
+ }),
54
+ }).then((response) => response.json());
55
+ });
56
+ }
57
+ function tokenizeCardConnectBankAccount(account, config) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const result = yield tokenizeCardConnectBankAccountInternal(account.routingNumber, account.accountNumber, config);
60
+ if (!result.token || result.errorcode !== 0) {
61
+ throw new ClientError(result.message || 'Tokenization failed', {
62
+ _rawPayload: result,
63
+ });
64
+ }
65
+ return result.token;
66
+ });
67
+ }
68
+ function tokenizeSpreedlyBankAccount(data, config) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ if (config.spreedlyEnvironmentKey === undefined) {
71
+ throw new Error('Spreedly environment key not configured');
72
+ }
73
+ const contact = data.contact || { firstName: '', lastName: '' };
74
+ const address = data.address || {
75
+ address1: '',
76
+ city: '',
77
+ state: '',
78
+ zip: '',
79
+ country: 'US'
80
+ };
81
+ return fetch(SPREEDLY_TOKENIZER_URL +
82
+ '?' +
83
+ new URLSearchParams({ environment_key: config.spreedlyEnvironmentKey }), {
84
+ method: 'POST',
85
+ headers: {
86
+ 'Content-Type': 'application/json',
87
+ },
88
+ body: JSON.stringify({
89
+ payment_method: {
90
+ bank_account: {
91
+ first_name: contact.firstName,
92
+ last_name: contact.lastName,
93
+ email: contact.email || '',
94
+ address1: address.address1,
95
+ address2: address.address2 || '',
96
+ city: address.city,
97
+ state: address.state,
98
+ zip: address.zip,
99
+ country: address.country || 'US',
100
+ bank_account_number: data.account.accountNumber.replace(/\s+/g, ''),
101
+ bank_routing_number: data.account.routingNumber.replace(/\s+/g, ''),
102
+ bank_account_holder_type: data.account.accountHolderType || 'personal',
103
+ bank_account_type: data.account.accountType || 'checking',
104
+ },
105
+ },
106
+ retained: false,
107
+ }),
108
+ })
109
+ .then(unpackSpreedlyResponse)
110
+ .then(extractSpreedlyToken);
111
+ });
112
+ }
@@ -5,6 +5,7 @@ import ConfigHandler from '../config-handler';
5
5
  export declare class CardConnectTokenizer extends Tokenizer {
6
6
  private iframeUrl;
7
7
  private containerId;
8
+ private layout;
8
9
  private iframe;
9
10
  private messageHandler?;
10
11
  private expectedOrigin;
@@ -16,10 +17,14 @@ export declare class CardConnectTokenizer extends Tokenizer {
16
17
  private accountTypeEl?;
17
18
  private enableTestMode;
18
19
  private cachedTokenResult?;
20
+ private tokenizationPromise?;
21
+ private tokenizationResolve?;
22
+ private tokenizationReject?;
19
23
  private constructor();
20
- static create(gateway: PaymentGateway, container: TokenizerContainer, config?: {
24
+ static create(gateway: PaymentGateway, container: TokenizerContainer, config: {
21
25
  organizationId: string;
22
26
  embedId: string;
27
+ clientConfig: ConfigHandler;
23
28
  }): Promise<CardConnectTokenizer>;
24
29
  private createInternalElements;
25
30
  private createCreditCardFields;
@@ -34,6 +39,9 @@ export declare class CardConnectTokenizer extends Tokenizer {
34
39
  clear(): void;
35
40
  focus(field: 'cardNumber' | 'cvv' | 'expiry' | 'routingNumber' | 'accountNumber'): void;
36
41
  destroy(): void;
42
+ hasToken(): boolean;
43
+ getToken(): PaymentToken | null;
44
+ get tokenizationMode(): 'auto' | 'manual';
37
45
  private handleMessage;
38
46
  private handleValidationMessage;
39
47
  private static generateIframeUrl;