@idonatedev/idonate-sdk 1.1.0-dev13 → 1.1.0-dev15
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.d.ts +1 -1
- package/dist/constants.js +2 -6
- package/dist/esm/apple-pay.d.ts +12 -0
- package/dist/esm/apple-pay.js +74 -0
- package/dist/esm/cloudflare-challenge-handler.d.ts +5 -0
- package/dist/esm/cloudflare-challenge-handler.js +77 -0
- package/dist/esm/config-handler.d.ts +22 -0
- package/dist/esm/config-handler.js +47 -0
- package/dist/esm/constants.d.ts +18 -0
- package/dist/esm/constants.js +81 -0
- package/dist/esm/google-pay.d.ts +18 -0
- package/dist/esm/google-pay.js +140 -0
- package/dist/esm/idonate-client.d.ts +28 -0
- package/dist/esm/idonate-client.js +256 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/recaptcha.d.ts +12 -0
- package/dist/esm/recaptcha.js +89 -0
- package/dist/esm/shared.d.ts +3 -0
- package/dist/esm/shared.js +13 -0
- package/dist/esm/test-utils.d.ts +81 -0
- package/dist/esm/test-utils.js +94 -0
- package/dist/esm/tokenize/CardConnectTokenizer.d.ts +51 -0
- package/dist/esm/tokenize/CardConnectTokenizer.js +706 -0
- package/dist/esm/tokenize/SpreedlyTokenizer.d.ts +92 -0
- package/dist/esm/tokenize/SpreedlyTokenizer.js +1140 -0
- package/dist/esm/tokenize/Tokenizer.d.ts +37 -0
- package/dist/esm/tokenize/Tokenizer.js +146 -0
- package/dist/esm/tokenize/iats.d.ts +3 -0
- package/dist/esm/tokenize/iats.js +48 -0
- package/dist/esm/tokenize/index.d.ts +6 -0
- package/dist/esm/tokenize/index.js +6 -0
- package/dist/esm/tokenize/spreedly-secure.d.ts +8 -0
- package/dist/esm/tokenize/spreedly-secure.js +40 -0
- package/dist/esm/tokenize/styles.d.ts +4 -0
- package/dist/esm/tokenize/styles.js +46 -0
- package/dist/esm/tokenize/tokenizer-constants.d.ts +62 -0
- package/dist/esm/tokenize/tokenizer-constants.js +62 -0
- package/dist/esm/tokenize/tokenizer-utils.d.ts +19 -0
- package/dist/esm/tokenize/tokenizer-utils.js +139 -0
- package/dist/esm/tokenize/types.d.ts +144 -0
- package/dist/esm/tokenize/types.js +26 -0
- package/dist/esm/typeAdapters.d.ts +29 -0
- package/dist/esm/typeAdapters.js +188 -0
- package/dist/esm/types.d.ts +367 -0
- package/dist/esm/types.js +14 -0
- package/dist/esm/util.d.ts +17 -0
- package/dist/esm/util.js +113 -0
- package/package.json +13 -2
- package/umd/idonate-sdk.js +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SDK_VERSION
|
|
1
|
+
export declare const SDK_VERSION = "__SDK_VERSION__";
|
|
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,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
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;
|
|
7
|
-
|
|
8
|
-
exports.SDK_VERSION = package_json_1.default.version;
|
|
4
|
+
exports.SDK_VERSION = '1.1.0-dev15';
|
|
9
5
|
exports.PRODUCTION_BASE_URL = 'https://secure-api.idonate.com';
|
|
10
6
|
exports.SANDBOX_BASE_URL = 'https://api.qa-idonate.com';
|
|
11
7
|
exports.PRODUCTION_CARD_CONNECT_BASE_URL = 'https://boltgw.cardconnect.com:8443';
|
|
@@ -83,6 +79,6 @@ input#cccvvfield {
|
|
|
83
79
|
}
|
|
84
80
|
`.replace(/\s+/gi, ' ');
|
|
85
81
|
exports.CLIENT_HEADERS = {
|
|
86
|
-
'User-Agent': navigator.userAgent + ` idonate-sdk@${
|
|
82
|
+
'User-Agent': navigator.userAgent + ` idonate-sdk@${exports.SDK_VERSION}`,
|
|
87
83
|
'Content-Type': 'application/json',
|
|
88
84
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApplePayMerchantValidationPayload, MerchantSession, TokenizeCardConnectApplePayResult } from './types';
|
|
2
|
+
export default class ApplePay {
|
|
3
|
+
private appleSession;
|
|
4
|
+
private paymentRequest;
|
|
5
|
+
private readonly paymentRequestDefaults;
|
|
6
|
+
private static readonly ApplePayApiVersion;
|
|
7
|
+
constructor(paymentRequest: Partial<ApplePayJS.ApplePayPaymentRequest>);
|
|
8
|
+
static isSupported(): boolean;
|
|
9
|
+
begin(): Promise<ApplePaySession>;
|
|
10
|
+
createSession(payload: ApplePayMerchantValidationPayload, embedApiBaseUrl: string): Promise<MerchantSession>;
|
|
11
|
+
tokenizeWithCardConnect(applePaymentMethod: ApplePayJS.ApplePayPayment, cardConnectBaseUrl: string): Promise<TokenizeCardConnectApplePayResult>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
import { CLIENT_HEADERS } from './constants';
|
|
11
|
+
class ApplePay {
|
|
12
|
+
constructor(paymentRequest) {
|
|
13
|
+
this.appleSession = null;
|
|
14
|
+
this.paymentRequestDefaults = {
|
|
15
|
+
currencyCode: 'USD',
|
|
16
|
+
countryCode: 'US',
|
|
17
|
+
merchantCapabilities: ['supports3DS', 'supportsCredit', 'supportsDebit'],
|
|
18
|
+
supportedNetworks: ['amex', 'masterCard', 'visa', 'discover'],
|
|
19
|
+
requiredBillingContactFields: ['postalAddress', 'name'],
|
|
20
|
+
requiredShippingContactFields: ['email', 'phone'],
|
|
21
|
+
total: {
|
|
22
|
+
label: 'iDonate',
|
|
23
|
+
amount: '',
|
|
24
|
+
type: 'final',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
this.paymentRequest = Object.assign({}, this.paymentRequestDefaults, paymentRequest);
|
|
28
|
+
}
|
|
29
|
+
static isSupported() {
|
|
30
|
+
return (window.ApplePaySession &&
|
|
31
|
+
ApplePaySession.canMakePayments() &&
|
|
32
|
+
ApplePaySession.supportsVersion(ApplePay.ApplePayApiVersion));
|
|
33
|
+
}
|
|
34
|
+
begin() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
if (!ApplePay.isSupported()) {
|
|
37
|
+
throw new Error('Apple Pay Not Supported');
|
|
38
|
+
}
|
|
39
|
+
this.appleSession = new ApplePaySession(ApplePay.ApplePayApiVersion, this.paymentRequest);
|
|
40
|
+
this.appleSession.begin();
|
|
41
|
+
return this.appleSession;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
createSession(payload, embedApiBaseUrl) {
|
|
45
|
+
return fetch(`${embedApiBaseUrl}/payment/create-session`, {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers: CLIENT_HEADERS,
|
|
48
|
+
body: JSON.stringify(payload),
|
|
49
|
+
}).then((response) => response.json());
|
|
50
|
+
}
|
|
51
|
+
tokenizeWithCardConnect(applePaymentMethod, cardConnectBaseUrl) {
|
|
52
|
+
const paymentData = applePaymentMethod.token.paymentData;
|
|
53
|
+
const token = paymentData.data;
|
|
54
|
+
const ectype = 'apple';
|
|
55
|
+
const ecsig = paymentData.signature;
|
|
56
|
+
const eckey = paymentData.header.ephemeralPublicKey;
|
|
57
|
+
const ectid = paymentData.header.transactionId;
|
|
58
|
+
const ecpublickeyhash = paymentData.header.publicKeyHash;
|
|
59
|
+
const dataString = `${token}&ectype=${ectype}&ecsig=${ecsig}&eckey=${eckey}&ectid=${ectid}&echash=&ecpublickeyhash=${ecpublickeyhash}`;
|
|
60
|
+
return fetch(`${cardConnectBaseUrl}/cardsecure/api/v1/ccn/tokenize`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: {
|
|
63
|
+
'Content-Type': 'application/json',
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify({
|
|
66
|
+
encryptionhandler: 'EC_APPLE_PAY',
|
|
67
|
+
devicedata: dataString,
|
|
68
|
+
unique: true,
|
|
69
|
+
}),
|
|
70
|
+
}).then((response) => response.json());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
ApplePay.ApplePayApiVersion = 6;
|
|
74
|
+
export default ApplePay;
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
let turnstileInstance = null;
|
|
11
|
+
export const handleCFChallenge = (challengeResponse, sdkClient) => new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
try {
|
|
14
|
+
const document = window === null || window === void 0 ? void 0 : window.document;
|
|
15
|
+
if (!document || !window) {
|
|
16
|
+
throw new Error('document is not present on window');
|
|
17
|
+
}
|
|
18
|
+
const challengeWrapper = document.createElement('div');
|
|
19
|
+
const challengeDiv = document.createElement('div');
|
|
20
|
+
const showChallenge = (turnstile) => {
|
|
21
|
+
var _a;
|
|
22
|
+
(_a = turnstile === null || turnstile === void 0 ? void 0 : turnstile.render) === null || _a === void 0 ? void 0 : _a.call(turnstile, '#iDonateTurnstileBox', {
|
|
23
|
+
sitekey: sdkClient.config.turnstileSiteKey,
|
|
24
|
+
callback(token, preClearance) {
|
|
25
|
+
challengeWrapper.remove();
|
|
26
|
+
resolve({ token, preClearance });
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
window.idonateTurnstileLoadedHandler = () => {
|
|
31
|
+
const turnstile = window.turnstile;
|
|
32
|
+
challengeDiv.innerHTML = '';
|
|
33
|
+
if (turnstile) {
|
|
34
|
+
turnstileInstance = turnstile;
|
|
35
|
+
}
|
|
36
|
+
showChallenge(turnstile);
|
|
37
|
+
};
|
|
38
|
+
challengeWrapper.setAttribute('id', 'idonateTurnstileWrapper');
|
|
39
|
+
challengeWrapper.style.position = 'fixed';
|
|
40
|
+
challengeWrapper.style.top = '0';
|
|
41
|
+
challengeWrapper.style.bottom = '0';
|
|
42
|
+
challengeWrapper.style.left = '0';
|
|
43
|
+
challengeWrapper.style.right = '0';
|
|
44
|
+
challengeWrapper.style.backgroundColor = 'rgba(0,0,0,0.9)';
|
|
45
|
+
challengeWrapper.style.transition = 'all 400ms';
|
|
46
|
+
challengeWrapper.style.display = 'flex';
|
|
47
|
+
challengeWrapper.style.flexDirection = 'column';
|
|
48
|
+
challengeWrapper.style.padding = '40px 30px';
|
|
49
|
+
challengeWrapper.style.opacity = '0';
|
|
50
|
+
challengeWrapper.style.color = 'white';
|
|
51
|
+
challengeWrapper.style.fontFamily = 'sans-serif';
|
|
52
|
+
challengeWrapper.style.zIndex = '1000';
|
|
53
|
+
challengeWrapper.innerHTML =
|
|
54
|
+
'<h1 id="idonateTurnstileVerificationHeader">Last tiny step before we submit your payment:</h1>';
|
|
55
|
+
challengeDiv.setAttribute('id', 'iDonateTurnstileBox');
|
|
56
|
+
challengeWrapper.append(challengeDiv);
|
|
57
|
+
document.body.append(challengeWrapper);
|
|
58
|
+
if (turnstileInstance) {
|
|
59
|
+
showChallenge(turnstileInstance);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const cloudflareScript = document.createElement('script');
|
|
63
|
+
challengeDiv.innerHTML = 'loading ...';
|
|
64
|
+
cloudflareScript.src =
|
|
65
|
+
sdkClient.config.turnstileCdnUrl +
|
|
66
|
+
'?render=explicit&onload=idonateTurnstileLoadedHandler';
|
|
67
|
+
document.body.append(cloudflareScript);
|
|
68
|
+
}
|
|
69
|
+
(_a = challengeDiv.scrollIntoView) === null || _a === void 0 ? void 0 : _a.call(challengeDiv);
|
|
70
|
+
challengeWrapper.style.opacity = '1';
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
(_b = console === null || console === void 0 ? void 0 : console.error) === null || _b === void 0 ? void 0 : _b.call(console, e);
|
|
74
|
+
(_c = console === null || console === void 0 ? void 0 : console.warn) === null || _c === void 0 ? void 0 : _c.call(console, 'iDonate SDK: Could not handle request, please reload the page and try again');
|
|
75
|
+
reject(null);
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClientOptions } from './types';
|
|
2
|
+
export default class ConfigHandler {
|
|
3
|
+
readonly apiBaseUrl: string;
|
|
4
|
+
readonly embedApiBaseUrl: string;
|
|
5
|
+
readonly cardConnectBaseUrl: string;
|
|
6
|
+
readonly cardConnectTokenizerUrl: string;
|
|
7
|
+
readonly authApiBaseUrl: string;
|
|
8
|
+
readonly donorApiBaseUrl: string;
|
|
9
|
+
readonly spreedlyEnvironmentKey: string | undefined;
|
|
10
|
+
readonly applePayUrl: string;
|
|
11
|
+
readonly pcScriptBase: string;
|
|
12
|
+
readonly pcScriptId: string;
|
|
13
|
+
readonly enableDelay: boolean;
|
|
14
|
+
readonly secondsToDelay: number;
|
|
15
|
+
readonly turnstileCdnUrl: string;
|
|
16
|
+
readonly turnstileSiteKey: string;
|
|
17
|
+
readonly client: string;
|
|
18
|
+
readonly enableSpreedlySecureTokenization: boolean;
|
|
19
|
+
readonly organizationId: number | undefined;
|
|
20
|
+
readonly embedId: string | undefined;
|
|
21
|
+
constructor(options: Partial<ClientOptions>);
|
|
22
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SANDBOX_BASE_URL, PRODUCTION_CARD_CONNECT_BASE_URL, PRODUCTION_BASE_URL, SANDBOX_CARD_CONNECT_BASE_URL, SANDBOX_APPLE_PAY_URL, APPLE_PAY_URL, FALLBACK_PC_SCRIPT_URL, FALLBACK_PC_SCRIPT_ID, FALLBACK_CF_TURNSTILE_SITE_KEY, DEFAULT_CF_TURNSTILE_CDN_EXPLICIT_URL, DEFAULT_APP_NAME, } from './constants';
|
|
2
|
+
export default class ConfigHandler {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
if (options.enableSandboxMode) {
|
|
5
|
+
this.apiBaseUrl = SANDBOX_BASE_URL;
|
|
6
|
+
this.cardConnectBaseUrl = SANDBOX_CARD_CONNECT_BASE_URL;
|
|
7
|
+
this.applePayUrl = SANDBOX_APPLE_PAY_URL;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
this.apiBaseUrl = PRODUCTION_BASE_URL;
|
|
11
|
+
this.cardConnectBaseUrl = PRODUCTION_CARD_CONNECT_BASE_URL;
|
|
12
|
+
this.applePayUrl = APPLE_PAY_URL;
|
|
13
|
+
}
|
|
14
|
+
this.client = options.sdkClientName || DEFAULT_APP_NAME;
|
|
15
|
+
if (options.overrideBaseUrl) {
|
|
16
|
+
this.apiBaseUrl = options.overrideBaseUrl;
|
|
17
|
+
}
|
|
18
|
+
this.authApiBaseUrl =
|
|
19
|
+
options.overrideAuthApiBaseUrl || `${this.apiBaseUrl}/auth`;
|
|
20
|
+
this.donorApiBaseUrl =
|
|
21
|
+
options.overrideDonorApiBaseUrl || `${this.apiBaseUrl}/donor`;
|
|
22
|
+
this.embedApiBaseUrl =
|
|
23
|
+
options.overrideEmbedApiBaseUrl || `${this.apiBaseUrl}/embed`;
|
|
24
|
+
if (options.overrideApplePayUrl) {
|
|
25
|
+
this.applePayUrl = options.overrideApplePayUrl;
|
|
26
|
+
}
|
|
27
|
+
if (options.overrideCardConnectBaseUrl) {
|
|
28
|
+
this.cardConnectBaseUrl = options.overrideCardConnectBaseUrl;
|
|
29
|
+
}
|
|
30
|
+
this.pcScriptBase = options.pcScriptBase || FALLBACK_PC_SCRIPT_URL;
|
|
31
|
+
this.pcScriptId = options.pcScriptId || FALLBACK_PC_SCRIPT_ID;
|
|
32
|
+
this.turnstileCdnUrl =
|
|
33
|
+
options.turnstileCdnUrl || DEFAULT_CF_TURNSTILE_CDN_EXPLICIT_URL;
|
|
34
|
+
this.turnstileSiteKey =
|
|
35
|
+
options.turnstileSiteKey || FALLBACK_CF_TURNSTILE_SITE_KEY;
|
|
36
|
+
if (options === null || options === void 0 ? void 0 : options.spreedlyEnvironmentKey) {
|
|
37
|
+
this.spreedlyEnvironmentKey = options.spreedlyEnvironmentKey;
|
|
38
|
+
}
|
|
39
|
+
this.enableDelay = options.enableDelay || false;
|
|
40
|
+
this.secondsToDelay = options.secondsToDelay || 0;
|
|
41
|
+
this.enableSpreedlySecureTokenization =
|
|
42
|
+
options.enableSpreedlySecureTokenization || false;
|
|
43
|
+
this.organizationId = options.organizationId;
|
|
44
|
+
this.embedId = options.embedId;
|
|
45
|
+
this.cardConnectTokenizerUrl = `${this.cardConnectBaseUrl}/itoke/ajax-tokenizer.html`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "__SDK_VERSION__";
|
|
2
|
+
export declare const PRODUCTION_BASE_URL = "https://secure-api.idonate.com";
|
|
3
|
+
export declare const SANDBOX_BASE_URL = "https://api.qa-idonate.com";
|
|
4
|
+
export declare const PRODUCTION_CARD_CONNECT_BASE_URL = "https://boltgw.cardconnect.com:8443";
|
|
5
|
+
export declare const SANDBOX_CARD_CONNECT_BASE_URL = "https://boltgw-uat.cardconnect.com";
|
|
6
|
+
export declare const SPREEDLY_TOKENIZER_URL = "https://core.spreedly.com/v1/payment_methods.json";
|
|
7
|
+
export declare const APPLE_PAY_URL = "https://apple-pay-gateway.apple.com/paymentservices/paymentSession";
|
|
8
|
+
export declare const SANDBOX_APPLE_PAY_URL = "https://apple-pay-gateway-cert.apple.com/paymentservices/paymentSession";
|
|
9
|
+
export declare const FALLBACK_PC_SCRIPT_URL = "https://p.idonate.com/r";
|
|
10
|
+
export declare const FALLBACK_PC_SCRIPT_ID = "_3fd4dad26e8c277bc50fb2ddf8233b50bc8d9704";
|
|
11
|
+
export declare const FALLBACK_CF_TURNSTILE_SITE_KEY = "0x4AAAAAAAxuRxNZTvX8shIj";
|
|
12
|
+
export declare const DEFAULT_CF_TURNSTILE_CDN_EXPLICIT_URL = "https://challenges.cloudflare.com/turnstile/v0/api.js";
|
|
13
|
+
export declare const DEFAULT_APP_NAME = "unnamed-sdk-client";
|
|
14
|
+
export declare const CARD_CONNECT_DEFAULT_STYLE: string;
|
|
15
|
+
export declare const CLIENT_HEADERS: {
|
|
16
|
+
'User-Agent': string;
|
|
17
|
+
'Content-Type': string;
|
|
18
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const SDK_VERSION = '1.1.0-dev15';
|
|
2
|
+
export const PRODUCTION_BASE_URL = 'https://secure-api.idonate.com';
|
|
3
|
+
export const SANDBOX_BASE_URL = 'https://api.qa-idonate.com';
|
|
4
|
+
export const PRODUCTION_CARD_CONNECT_BASE_URL = 'https://boltgw.cardconnect.com:8443';
|
|
5
|
+
export const SANDBOX_CARD_CONNECT_BASE_URL = 'https://boltgw-uat.cardconnect.com';
|
|
6
|
+
export const SPREEDLY_TOKENIZER_URL = 'https://core.spreedly.com/v1/payment_methods.json';
|
|
7
|
+
export const APPLE_PAY_URL = 'https://apple-pay-gateway.apple.com/paymentservices/paymentSession';
|
|
8
|
+
export const SANDBOX_APPLE_PAY_URL = 'https://apple-pay-gateway-cert.apple.com/paymentservices/paymentSession';
|
|
9
|
+
export const FALLBACK_PC_SCRIPT_URL = 'https://p.idonate.com/r';
|
|
10
|
+
export const FALLBACK_PC_SCRIPT_ID = '_3fd4dad26e8c277bc50fb2ddf8233b50bc8d9704';
|
|
11
|
+
export const FALLBACK_CF_TURNSTILE_SITE_KEY = '0x4AAAAAAAxuRxNZTvX8shIj';
|
|
12
|
+
export const DEFAULT_CF_TURNSTILE_CDN_EXPLICIT_URL = 'https://challenges.cloudflare.com/turnstile/v0/api.js';
|
|
13
|
+
export const DEFAULT_APP_NAME = 'unnamed-sdk-client';
|
|
14
|
+
export const CARD_CONNECT_DEFAULT_STYLE = `
|
|
15
|
+
body {
|
|
16
|
+
margin: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
form {
|
|
20
|
+
display: flex;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
label#cccardlabel {
|
|
24
|
+
display: none;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
br {
|
|
28
|
+
display: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
label#cccvvlabel {
|
|
32
|
+
display: none;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
label#ccexpirylabel {
|
|
36
|
+
display: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
input {
|
|
40
|
+
padding: 10px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
select {
|
|
44
|
+
padding: 10px;
|
|
45
|
+
font-size: 14px;
|
|
46
|
+
color: #8b959d;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
select#ccexpirymonth {
|
|
50
|
+
margin-right: -30px;
|
|
51
|
+
border: 1px solid #b6b8ba;
|
|
52
|
+
border-right: 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
input#ccnumfield {
|
|
56
|
+
width: 70%;
|
|
57
|
+
border: 1px solid #b6b8ba;
|
|
58
|
+
border-right: 0;
|
|
59
|
+
border-top-left-radius: 3px;
|
|
60
|
+
border-bottom-left-radius: 3px;
|
|
61
|
+
font-size: 14px;
|
|
62
|
+
color: #8b959d;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
select#ccexpiryyear {
|
|
66
|
+
border: 1px solid #b6b8ba;
|
|
67
|
+
border-right: 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
input#cccvvfield {
|
|
71
|
+
border: 1px solid #b6b8ba;
|
|
72
|
+
border-top-right-radius: 3px;
|
|
73
|
+
border-bottom-right-radius: 3px;
|
|
74
|
+
font-size: 14px;
|
|
75
|
+
color: #8b959d;
|
|
76
|
+
}
|
|
77
|
+
`.replace(/\s+/gi, ' ');
|
|
78
|
+
export const CLIENT_HEADERS = {
|
|
79
|
+
'User-Agent': navigator.userAgent + ` idonate-sdk@${SDK_VERSION}`,
|
|
80
|
+
'Content-Type': 'application/json',
|
|
81
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TokenizeCardConnectGooglePayResult, GooglePayConfig } from './types';
|
|
2
|
+
export default class GooglePay {
|
|
3
|
+
private static resolveLib;
|
|
4
|
+
static injectScript(): void;
|
|
5
|
+
private baseRequest;
|
|
6
|
+
private baseCardPaymentMethod;
|
|
7
|
+
private transactionInfo;
|
|
8
|
+
private tokenizationSpecification;
|
|
9
|
+
private googlePayOptions;
|
|
10
|
+
private readonly paymentRequestDefaults;
|
|
11
|
+
private paymentRequest;
|
|
12
|
+
paymentsClient: google.payments.api.PaymentsClient | null;
|
|
13
|
+
constructor(googlePayConfig: GooglePayConfig);
|
|
14
|
+
getGoogleIsReadyToPayRequest(): google.payments.api.IsReadyToPayRequest;
|
|
15
|
+
getGooglePaymentClient(): Promise<google.payments.api.PaymentsClient>;
|
|
16
|
+
onGooglePaymentButtonClicked(transactionInfoUpdate: Partial<google.payments.api.TransactionInfo>): Promise<google.payments.api.PaymentData>;
|
|
17
|
+
tokenizeWithCardConnect(paymentToken: string, cardConnectBaseUrl: string): Promise<TokenizeCardConnectGooglePayResult>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export default class GooglePay {
|
|
2
|
+
static resolveLib(options) {
|
|
3
|
+
const startWait = new Date();
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
function poll() {
|
|
6
|
+
if (window.google !== undefined &&
|
|
7
|
+
window.google.payments !== undefined) {
|
|
8
|
+
const paymentsClient = new google.payments.api.PaymentsClient(options);
|
|
9
|
+
resolve(paymentsClient);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
const elapsedMs = new Date().valueOf() - startWait.valueOf();
|
|
13
|
+
if (elapsedMs > 15000) {
|
|
14
|
+
reject(new Error('pay.js not loaded after 15 seconds'));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
setTimeout(poll, 250);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
poll();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static injectScript() {
|
|
25
|
+
if (window.google !== undefined && window.google.payments !== undefined) {
|
|
26
|
+
throw new Error('google payments is already injected');
|
|
27
|
+
}
|
|
28
|
+
const script = document.createElement('script');
|
|
29
|
+
script.src = 'https://pay.google.com/gp/p/js/pay.js?render=explicit';
|
|
30
|
+
script.async = true;
|
|
31
|
+
script.defer = true;
|
|
32
|
+
document.body.appendChild(script);
|
|
33
|
+
}
|
|
34
|
+
constructor(googlePayConfig) {
|
|
35
|
+
this.baseRequest = {
|
|
36
|
+
apiVersion: 2,
|
|
37
|
+
apiVersionMinor: 0,
|
|
38
|
+
};
|
|
39
|
+
this.baseCardPaymentMethod = {
|
|
40
|
+
type: 'CARD',
|
|
41
|
+
parameters: {
|
|
42
|
+
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
|
|
43
|
+
allowedCardNetworks: [
|
|
44
|
+
'AMEX',
|
|
45
|
+
'DISCOVER',
|
|
46
|
+
'INTERAC',
|
|
47
|
+
'JCB',
|
|
48
|
+
'MASTERCARD',
|
|
49
|
+
'VISA',
|
|
50
|
+
],
|
|
51
|
+
billingAddressRequired: true,
|
|
52
|
+
billingAddressParameters: {
|
|
53
|
+
format: 'FULL',
|
|
54
|
+
phoneNumberRequired: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
this.transactionInfo = {
|
|
59
|
+
countryCode: 'US',
|
|
60
|
+
currencyCode: 'USD',
|
|
61
|
+
totalPriceStatus: 'FINAL',
|
|
62
|
+
totalPrice: '',
|
|
63
|
+
};
|
|
64
|
+
this.tokenizationSpecification = {
|
|
65
|
+
type: 'PAYMENT_GATEWAY',
|
|
66
|
+
parameters: {
|
|
67
|
+
gateway: 'cardconnect',
|
|
68
|
+
gatewayMerchantId: '',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
this.googlePayOptions = {
|
|
72
|
+
environment: 'PRODUCTION',
|
|
73
|
+
};
|
|
74
|
+
this.paymentRequestDefaults = Object.assign(Object.assign({}, this.baseRequest), { merchantInfo: {
|
|
75
|
+
merchantId: '',
|
|
76
|
+
}, transactionInfo: this.transactionInfo, emailRequired: true, allowedPaymentMethods: [
|
|
77
|
+
Object.assign(Object.assign({}, this.baseCardPaymentMethod), { tokenizationSpecification: this.tokenizationSpecification }),
|
|
78
|
+
] });
|
|
79
|
+
this.paymentsClient = null;
|
|
80
|
+
const { paymentOptions, cardConnectMerchantId, paymentDataRequest, baseCardPaymentMethodParameters = {}, } = googlePayConfig;
|
|
81
|
+
this.tokenizationSpecification.parameters.gatewayMerchantId =
|
|
82
|
+
cardConnectMerchantId;
|
|
83
|
+
this.paymentRequest = Object.assign({}, this.paymentRequestDefaults, paymentDataRequest);
|
|
84
|
+
this.googlePayOptions = Object.assign({}, this.googlePayOptions, Object.assign(Object.assign({}, paymentOptions), { merchantInfo: this.paymentRequest.merchantInfo }));
|
|
85
|
+
this.baseCardPaymentMethod.parameters = Object.assign(Object.assign({}, this.baseCardPaymentMethod.parameters), baseCardPaymentMethodParameters);
|
|
86
|
+
}
|
|
87
|
+
getGoogleIsReadyToPayRequest() {
|
|
88
|
+
return Object.assign({}, this.baseRequest, {
|
|
89
|
+
allowedPaymentMethods: [this.baseCardPaymentMethod],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
getGooglePaymentClient() {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
if (!this.paymentsClient) {
|
|
95
|
+
GooglePay.resolveLib(this.googlePayOptions)
|
|
96
|
+
.then((client) => {
|
|
97
|
+
this.paymentsClient = client;
|
|
98
|
+
resolve(client);
|
|
99
|
+
})
|
|
100
|
+
.catch((err) => reject(err));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
resolve(this.paymentsClient);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
onGooglePaymentButtonClicked(transactionInfoUpdate) {
|
|
108
|
+
const paymentDataRequest = this.paymentRequest;
|
|
109
|
+
this.transactionInfo = Object.assign({}, this.transactionInfo, transactionInfoUpdate);
|
|
110
|
+
paymentDataRequest.transactionInfo = this.transactionInfo;
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
if (!this.paymentsClient) {
|
|
113
|
+
reject(new Error('PaymentClient is not initialized'));
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.paymentsClient
|
|
117
|
+
.loadPaymentData(paymentDataRequest)
|
|
118
|
+
.then((paymentData) => {
|
|
119
|
+
resolve(paymentData);
|
|
120
|
+
})
|
|
121
|
+
.catch((err) => {
|
|
122
|
+
reject(err);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
tokenizeWithCardConnect(paymentToken, cardConnectBaseUrl) {
|
|
128
|
+
return fetch(`${cardConnectBaseUrl}/cardsecure/api/v1/ccn/tokenize`, {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
headers: {
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
},
|
|
133
|
+
body: JSON.stringify({
|
|
134
|
+
encryptionhandler: 'EC_GOOGLE_PAY',
|
|
135
|
+
devicedata: paymentToken,
|
|
136
|
+
unique: true,
|
|
137
|
+
}),
|
|
138
|
+
}).then((response) => response.json());
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ClientOptions, Contact, Address, CreatePaymentMethodRequest, CreatePaymentMethodResult, CreateDonationRequest, CreateDonationResult, TokenizeApplePayResult } from './types';
|
|
2
|
+
import ConfigHandler from './config-handler';
|
|
3
|
+
import { Tokenizer, PaymentMethodType, PaymentGateway, TokenizerContainer } from './tokenize';
|
|
4
|
+
export default class iDonateClient {
|
|
5
|
+
private readonly clientKey;
|
|
6
|
+
private readonly embedId;
|
|
7
|
+
private currentOrganizationId;
|
|
8
|
+
private allowTransaction;
|
|
9
|
+
get organizationId(): string;
|
|
10
|
+
readonly options: ClientOptions;
|
|
11
|
+
readonly config: ConfigHandler;
|
|
12
|
+
constructor(clientKey: string, embedId: string, options?: Partial<ClientOptions>);
|
|
13
|
+
createDonation(donation: CreateDonationRequest): Promise<CreateDonationResult>;
|
|
14
|
+
createTransaction(donation: CreateDonationRequest): Promise<{
|
|
15
|
+
transactionId: string | undefined;
|
|
16
|
+
_raw_response: any;
|
|
17
|
+
}>;
|
|
18
|
+
createPaymentMethod(paymentMethod: CreatePaymentMethodRequest): Promise<CreatePaymentMethodResult>;
|
|
19
|
+
setOrganizationId(organizationId: string): void;
|
|
20
|
+
waitForDonationResult(donationId: string, afterEachCheck?: () => void): Promise<any>;
|
|
21
|
+
tokenizeCardConnectApplePay(applePayRequest: Partial<ApplePayJS.ApplePayPaymentRequest>): Promise<TokenizeApplePayResult>;
|
|
22
|
+
createTokenizer(gateway: PaymentGateway, container: TokenizerContainer): Promise<Tokenizer>;
|
|
23
|
+
tokenizeSpreedlyPayPal(data: {
|
|
24
|
+
contact: Contact;
|
|
25
|
+
address: Address;
|
|
26
|
+
}): Promise<string>;
|
|
27
|
+
selectGateway(availableGateways: PaymentGateway[], paymentType: PaymentMethodType, preferredGatewayId?: string): PaymentGateway | undefined;
|
|
28
|
+
}
|