@fat-zebra/sdk 1.5.5-beta.0 → 1.5.6
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/applepay/applepay.js +10 -0
- package/dist/applepay/clients/apple-pay-client.js +1 -1
- package/dist/click_to_pay/index.d.ts +1 -0
- package/dist/click_to_pay/index.js +27 -5
- package/dist/click_to_pay/types.d.ts +1 -0
- package/dist/hpp/hpp.js +1 -0
- package/dist/local/fatzebra.js.map +1 -1
- package/dist/main.js +3 -3
- package/dist/paypal/paypal-button.d.ts +31 -0
- package/dist/paypal/paypal-button.js +199 -0
- package/dist/paypal/paypal-checkout.d.ts +21 -0
- package/dist/paypal/paypal-checkout.js +100 -0
- package/dist/paypal/types.d.ts +188 -0
- package/dist/paypal/types.js +5 -0
- package/dist/paypal/validation.d.ts +4 -0
- package/dist/paypal/validation.js +65 -0
- package/dist/react/{applePayUrl.d.ts → url.d.ts} +2 -2
- package/dist/react/url.js +33 -0
- package/dist/sandbox/fatzebra.js +1 -1
- package/dist/sandbox/fatzebra.js.LICENSE.txt +1 -1
- package/dist/sca/index.js +4 -2
- package/dist/sca/scenarios/enrollment.js +2 -2
- package/dist/sca/scenarios/validation.js +3 -3
- package/dist/sca/types.d.ts +2 -0
- package/dist/shared/event-manager.d.ts +1 -1
- package/dist/shared/types.d.ts +16 -3
- package/dist/shared/types.js +9 -1
- package/dist/src/paypal/paypal-button.js +311 -0
- package/dist/src/paypal/paypal-button.js.map +1 -0
- package/dist/src/paypal/paypal-button.test.js +41 -0
- package/dist/src/paypal/paypal-button.test.js.map +1 -0
- package/dist/src/paypal/paypal-checkout.js +111 -0
- package/dist/src/paypal/paypal-checkout.js.map +1 -0
- package/dist/src/paypal/paypal-checkout.test.js +167 -0
- package/dist/src/paypal/paypal-checkout.test.js.map +1 -0
- package/dist/src/paypal/types.js +9 -0
- package/dist/src/paypal/types.js.map +1 -0
- package/dist/src/paypal/validation.js +73 -0
- package/dist/src/paypal/validation.js.map +1 -0
- package/dist/src/react/{applePayUrl.js → url.js} +21 -7
- package/dist/src/react/url.js.map +1 -0
- package/dist/src/react/url.test.js +88 -0
- package/dist/src/react/url.test.js.map +1 -0
- package/dist/src/react/useFatZebra.js +56 -7
- package/dist/src/react/useFatZebra.js.map +1 -1
- package/dist/validation/schemas/applepay/options.json +73 -0
- package/dist/validation/schemas/click-to-pay/options.json +3 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
- package/.idea/fatzebra-js.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/applepay/applepaymanager.d.ts +0 -28
- package/dist/applepay/applepaymanager.js +0 -115
- package/dist/local/fatzebra.js +0 -19565
- package/dist/production/fatzebra.css +0 -91
- package/dist/production/fatzebra.js +0 -2
- package/dist/react/ApplePay.d.ts +0 -9
- package/dist/react/ApplePay.js +0 -11
- package/dist/react/applePayUrl.js +0 -19
- package/dist/src/applepay/applepaymanager.js +0 -279
- package/dist/src/applepay/applepaymanager.js.map +0 -1
- package/dist/src/react/ApplePayButton.js +0 -56
- package/dist/src/react/ApplePayButton.js.map +0 -1
- package/dist/src/react/applePayUrl.js.map +0 -1
- package/dist/src/react/applePayUrl.test.js +0 -57
- package/dist/src/react/applePayUrl.test.js.map +0 -1
- package/dist/src/react/useMessage.js +0 -140
- package/dist/src/react/useMessage.js.map +0 -1
- package/dist/src/react/useMessage.test.js +0 -222
- package/dist/src/react/useMessage.test.js.map +0 -1
- package/dist/src/validation/validators/apple-pay-load-params-button-validator.js +0 -19
- package/dist/src/validation/validators/apple-pay-load-params-button-validator.js.map +0 -1
- package/dist/staging/fatzebra.css +0 -91
- package/dist/staging/fatzebra.js +0 -19565
- package/dist/staging/fatzebra.js.map +0 -1
- package/dist/staging/index.html +0 -247
|
@@ -1 +1 @@
|
|
|
1
|
-
/** @license URI.js v4.
|
|
1
|
+
/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
|
package/dist/sca/index.js
CHANGED
|
@@ -93,8 +93,8 @@ class Sca {
|
|
|
93
93
|
this._cardinal.setup(cardinalJwt);
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
-
perform3DS(
|
|
97
|
-
return __awaiter(this,
|
|
96
|
+
perform3DS(_a) {
|
|
97
|
+
return __awaiter(this, arguments, void 0, function* ({ sessionID }) {
|
|
98
98
|
this.sessionId = sessionID;
|
|
99
99
|
// Register handler. Called after OTP is entered on challenge prompt.
|
|
100
100
|
this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -178,6 +178,8 @@ class Sca {
|
|
|
178
178
|
session_id: this.sessionId,
|
|
179
179
|
challenge_window_size: this.challengeWindowSize,
|
|
180
180
|
hide_card_holder: this.paymentIntent.payment.hide_card_holder,
|
|
181
|
+
screen_height: window.screen.height,
|
|
182
|
+
screen_width: window.screen.width,
|
|
181
183
|
customer: this.customerProperties(this.customer),
|
|
182
184
|
})).data;
|
|
183
185
|
});
|
|
@@ -21,7 +21,7 @@ const enrollmentScenarios = [
|
|
|
21
21
|
veresEnrolled: VEResEnrolled.BYPASSED,
|
|
22
22
|
pares: null,
|
|
23
23
|
outcome: {
|
|
24
|
-
success: false,
|
|
24
|
+
success: false, // no liability shift
|
|
25
25
|
authenticationType: 'bypass',
|
|
26
26
|
errorCode: ScaErrorCode.BYPASSED_AUTHENTICATION
|
|
27
27
|
},
|
|
@@ -34,7 +34,7 @@ const enrollmentScenarios = [
|
|
|
34
34
|
veresEnrolled: VEResEnrolled.UNABLE,
|
|
35
35
|
pares: null,
|
|
36
36
|
outcome: {
|
|
37
|
-
success: false,
|
|
37
|
+
success: false, // no liability shift
|
|
38
38
|
errorCode: ScaErrorCode.AUTHENTICATION_NOT_AVAILABLE_ON_LOOKUP
|
|
39
39
|
}
|
|
40
40
|
},
|
|
@@ -34,7 +34,7 @@ const validationScenarios = [
|
|
|
34
34
|
pares: PARes.CANCELED,
|
|
35
35
|
outcome: {
|
|
36
36
|
authenticationType: 'challenge',
|
|
37
|
-
success: false,
|
|
37
|
+
success: false, // no liability shift
|
|
38
38
|
errorCode: ScaErrorCode.UNSUCCESSFUL_STEPUP_AUTHENTICATION
|
|
39
39
|
}
|
|
40
40
|
},
|
|
@@ -47,7 +47,7 @@ const validationScenarios = [
|
|
|
47
47
|
pares: PARes.NOT_COMPLETED,
|
|
48
48
|
outcome: {
|
|
49
49
|
authenticationType: 'challenge',
|
|
50
|
-
success: false,
|
|
50
|
+
success: false, // no liability shift
|
|
51
51
|
errorCode: ScaErrorCode.UNAVAILABLE_STEPUP_AUTHENTICATION
|
|
52
52
|
}
|
|
53
53
|
},
|
|
@@ -126,7 +126,7 @@ const validationScenarios = [
|
|
|
126
126
|
pares: null,
|
|
127
127
|
outcome: {
|
|
128
128
|
authenticationType: 'challenge',
|
|
129
|
-
success: false,
|
|
129
|
+
success: false, // no liability shift
|
|
130
130
|
errorCode: ScaErrorCode.UNSUCCESSFUL_STEPUP_AUTHENTICATION
|
|
131
131
|
}
|
|
132
132
|
},
|
package/dist/sca/types.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ interface ErrorEventDetail {
|
|
|
23
23
|
errors: string[];
|
|
24
24
|
data: any;
|
|
25
25
|
}
|
|
26
|
-
declare const emit: (event: PublicEvent, data
|
|
26
|
+
declare const emit: (event: PublicEvent, data?: SuccessEventDetail | ErrorEventDetail, target?: HTMLElement | Window) => void;
|
|
27
27
|
declare const off: (event: PublicEvent, callback: (e: any) => void, target?: HTMLElement | Window) => void;
|
|
28
28
|
declare const onOnce: (event: PublicEvent, callback: (e: any) => void, target?: HTMLElement | Window) => void;
|
|
29
29
|
declare const on: (event: PublicEvent, callback: (e: any) => void, target?: HTMLElement | Window) => void;
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Environment } from './env';
|
|
2
2
|
import { MerchantCapability, SupportedNetwork } from "../applepay/clients/apple-pay-client";
|
|
3
|
+
declare enum Channel {
|
|
4
|
+
CLICK_TO_PAY = "click_to_pay"
|
|
5
|
+
}
|
|
3
6
|
declare enum PublicEvent {
|
|
7
|
+
HPP_READY = "fz.ready",
|
|
4
8
|
FORM_VALIDATION_ERROR = "fz.form_validation.error",
|
|
5
9
|
FORM_VALIDATION_SUCCESS = "fz.form_validation.success",
|
|
6
10
|
VALIDATION_ERROR = "fz.validation.error",
|
|
@@ -14,7 +18,8 @@ declare enum PublicEvent {
|
|
|
14
18
|
CLICK_TO_PAY_TOKENIZATION_SUCCESS = "fz.click_to_pay.tokenization.success",
|
|
15
19
|
CLICK_TO_PAY_TOKENIZATION_ERROR = "fz.click_to_pay.tokenization.error",
|
|
16
20
|
CLICK_TO_PAY_RESIZE = "fz.click_to_pay.resize",
|
|
17
|
-
CLICK_TO_PAY_DCF_LOADED = "fz.click_to_pay.dcf"
|
|
21
|
+
CLICK_TO_PAY_DCF_LOADED = "fz.click_to_pay.dcf",
|
|
22
|
+
CLICK_TO_PAY_MRT = "fz.click_to_pay.mrt"
|
|
18
23
|
}
|
|
19
24
|
declare enum BridgeEvent {
|
|
20
25
|
TOKENIZE_CARD_REQUEST = "fzi.tc_req",
|
|
@@ -25,7 +30,9 @@ declare enum BridgeEvent {
|
|
|
25
30
|
FORM_VALIDATION_ERROR = "fzi.form_validation_error",
|
|
26
31
|
FORM_VALIDATION_SUCCESS = "fzi.form_validation_success",
|
|
27
32
|
BIN_LOOKUP = "fzi.bin_lookup",
|
|
28
|
-
CLICK_TO_PAY_TOKENIZATION = "fzi.c2p.tc_res"
|
|
33
|
+
CLICK_TO_PAY_TOKENIZATION = "fzi.c2p.tc_res",
|
|
34
|
+
CLICK_TO_PAY_REQUEST_MRT = "fzi.c2p.mrt_req",
|
|
35
|
+
CLICK_TO_PAY_RETURN_MRT = "fzi.c2p.mrt_ret"
|
|
29
36
|
}
|
|
30
37
|
declare enum PaymentMethodType {
|
|
31
38
|
CARD = "card",
|
|
@@ -88,6 +95,9 @@ export type PaymentConfig = {
|
|
|
88
95
|
paymentIntent: PaymentIntent;
|
|
89
96
|
options: OptionalUrlValues;
|
|
90
97
|
};
|
|
98
|
+
export type ApplePayButtonType = 'buy' | 'donate' | 'plain' | 'set-up' | 'book' | 'check-out' | 'subscribe' | 'add-money' | 'contribute' | 'order' | 'reload' | 'rent' | 'support' | 'tip' | 'top-up' | 'continue';
|
|
99
|
+
export type ApplePayButtonStyle = 'black' | 'white' | 'white-outline';
|
|
100
|
+
export type ApplePayButtonLocale = 'ar-AB' | 'ca-ES' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'el-GR' | 'en-AU' | 'en-GB' | 'en-US' | 'es-ES' | 'es-MX' | 'fi-FI' | 'fr-CA' | 'fr-FR' | 'he-IL' | 'hi-IN' | 'hr-HR' | 'hu-HU' | 'id-ID' | 'it-IT' | 'ja-JP' | 'ko-KR' | 'ms-MY' | 'nb-NO' | 'nl-NL' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ro-RO' | 'ru-RU' | 'sk-SK' | 'sv-SE' | 'th-TH' | 'tr-TR' | 'uk-UA' | 'vi-VN' | 'zh-CN' | 'zh-HK' | 'zh-TW';
|
|
91
101
|
export type OptionalUrlValues = {
|
|
92
102
|
hide_card_holder?: boolean;
|
|
93
103
|
hide_button?: boolean;
|
|
@@ -101,6 +111,9 @@ export type OptionalUrlValues = {
|
|
|
101
111
|
css?: string;
|
|
102
112
|
css_signature?: string;
|
|
103
113
|
tokenize_only?: boolean;
|
|
114
|
+
apple_button_style?: ApplePayButtonStyle;
|
|
115
|
+
apple_button_type?: ApplePayButtonType;
|
|
116
|
+
apple_button_locale?: ApplePayButtonLocale;
|
|
104
117
|
};
|
|
105
118
|
declare global {
|
|
106
119
|
interface Window {
|
|
@@ -149,5 +162,5 @@ type ApplePayPaymentResponse = {
|
|
|
149
162
|
errors?: Array<string>;
|
|
150
163
|
data?: string;
|
|
151
164
|
};
|
|
152
|
-
export { BridgeEvent, PublicEvent, PaymentMethodType, };
|
|
165
|
+
export { Channel, BridgeEvent, PublicEvent, PaymentMethodType, };
|
|
153
166
|
export type { PaymentMethod, PaymentIntent, Payment, Card, CardOnFile, CustomerSnakeCase, Customer, Handlers, ValidationResult, TokenizeCardResponse, ApplePayPaymentResponse };
|
package/dist/shared/types.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
var Channel;
|
|
2
|
+
(function (Channel) {
|
|
3
|
+
Channel["CLICK_TO_PAY"] = "click_to_pay";
|
|
4
|
+
})(Channel || (Channel = {}));
|
|
1
5
|
var PublicEvent;
|
|
2
6
|
(function (PublicEvent) {
|
|
7
|
+
PublicEvent["HPP_READY"] = "fz.ready";
|
|
3
8
|
PublicEvent["FORM_VALIDATION_ERROR"] = "fz.form_validation.error";
|
|
4
9
|
PublicEvent["FORM_VALIDATION_SUCCESS"] = "fz.form_validation.success";
|
|
5
10
|
PublicEvent["VALIDATION_ERROR"] = "fz.validation.error";
|
|
@@ -14,6 +19,7 @@ var PublicEvent;
|
|
|
14
19
|
PublicEvent["CLICK_TO_PAY_TOKENIZATION_ERROR"] = "fz.click_to_pay.tokenization.error";
|
|
15
20
|
PublicEvent["CLICK_TO_PAY_RESIZE"] = "fz.click_to_pay.resize";
|
|
16
21
|
PublicEvent["CLICK_TO_PAY_DCF_LOADED"] = "fz.click_to_pay.dcf";
|
|
22
|
+
PublicEvent["CLICK_TO_PAY_MRT"] = "fz.click_to_pay.mrt";
|
|
17
23
|
})(PublicEvent || (PublicEvent = {}));
|
|
18
24
|
var BridgeEvent;
|
|
19
25
|
(function (BridgeEvent) {
|
|
@@ -26,10 +32,12 @@ var BridgeEvent;
|
|
|
26
32
|
BridgeEvent["FORM_VALIDATION_SUCCESS"] = "fzi.form_validation_success";
|
|
27
33
|
BridgeEvent["BIN_LOOKUP"] = "fzi.bin_lookup";
|
|
28
34
|
BridgeEvent["CLICK_TO_PAY_TOKENIZATION"] = "fzi.c2p.tc_res";
|
|
35
|
+
BridgeEvent["CLICK_TO_PAY_REQUEST_MRT"] = "fzi.c2p.mrt_req";
|
|
36
|
+
BridgeEvent["CLICK_TO_PAY_RETURN_MRT"] = "fzi.c2p.mrt_ret";
|
|
29
37
|
})(BridgeEvent || (BridgeEvent = {}));
|
|
30
38
|
var PaymentMethodType;
|
|
31
39
|
(function (PaymentMethodType) {
|
|
32
40
|
PaymentMethodType["CARD"] = "card";
|
|
33
41
|
PaymentMethodType["CARD_ON_FILE"] = "card_on_file";
|
|
34
42
|
})(PaymentMethodType || (PaymentMethodType = {}));
|
|
35
|
-
export { BridgeEvent, PublicEvent, PaymentMethodType, };
|
|
43
|
+
export { Channel, BridgeEvent, PublicEvent, PaymentMethodType, };
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.PayPalButton = void 0;
|
|
66
|
+
var event_manager_1 = require("../shared/event-manager");
|
|
67
|
+
var types_1 = require("./types");
|
|
68
|
+
var api_gateway_client_1 = __importDefault(require("../shared/api-gateway-client"));
|
|
69
|
+
var types_2 = require("../shared/types");
|
|
70
|
+
var util = __importStar(require("../shared/util"));
|
|
71
|
+
var constants_1 = require("../shared/constants");
|
|
72
|
+
var defaultStyle = {
|
|
73
|
+
layout: 'horizontal',
|
|
74
|
+
color: 'gold',
|
|
75
|
+
shape: 'pill',
|
|
76
|
+
label: 'paypal',
|
|
77
|
+
};
|
|
78
|
+
var PayPalButton = /** @class */ (function () {
|
|
79
|
+
function PayPalButton(paymentMethod, paymentIntent, billingAgreement, buttonStyle) {
|
|
80
|
+
this.paymentMethod = paymentMethod;
|
|
81
|
+
this.paymentIntent = paymentIntent;
|
|
82
|
+
this.billingAgreement = billingAgreement;
|
|
83
|
+
this.buttonStyle = buttonStyle;
|
|
84
|
+
this.client = new api_gateway_client_1.default({ accessToken: window.localStorage.getItem(constants_1.LocalStorageAccessTokenKey),
|
|
85
|
+
username: window.MerchantUsername,
|
|
86
|
+
});
|
|
87
|
+
this.createButton();
|
|
88
|
+
}
|
|
89
|
+
Object.defineProperty(PayPalButton.prototype, "paypalButtons", {
|
|
90
|
+
get: function () {
|
|
91
|
+
return this._paypalButtons;
|
|
92
|
+
},
|
|
93
|
+
enumerable: false,
|
|
94
|
+
configurable: true
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(PayPalButton.prototype, "paypalActions", {
|
|
97
|
+
get: function () {
|
|
98
|
+
return this.actions;
|
|
99
|
+
},
|
|
100
|
+
enumerable: false,
|
|
101
|
+
configurable: true
|
|
102
|
+
});
|
|
103
|
+
PayPalButton.prototype.render = function (containerId) {
|
|
104
|
+
var container = this.getContainer(containerId);
|
|
105
|
+
if (typeof (container) != 'undefined' && container != null) {
|
|
106
|
+
this._paypalButtons.render('#' + container.id);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_ERROR, {
|
|
110
|
+
errors: ["Container with id #".concat(containerId, " does not exist.")],
|
|
111
|
+
data: null
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
PayPalButton.prototype.getContainer = function (containerId) {
|
|
116
|
+
return document.getElementById(containerId);
|
|
117
|
+
};
|
|
118
|
+
PayPalButton.prototype.createButton = function () {
|
|
119
|
+
var _this = this;
|
|
120
|
+
var button = ({});
|
|
121
|
+
button.style = (this.buttonStyle ? this.buttonStyle : defaultStyle);
|
|
122
|
+
if (this.billingAgreement === true) {
|
|
123
|
+
button.createBillingAgreement = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
return [2 /*return*/, this.createBillingAgreement()];
|
|
126
|
+
});
|
|
127
|
+
}); };
|
|
128
|
+
button.onApprove = function (data, actions) { return __awaiter(_this, void 0, void 0, function () {
|
|
129
|
+
return __generator(this, function (_a) {
|
|
130
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_PROCESSESING, { data: {}, message: 'The request is being processed.' });
|
|
131
|
+
return [2 /*return*/, this.approveBillingAgreement(data)];
|
|
132
|
+
});
|
|
133
|
+
}); };
|
|
134
|
+
button.onCancel = function (data, actions) {
|
|
135
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_CANCEL, { data: { id: data.orderID }, message: 'PayPal Billing Agreement cancelled.' });
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
button.createOrder = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
return [2 /*return*/, this.createOrder()];
|
|
142
|
+
});
|
|
143
|
+
}); };
|
|
144
|
+
button.onApprove = function (data, actions) { return __awaiter(_this, void 0, void 0, function () {
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_PROCESSESING, { data: {}, message: 'The request is being processed.' });
|
|
147
|
+
return [2 /*return*/, this.approveOrder(data)];
|
|
148
|
+
});
|
|
149
|
+
}); };
|
|
150
|
+
button.onCancel = function (data, actions) {
|
|
151
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_CANCEL, { data: { id: data.orderID }, message: 'PayPal Order cancelled.' });
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
button.onError = function (error) {
|
|
155
|
+
// This flag is used to prevent emitting general error from PayPal
|
|
156
|
+
// if an error has already been raised and emitted.
|
|
157
|
+
if (_this.validationErrorRaised === false) {
|
|
158
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_ERROR, {
|
|
159
|
+
errors: ['PayPal Checkout failed.'],
|
|
160
|
+
data: null
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
this._paypalButtons = window.paypal.Buttons(button);
|
|
165
|
+
};
|
|
166
|
+
PayPalButton.prototype.createOrder = function () {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
+
var payload, response, error_1;
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
_a.trys.push([0, 2, , 3]);
|
|
173
|
+
this.validationErrorRaised = false;
|
|
174
|
+
payload = util.toObjectWithSnakeCaseKeys(this.paymentMethod);
|
|
175
|
+
payload.payment_intent = this.paymentIntent;
|
|
176
|
+
return [4 /*yield*/, this.client.createPayPalOrder({
|
|
177
|
+
order: payload
|
|
178
|
+
})];
|
|
179
|
+
case 1:
|
|
180
|
+
response = (_a.sent()).data;
|
|
181
|
+
return [2 /*return*/, response.id];
|
|
182
|
+
case 2:
|
|
183
|
+
error_1 = _a.sent();
|
|
184
|
+
this.validationErrorRaised = true;
|
|
185
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_ERROR, {
|
|
186
|
+
errors: this.formatError(error_1),
|
|
187
|
+
data: null
|
|
188
|
+
});
|
|
189
|
+
return [2 /*return*/, null];
|
|
190
|
+
case 3: return [2 /*return*/];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
PayPalButton.prototype.approveOrder = function (data) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
+
var response, error_2;
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
_a.trys.push([0, 5, , 6]);
|
|
202
|
+
this.validationErrorRaised = false;
|
|
203
|
+
response = undefined;
|
|
204
|
+
if (!(this.paymentMethod.intent.toUpperCase() === types_1.PayPalIntent.CAPTURE)) return [3 /*break*/, 2];
|
|
205
|
+
return [4 /*yield*/, this.client.capturePayPalOrder({
|
|
206
|
+
id: data.orderID
|
|
207
|
+
})];
|
|
208
|
+
case 1:
|
|
209
|
+
response = (_a.sent()).data;
|
|
210
|
+
return [3 /*break*/, 4];
|
|
211
|
+
case 2:
|
|
212
|
+
if (!(this.paymentMethod.intent.toUpperCase() === types_1.PayPalIntent.AUTHORIZE)) return [3 /*break*/, 4];
|
|
213
|
+
return [4 /*yield*/, this.client.authorizePayPalOrder({
|
|
214
|
+
id: data.orderID
|
|
215
|
+
})];
|
|
216
|
+
case 3:
|
|
217
|
+
response = (_a.sent()).data;
|
|
218
|
+
_a.label = 4;
|
|
219
|
+
case 4:
|
|
220
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_SUCCESS, {
|
|
221
|
+
data: util.toObjectWithCamelCaseKeys(response),
|
|
222
|
+
message: 'PayPal order approved.'
|
|
223
|
+
});
|
|
224
|
+
return [2 /*return*/];
|
|
225
|
+
case 5:
|
|
226
|
+
error_2 = _a.sent();
|
|
227
|
+
this.validationErrorRaised = true;
|
|
228
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_ERROR, {
|
|
229
|
+
errors: this.formatError(error_2),
|
|
230
|
+
data: null
|
|
231
|
+
});
|
|
232
|
+
return [2 /*return*/];
|
|
233
|
+
case 6: return [2 /*return*/];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
PayPalButton.prototype.createBillingAgreement = function () {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
240
|
+
var payload, response, error_3;
|
|
241
|
+
return __generator(this, function (_a) {
|
|
242
|
+
switch (_a.label) {
|
|
243
|
+
case 0:
|
|
244
|
+
_a.trys.push([0, 2, , 3]);
|
|
245
|
+
this.validationErrorRaised = false;
|
|
246
|
+
payload = util.toObjectWithSnakeCaseKeys(this.paymentMethod);
|
|
247
|
+
delete payload.billing_agreement;
|
|
248
|
+
return [4 /*yield*/, this.client.createPayPalBillingAgreement({
|
|
249
|
+
billing: payload
|
|
250
|
+
})];
|
|
251
|
+
case 1:
|
|
252
|
+
response = (_a.sent()).data;
|
|
253
|
+
return [2 /*return*/, response.token_id];
|
|
254
|
+
case 2:
|
|
255
|
+
error_3 = _a.sent();
|
|
256
|
+
this.validationErrorRaised = true;
|
|
257
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_ERROR, {
|
|
258
|
+
errors: this.formatError(error_3),
|
|
259
|
+
data: null
|
|
260
|
+
});
|
|
261
|
+
return [2 /*return*/];
|
|
262
|
+
case 3: return [2 /*return*/];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
PayPalButton.prototype.approveBillingAgreement = function (data) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
269
|
+
var response, error_4;
|
|
270
|
+
return __generator(this, function (_a) {
|
|
271
|
+
switch (_a.label) {
|
|
272
|
+
case 0:
|
|
273
|
+
_a.trys.push([0, 2, , 3]);
|
|
274
|
+
this.validationErrorRaised = false;
|
|
275
|
+
return [4 /*yield*/, this.client.approvePayPalBillingAgreement({
|
|
276
|
+
id: data.billingToken
|
|
277
|
+
})];
|
|
278
|
+
case 1:
|
|
279
|
+
response = (_a.sent()).data;
|
|
280
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_SUCCESS, {
|
|
281
|
+
data: util.toObjectWithCamelCaseKeys(response),
|
|
282
|
+
message: 'PayPal Billing Agreement created.'
|
|
283
|
+
});
|
|
284
|
+
return [2 /*return*/];
|
|
285
|
+
case 2:
|
|
286
|
+
error_4 = _a.sent();
|
|
287
|
+
this.validationErrorRaised = true;
|
|
288
|
+
(0, event_manager_1.emit)(types_2.PublicEvent.PAYPAL_ERROR, {
|
|
289
|
+
errors: this.formatError(error_4),
|
|
290
|
+
data: null
|
|
291
|
+
});
|
|
292
|
+
return [2 /*return*/];
|
|
293
|
+
case 3: return [2 /*return*/];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
PayPalButton.prototype.formatError = function (error) {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
var message = [(_b = (_a = error === null || error === void 0 ? void 0 : error.request) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.errors].flat();
|
|
301
|
+
if (typeof message[0] === 'undefined')
|
|
302
|
+
message = [error === null || error === void 0 ? void 0 : error.message].flat();
|
|
303
|
+
if (typeof message[0] === 'undefined')
|
|
304
|
+
message = ['Unknown error'];
|
|
305
|
+
return message;
|
|
306
|
+
};
|
|
307
|
+
return PayPalButton;
|
|
308
|
+
}());
|
|
309
|
+
exports.PayPalButton = PayPalButton;
|
|
310
|
+
exports.default = PayPalButton;
|
|
311
|
+
//# sourceMappingURL=paypal-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paypal-button.js","sourceRoot":"","sources":["../../../src/paypal/paypal-button.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA8C;AAE9C,iCASgB;AAEhB,oFAAwD;AACxD,yCAA4D;AAE5D,mDAAsC;AACtC,iDAAgE;AAoBhE,IAAM,YAAY,GAAG;IACnB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,QAAQ;CAChB,CAAA;AAED;IAUE,sBACE,aAAmC,EACnC,aAA6B,EAC7B,gBAA0B,EAC1B,WAA+B;QAE/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAG9B,IAAI,CAAC,MAAM,GAAG,IAAI,4BAAa,CAC7B,EAAE,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,sCAA0B,CAAC;YACpE,QAAQ,EAA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|
+
* @jest-environment jsdom
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var types_1 = require("../shared/types");
|
|
7
|
+
var paypal_button_1 = require("./paypal-button");
|
|
8
|
+
var eventManager = require('../../src/shared/event-manager');
|
|
9
|
+
eventManager.emit = jest.fn();
|
|
10
|
+
describe('PayPalButton', function () {
|
|
11
|
+
var instance;
|
|
12
|
+
beforeEach(function () {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
window.paypal = jest.fn();
|
|
15
|
+
window.paypal.Buttons = jest.fn().mockImplementation(function () {
|
|
16
|
+
return {
|
|
17
|
+
render: function () { return true; }
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
instance = new paypal_button_1.PayPalButton();
|
|
21
|
+
localStorage.setItem('x-fz-token', 'TOKEN');
|
|
22
|
+
});
|
|
23
|
+
describe('render()', function () {
|
|
24
|
+
it('should emit fz.paypal.error if container does not exist', function () {
|
|
25
|
+
instance.render('invalid-container-id');
|
|
26
|
+
var eventDetail = {
|
|
27
|
+
errors: ["Container with id #invalid-container-id does not exist."]
|
|
28
|
+
};
|
|
29
|
+
expect(eventManager.emit).toHaveBeenCalledTimes(1);
|
|
30
|
+
expect(eventManager.emit.mock.calls[0][0]).toBe(types_1.PublicEvent.PAYPAL_ERROR);
|
|
31
|
+
expect(eventManager.emit.mock.calls[0][1]).toMatchObject(eventDetail);
|
|
32
|
+
});
|
|
33
|
+
it('calls paypal.render()', function () {
|
|
34
|
+
instance.getContainer = jest.fn().mockReturnValue(Object);
|
|
35
|
+
var spy = jest.spyOn(instance.paypalButtons, 'render');
|
|
36
|
+
instance.render('containerID');
|
|
37
|
+
expect(spy).toHaveBeenCalled();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=paypal-button.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paypal-button.test.js","sourceRoot":"","s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