@idonatedev/idonate-sdk 1.0.15 → 1.1.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 (50) hide show
  1. package/README.md +31 -0
  2. package/dist/apple-pay.d.ts +0 -1
  3. package/dist/apple-pay.js +32 -62
  4. package/dist/cloudflare-challenge-handler.d.ts +2 -2
  5. package/dist/cloudflare-challenge-handler.js +65 -92
  6. package/dist/config-handler.d.ts +3 -0
  7. package/dist/config-handler.js +16 -11
  8. package/dist/constants.d.ts +1 -0
  9. package/dist/constants.js +67 -3
  10. package/dist/google-pay.d.ts +0 -1
  11. package/dist/google-pay.js +65 -78
  12. package/dist/idonate-client.d.ts +6 -19
  13. package/dist/idonate-client.js +165 -192
  14. package/dist/index.js +40 -11
  15. package/dist/recaptcha.d.ts +0 -1
  16. package/dist/recaptcha.js +40 -49
  17. package/dist/shared.js +8 -9
  18. package/dist/test-utils.d.ts +81 -0
  19. package/dist/test-utils.js +110 -0
  20. package/dist/tokenize/CardConnectTokenizer.d.ts +43 -0
  21. package/dist/tokenize/CardConnectTokenizer.js +620 -0
  22. package/dist/tokenize/SpreedlyTokenizer.d.ts +85 -0
  23. package/dist/tokenize/SpreedlyTokenizer.js +952 -0
  24. package/dist/tokenize/Tokenizer.d.ts +32 -0
  25. package/dist/tokenize/Tokenizer.js +183 -0
  26. package/dist/tokenize/iats.js +11 -13
  27. package/dist/tokenize/index.d.ts +5 -3
  28. package/dist/tokenize/index.js +43 -6
  29. package/dist/tokenize/spreedly-secure.d.ts +8 -0
  30. package/dist/tokenize/spreedly-secure.js +43 -0
  31. package/dist/tokenize/styles.d.ts +3 -0
  32. package/dist/tokenize/styles.js +42 -0
  33. package/dist/tokenize/tokenizer-constants.d.ts +62 -0
  34. package/dist/tokenize/tokenizer-constants.js +65 -0
  35. package/dist/tokenize/tokenizer-utils.d.ts +19 -0
  36. package/dist/tokenize/tokenizer-utils.js +156 -0
  37. package/dist/tokenize/types.d.ts +149 -0
  38. package/dist/tokenize/types.js +30 -0
  39. package/dist/typeAdapters.d.ts +3 -2
  40. package/dist/typeAdapters.js +42 -50
  41. package/dist/types.d.ts +50 -41
  42. package/dist/types.js +12 -24
  43. package/dist/util.d.ts +2 -2
  44. package/dist/util.js +30 -33
  45. package/package.json +41 -18
  46. package/umd/idonate-sdk.js +1 -1
  47. package/dist/tokenize/cardconnect.d.ts +0 -3
  48. package/dist/tokenize/cardconnect.js +0 -16
  49. package/dist/tokenize/spreedly.d.ts +0 -48
  50. package/dist/tokenize/spreedly.js +0 -208
@@ -1,18 +1,39 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- var GooglePay = (function () {
15
- function GooglePay(googlePayConfig) {
3
+ class GooglePay {
4
+ static resolveLib(options) {
5
+ const startWait = new Date();
6
+ return new Promise((resolve, reject) => {
7
+ function poll() {
8
+ if (window.google !== undefined &&
9
+ window.google.payments !== undefined) {
10
+ const paymentsClient = new google.payments.api.PaymentsClient(options);
11
+ resolve(paymentsClient);
12
+ }
13
+ else {
14
+ const elapsedMs = new Date().valueOf() - startWait.valueOf();
15
+ if (elapsedMs > 15000) {
16
+ reject(new Error('pay.js not loaded after 15 seconds'));
17
+ }
18
+ else {
19
+ setTimeout(poll, 250);
20
+ }
21
+ }
22
+ }
23
+ poll();
24
+ });
25
+ }
26
+ static injectScript() {
27
+ if (window.google !== undefined && window.google.payments !== undefined) {
28
+ throw new Error('google payments is already injected');
29
+ }
30
+ const script = document.createElement('script');
31
+ script.src = 'https://pay.google.com/gp/p/js/pay.js?render=explicit';
32
+ script.async = true;
33
+ script.defer = true;
34
+ document.body.appendChild(script);
35
+ }
36
+ constructor(googlePayConfig) {
16
37
  this.baseRequest = {
17
38
  apiVersion: 2,
18
39
  apiVersionMinor: 0,
@@ -52,94 +73,61 @@ var GooglePay = (function () {
52
73
  this.googlePayOptions = {
53
74
  environment: 'PRODUCTION',
54
75
  };
55
- this.paymentRequestDefaults = __assign(__assign({}, this.baseRequest), { merchantInfo: {
76
+ this.paymentRequestDefaults = Object.assign(Object.assign({}, this.baseRequest), { merchantInfo: {
56
77
  merchantId: '',
57
78
  }, transactionInfo: this.transactionInfo, emailRequired: true, allowedPaymentMethods: [
58
- __assign(__assign({}, this.baseCardPaymentMethod), { tokenizationSpecification: this.tokenizationSpecification }),
79
+ Object.assign(Object.assign({}, this.baseCardPaymentMethod), { tokenizationSpecification: this.tokenizationSpecification }),
59
80
  ] });
60
81
  this.paymentsClient = null;
61
- var paymentOptions = googlePayConfig.paymentOptions, cardConnectMerchantId = googlePayConfig.cardConnectMerchantId, paymentDataRequest = googlePayConfig.paymentDataRequest, _a = googlePayConfig.baseCardPaymentMethodParameters, baseCardPaymentMethodParameters = _a === void 0 ? {} : _a;
62
- this.tokenizationSpecification.parameters.gatewayMerchantId = cardConnectMerchantId;
82
+ const { paymentOptions, cardConnectMerchantId, paymentDataRequest, baseCardPaymentMethodParameters = {}, } = googlePayConfig;
83
+ this.tokenizationSpecification.parameters.gatewayMerchantId =
84
+ cardConnectMerchantId;
63
85
  this.paymentRequest = Object.assign({}, this.paymentRequestDefaults, paymentDataRequest);
64
- this.googlePayOptions = Object.assign({}, this.googlePayOptions, __assign(__assign({}, paymentOptions), { merchantInfo: this.paymentRequest.merchantInfo }));
65
- this.baseCardPaymentMethod.parameters = __assign(__assign({}, this.baseCardPaymentMethod.parameters), baseCardPaymentMethodParameters);
86
+ this.googlePayOptions = Object.assign({}, this.googlePayOptions, Object.assign(Object.assign({}, paymentOptions), { merchantInfo: this.paymentRequest.merchantInfo }));
87
+ this.baseCardPaymentMethod.parameters = Object.assign(Object.assign({}, this.baseCardPaymentMethod.parameters), baseCardPaymentMethodParameters);
66
88
  }
67
- GooglePay.resolveLib = function (options) {
68
- var startWait = new Date();
69
- return new Promise(function (resolve, reject) {
70
- function poll() {
71
- if (window.google !== undefined &&
72
- window.google.payments !== undefined) {
73
- var paymentsClient = new google.payments.api.PaymentsClient(options);
74
- resolve(paymentsClient);
75
- }
76
- else {
77
- var elapsedMs = new Date().valueOf() - startWait.valueOf();
78
- if (elapsedMs > 15000) {
79
- reject(new Error('pay.js not loaded after 15 seconds'));
80
- }
81
- else {
82
- setTimeout(poll, 250);
83
- }
84
- }
85
- }
86
- poll();
87
- });
88
- };
89
- GooglePay.injectScript = function () {
90
- if (window.google !== undefined && window.google.payments !== undefined) {
91
- throw new Error('google payments is already injected');
92
- }
93
- var script = document.createElement('script');
94
- script.src = 'https://pay.google.com/gp/p/js/pay.js?render=explicit';
95
- script.async = true;
96
- script.defer = true;
97
- document.body.appendChild(script);
98
- };
99
- GooglePay.prototype.getGoogleIsReadyToPayRequest = function () {
89
+ getGoogleIsReadyToPayRequest() {
100
90
  return Object.assign({}, this.baseRequest, {
101
91
  allowedPaymentMethods: [this.baseCardPaymentMethod],
102
92
  });
103
- };
104
- GooglePay.prototype.getGooglePaymentClient = function () {
105
- var _this = this;
106
- return new Promise(function (resolve, reject) {
107
- if (!_this.paymentsClient) {
108
- GooglePay.resolveLib(_this.googlePayOptions)
109
- .then(function (client) {
110
- _this.paymentsClient = client;
93
+ }
94
+ getGooglePaymentClient() {
95
+ return new Promise((resolve, reject) => {
96
+ if (!this.paymentsClient) {
97
+ GooglePay.resolveLib(this.googlePayOptions)
98
+ .then((client) => {
99
+ this.paymentsClient = client;
111
100
  resolve(client);
112
101
  })
113
- .catch(function (err) { return reject(err); });
102
+ .catch((err) => reject(err));
114
103
  }
115
104
  else {
116
- resolve(_this.paymentsClient);
105
+ resolve(this.paymentsClient);
117
106
  }
118
107
  });
119
- };
120
- GooglePay.prototype.onGooglePaymentButtonClicked = function (transactionInfoUpdate) {
121
- var _this = this;
122
- var paymentDataRequest = this.paymentRequest;
108
+ }
109
+ onGooglePaymentButtonClicked(transactionInfoUpdate) {
110
+ const paymentDataRequest = this.paymentRequest;
123
111
  this.transactionInfo = Object.assign({}, this.transactionInfo, transactionInfoUpdate);
124
112
  paymentDataRequest.transactionInfo = this.transactionInfo;
125
- return new Promise(function (resolve, reject) {
126
- if (!_this.paymentsClient) {
113
+ return new Promise((resolve, reject) => {
114
+ if (!this.paymentsClient) {
127
115
  reject(new Error('PaymentClient is not initialized'));
128
116
  }
129
117
  else {
130
- _this.paymentsClient
118
+ this.paymentsClient
131
119
  .loadPaymentData(paymentDataRequest)
132
- .then(function (paymentData) {
120
+ .then((paymentData) => {
133
121
  resolve(paymentData);
134
122
  })
135
- .catch(function (err) {
123
+ .catch((err) => {
136
124
  reject(err);
137
125
  });
138
126
  }
139
127
  });
140
- };
141
- GooglePay.prototype.tokenizeWithCardConnect = function (paymentToken, cardConnectBaseUrl) {
142
- return fetch(cardConnectBaseUrl + "/cardsecure/api/v1/ccn/tokenize", {
128
+ }
129
+ tokenizeWithCardConnect(paymentToken, cardConnectBaseUrl) {
130
+ return fetch(`${cardConnectBaseUrl}/cardsecure/api/v1/ccn/tokenize`, {
143
131
  method: 'POST',
144
132
  headers: {
145
133
  'Content-Type': 'application/json',
@@ -149,8 +137,7 @@ var GooglePay = (function () {
149
137
  devicedata: paymentToken,
150
138
  unique: true,
151
139
  }),
152
- }).then(function (response) { return response.json(); });
153
- };
154
- return GooglePay;
155
- }());
140
+ }).then((response) => response.json());
141
+ }
142
+ }
156
143
  exports.default = GooglePay;
@@ -1,37 +1,24 @@
1
- /// <reference types="applepayjs" />
2
- import { ACHAccount, Address, ClientOptions, Contact, CreatePaymentMethodRequest, CreatePaymentMethodResult, CreateDonationRequest, CreateDonationResult, CreditCard, TokenizeApplePayResult } from './types';
1
+ import { ClientOptions, CreatePaymentMethodRequest, CreatePaymentMethodResult, CreateDonationRequest, CreateDonationResult, TokenizeApplePayResult } from './types';
3
2
  import ConfigHandler from './config-handler';
4
- import * as spreedly from './tokenize/spreedly';
3
+ import { Tokenizer, PaymentMethodType, PaymentGateway, TokenizerContainer } from './tokenize';
5
4
  export default class iDonateClient {
6
5
  private readonly clientKey;
6
+ private readonly embedId;
7
7
  private currentOrganizationId;
8
8
  private allowTransaction;
9
9
  get organizationId(): string;
10
10
  readonly options: ClientOptions;
11
11
  readonly config: ConfigHandler;
12
- constructor(clientKey: string, options?: Partial<ClientOptions>);
12
+ constructor(clientKey: string, embedId: string, options?: Partial<ClientOptions>);
13
13
  createDonation(donation: CreateDonationRequest): Promise<CreateDonationResult>;
14
14
  createTransaction(donation: CreateDonationRequest): Promise<{
15
15
  transactionId: string | undefined;
16
16
  _raw_response: any;
17
17
  }>;
18
18
  createPaymentMethod(paymentMethod: CreatePaymentMethodRequest): Promise<CreatePaymentMethodResult>;
19
- private tokenizeCardConnectBankAccountInternal;
20
19
  setOrganizationId(organizationId: string): void;
21
- tokenizeCardConnectBankAccount(account: Partial<ACHAccount> & Pick<ACHAccount, 'accountNumber' | 'routingNumber'>): Promise<string>;
22
- tokenizeSpreedlyCreditCard(data: {
23
- contact: Contact;
24
- address: Address;
25
- card: CreditCard;
26
- }): Promise<string>;
27
- tokenizeSpreedlyBankAccount(data: Parameters<typeof spreedly.tokenizeBankAccount>[0]): Promise<string>;
28
- tokenizeSpreedlyPayPal(data: {
29
- contact: Contact;
30
- address: Address;
31
- }): Promise<string>;
32
- generateCardConnectTokenizerUrl(formOptions?: {
33
- [option: string]: string;
34
- }): string;
35
20
  waitForDonationResult(donationId: string, afterEachCheck?: () => void): Promise<any>;
36
21
  tokenizeCardConnectApplePay(applePayRequest: Partial<ApplePayJS.ApplePayPaymentRequest>): Promise<TokenizeApplePayResult>;
22
+ createTokenizer(gateway: PaymentGateway, container: TokenizerContainer): Promise<Tokenizer>;
23
+ selectGateway(availableGateways: PaymentGateway[], paymentType: PaymentMethodType, preferredGatewayId?: string): PaymentGateway | undefined;
37
24
  }