@fat-zebra/sdk 1.5.6 → 1.5.7-beta.0
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/.idea/fatzebra-js.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/dist/applepay/applepaymanager.d.ts +28 -0
- package/dist/applepay/applepaymanager.js +115 -0
- package/dist/click_to_pay/index.js +5 -3
- package/dist/hpp/hpp.d.ts +4 -0
- package/dist/hpp/hpp.js +26 -6
- package/dist/local/fatzebra.js +19684 -0
- package/dist/local/fatzebra.js.map +1 -1
- package/dist/main.js +3 -3
- package/dist/production/fatzebra.css +91 -0
- package/dist/production/fatzebra.js +2 -0
- package/dist/react/ApplePay.d.ts +9 -0
- package/dist/react/ApplePay.js +11 -0
- package/dist/react/{url.d.ts → applePayUrl.d.ts} +2 -2
- package/dist/react/applePayUrl.js +19 -0
- package/dist/sandbox/fatzebra.js +1 -1
- package/dist/sandbox/fatzebra.js.LICENSE.txt +1 -1
- package/dist/sca/cardinal.d.ts +2 -11
- package/dist/sca/cardinal.js +4 -10
- package/dist/sca/index.d.ts +11 -1
- package/dist/sca/index.js +3 -40
- package/dist/sca/scenarios/enrollment.js +14 -2
- package/dist/sca/scenarios/validation.js +3 -3
- package/dist/sca/types/cardinal_types.d.ts +61 -0
- package/dist/sca/types/cardinal_types.js +11 -0
- package/dist/sca/types.d.ts +2 -1
- package/dist/sca/types.js +1 -0
- package/dist/sca/utility/index.d.ts +7 -0
- package/dist/sca/utility/index.js +39 -0
- package/dist/shared/bridge-client.d.ts +5 -1
- package/dist/shared/bridge-client.js +19 -1
- package/dist/shared/envs/local.d.ts +1 -1
- package/dist/shared/envs/local.js +1 -1
- package/dist/shared/types.d.ts +5 -15
- package/dist/shared/types.js +2 -2
- package/dist/src/applepay/applepaymanager.js +279 -0
- package/dist/src/applepay/applepaymanager.js.map +1 -0
- package/dist/src/react/ApplePayButton.js +56 -0
- package/dist/src/react/ApplePayButton.js.map +1 -0
- package/dist/src/react/{url.js → applePayUrl.js} +7 -21
- package/dist/src/react/applePayUrl.js.map +1 -0
- package/dist/src/react/applePayUrl.test.js +57 -0
- package/dist/src/react/applePayUrl.test.js.map +1 -0
- package/dist/src/react/useFatZebra.js +7 -56
- package/dist/src/react/useFatZebra.js.map +1 -1
- package/dist/src/react/useMessage.js +140 -0
- package/dist/src/react/useMessage.js.map +1 -0
- package/dist/src/react/useMessage.test.js +222 -0
- package/dist/src/react/useMessage.test.js.map +1 -0
- package/dist/src/validation/validators/apple-pay-load-params-button-validator.js +19 -0
- package/dist/src/validation/validators/apple-pay-load-params-button-validator.js.map +1 -0
- package/dist/staging/fatzebra.css +91 -0
- package/dist/staging/fatzebra.js +19684 -0
- package/dist/staging/fatzebra.js.map +1 -0
- package/dist/staging/index.html +247 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/tsconfig.json +1 -1
- package/dist/paypal/paypal-button.d.ts +0 -31
- package/dist/paypal/paypal-button.js +0 -199
- package/dist/paypal/paypal-checkout.d.ts +0 -21
- package/dist/paypal/paypal-checkout.js +0 -100
- package/dist/paypal/types.d.ts +0 -188
- package/dist/paypal/types.js +0 -5
- package/dist/paypal/validation.d.ts +0 -4
- package/dist/paypal/validation.js +0 -65
- package/dist/react/url.js +0 -33
- package/dist/src/paypal/paypal-button.js +0 -311
- package/dist/src/paypal/paypal-button.js.map +0 -1
- package/dist/src/paypal/paypal-button.test.js +0 -41
- package/dist/src/paypal/paypal-button.test.js.map +0 -1
- package/dist/src/paypal/paypal-checkout.js +0 -111
- package/dist/src/paypal/paypal-checkout.js.map +0 -1
- package/dist/src/paypal/paypal-checkout.test.js +0 -167
- package/dist/src/paypal/paypal-checkout.test.js.map +0 -1
- package/dist/src/paypal/types.js +0 -9
- package/dist/src/paypal/types.js.map +0 -1
- package/dist/src/paypal/validation.js +0 -73
- package/dist/src/paypal/validation.js.map +0 -1
- package/dist/src/react/url.js.map +0 -1
- package/dist/src/react/url.test.js +0 -88
- package/dist/src/react/url.test.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/fatzebra-js.iml" filepath="$PROJECT_DIR$/.idea/fatzebra-js.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PaymentRequest } from './clients/apple-pay-client';
|
|
2
|
+
import * as payNow from './clients/paynow-client';
|
|
3
|
+
import { PostMessage } from '../shared/post-message-client';
|
|
4
|
+
declare class ApplePayManager {
|
|
5
|
+
private merchantId;
|
|
6
|
+
private canMakePayments;
|
|
7
|
+
private iframe;
|
|
8
|
+
private applePaySession;
|
|
9
|
+
private postMessageClient;
|
|
10
|
+
private fzPayNowDomain;
|
|
11
|
+
private username?;
|
|
12
|
+
private token?;
|
|
13
|
+
constructor(config: {
|
|
14
|
+
iframe: HTMLIFrameElement;
|
|
15
|
+
fzPayNowDomain: string;
|
|
16
|
+
username?: string;
|
|
17
|
+
token?: string;
|
|
18
|
+
});
|
|
19
|
+
initialize(): Promise<void>;
|
|
20
|
+
checkApplePayEligibility(): void;
|
|
21
|
+
notifyApplePayEligibility(): void;
|
|
22
|
+
registerEventListener(): Promise<void>;
|
|
23
|
+
purchase(request: PaymentRequest): Promise<void>;
|
|
24
|
+
extractApplePaymentRequestParams(payload: any): PaymentRequest;
|
|
25
|
+
extractPayNowPaymentAttributes(payload: any): payNow.PaymentAttributes;
|
|
26
|
+
sendMessage(payload: PostMessage): void;
|
|
27
|
+
}
|
|
28
|
+
export default ApplePayManager;
|
|
@@ -0,0 +1,115 @@
|
|
|
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 { createSession, getEligibilty, } from './clients/apple-pay-client';
|
|
11
|
+
import * as payNow from './clients/paynow-client';
|
|
12
|
+
import { PostMessageClient } from '../shared/post-message-client';
|
|
13
|
+
// import * as process from "process";
|
|
14
|
+
const channel = 'applepay';
|
|
15
|
+
// const fzPayNowDomain = process.env.PAYNOW_BASE_URL
|
|
16
|
+
// do the domain handling stuff better
|
|
17
|
+
const paynowDomain = 'https://paynow.test';
|
|
18
|
+
const merchantSessionPath = '/v2/apple_pay/payment_session';
|
|
19
|
+
const purchaseTokenPath = '/v2/apple_pay/token';
|
|
20
|
+
class ApplePayManager {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
// if (!config.fzPayNowDomain) {
|
|
23
|
+
// console.log('hitting i here')
|
|
24
|
+
// this.fzPayNowDomain = process?.env?.PAYNOW_BASE_URL;
|
|
25
|
+
// } else {
|
|
26
|
+
this.fzPayNowDomain = config.fzPayNowDomain;
|
|
27
|
+
this.username = config.username;
|
|
28
|
+
this.token = config.token;
|
|
29
|
+
// }
|
|
30
|
+
this.iframe = config.iframe;
|
|
31
|
+
this.postMessageClient = new PostMessageClient({
|
|
32
|
+
channel: 'applepay',
|
|
33
|
+
target: this.iframe
|
|
34
|
+
});
|
|
35
|
+
this.initialize();
|
|
36
|
+
}
|
|
37
|
+
initialize() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
yield this.registerEventListener();
|
|
40
|
+
this.checkApplePayEligibility();
|
|
41
|
+
this.notifyApplePayEligibility();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
checkApplePayEligibility() {
|
|
45
|
+
if (getEligibilty()) {
|
|
46
|
+
this.canMakePayments = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
notifyApplePayEligibility() {
|
|
50
|
+
const message = {
|
|
51
|
+
channel,
|
|
52
|
+
subject: 'eligibility',
|
|
53
|
+
data: {
|
|
54
|
+
canMakePayments: this.canMakePayments
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.postMessageClient.send(message);
|
|
58
|
+
}
|
|
59
|
+
registerEventListener() {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
this.postMessageClient.setEventListeners({
|
|
62
|
+
'paymentrequest': (data) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
yield this.purchase(data);
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
resolve();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
purchase(request) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const applePayPaymentRequest = this.extractApplePaymentRequestParams(request);
|
|
72
|
+
const payNowPaymentAttributes = this.extractPayNowPaymentAttributes(request);
|
|
73
|
+
this.applePaySession = yield createSession(applePayPaymentRequest);
|
|
74
|
+
this.applePaySession.onvalidatemerchant = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
let merchantSession;
|
|
76
|
+
try {
|
|
77
|
+
merchantSession = yield payNow.getMerchantSession(event.validationURL, Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, domain_name: window.location.hostname, display_name: this.username }), `${paynowDomain}${merchantSessionPath}`, this.username, this.token);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
console.log('Unable to establish new merchant session');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.applePaySession.completeMerchantValidation(merchantSession);
|
|
84
|
+
});
|
|
85
|
+
this.applePaySession.onpaymentauthorized = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
try {
|
|
87
|
+
yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, token: event.payment.token }), `${paynowDomain}${purchaseTokenPath}`);
|
|
88
|
+
this.applePaySession.completePayment(window.ApplePaySession.STATUS_SUCCESS);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
this.applePaySession.completePayment(window.ApplePaySession.STATUS_FAILURE);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
this.applePaySession.begin();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
extractApplePaymentRequestParams(payload) {
|
|
98
|
+
const { countryCode, currencyCode, merchantCapabilities, supportedNetworks, total, } = payload;
|
|
99
|
+
return {
|
|
100
|
+
countryCode,
|
|
101
|
+
currencyCode,
|
|
102
|
+
merchantCapabilities,
|
|
103
|
+
supportedNetworks,
|
|
104
|
+
total,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
extractPayNowPaymentAttributes(payload) {
|
|
108
|
+
const { paymentAttributes } = payload;
|
|
109
|
+
return paymentAttributes;
|
|
110
|
+
}
|
|
111
|
+
sendMessage(payload) {
|
|
112
|
+
this.iframe.contentWindow.postMessage(payload, this.fzPayNowDomain);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export default ApplePayManager;
|
|
@@ -6,14 +6,15 @@ export const CLICK_TO_PAY_DEFAULT_OPTIONS = {
|
|
|
6
6
|
iframe: true,
|
|
7
7
|
postmessage: true,
|
|
8
8
|
};
|
|
9
|
+
const OPTIONS_EXCLUDED_FROM_URL_PARAMS = ["mrt"];
|
|
9
10
|
class ClickToPay {
|
|
10
11
|
constructor(config) {
|
|
11
12
|
this.addMRTListener = (mrt) => {
|
|
12
13
|
const handlers = {};
|
|
13
|
-
handlers[
|
|
14
|
+
handlers[PublicEvent.CLICK_TO_PAY_INITIAL_MRT_REQUEST] = (data) => {
|
|
14
15
|
const message = {
|
|
15
16
|
channel: Channel.CLICK_TO_PAY,
|
|
16
|
-
subject:
|
|
17
|
+
subject: PublicEvent.CLICK_TO_PAY_INITIAL_MRT_RESPONSE,
|
|
17
18
|
data: {
|
|
18
19
|
mrt
|
|
19
20
|
},
|
|
@@ -30,7 +31,8 @@ class ClickToPay {
|
|
|
30
31
|
this.options = config.options;
|
|
31
32
|
this.iframe = document.createElement('iframe');
|
|
32
33
|
document.getElementById(config.containerId).appendChild(this.iframe);
|
|
33
|
-
const
|
|
34
|
+
const urlParams = Object.fromEntries(Object.entries(config.options).filter(([key]) => !OPTIONS_EXCLUDED_FROM_URL_PARAMS.includes(key)));
|
|
35
|
+
const payNowUrl = this.getPayNowUrl(urlParams);
|
|
34
36
|
this.iframe.setAttribute("src", payNowUrl);
|
|
35
37
|
this.postMessageClient = new PostMessageClient({
|
|
36
38
|
channel: Channel.CLICK_TO_PAY,
|
package/dist/hpp/hpp.d.ts
CHANGED
|
@@ -46,7 +46,11 @@ declare class Hpp {
|
|
|
46
46
|
private postMessageClient;
|
|
47
47
|
private test;
|
|
48
48
|
private hppOptions;
|
|
49
|
+
private headlessLoaded;
|
|
50
|
+
private headlessPreviouslyLoaded;
|
|
51
|
+
private iframeLoaded;
|
|
49
52
|
constructor(config: HppModuleConfig);
|
|
53
|
+
setListenersAndEmitReady(): void;
|
|
50
54
|
load(config: HppLoadParams): void;
|
|
51
55
|
purchase(): void;
|
|
52
56
|
getPayNowUrl(options?: {
|
package/dist/hpp/hpp.js
CHANGED
|
@@ -17,25 +17,45 @@ class Hpp {
|
|
|
17
17
|
this.sca = config.sca;
|
|
18
18
|
this.test = config.test;
|
|
19
19
|
this.version = config.version || 2;
|
|
20
|
+
this.headlessLoaded = false;
|
|
21
|
+
this.headlessPreviouslyLoaded = false;
|
|
22
|
+
this.iframeLoaded = false;
|
|
20
23
|
this.postMessageClient = new PostMessageClient({
|
|
21
24
|
channel: 'sca',
|
|
22
25
|
target: this.iframe
|
|
23
26
|
});
|
|
24
27
|
}
|
|
28
|
+
setListenersAndEmitReady() {
|
|
29
|
+
if (this.headlessLoaded && this.iframeLoaded) {
|
|
30
|
+
// initial headless load
|
|
31
|
+
this.setCrossFramesEventListeners();
|
|
32
|
+
this.setPublicEventListeners();
|
|
33
|
+
emit(PublicEvent.HPP_READY);
|
|
34
|
+
}
|
|
35
|
+
else if (this.headlessPreviouslyLoaded && this.iframeLoaded) {
|
|
36
|
+
// subsequent iframe loads after headless has been previously loaded
|
|
37
|
+
// this caters for the SPA scenario
|
|
38
|
+
emit(PublicEvent.HPP_READY);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
25
41
|
load(config) {
|
|
26
42
|
this.hppOptions = config.options;
|
|
27
|
-
|
|
43
|
+
const { el, isExisting } = bridge.load2(process.env.PAYNOW_BRIDGE_URL);
|
|
44
|
+
this.headless = el;
|
|
45
|
+
this.headlessPreviouslyLoaded = isExisting;
|
|
28
46
|
this.iframe = document.createElement('iframe');
|
|
29
47
|
document.getElementById(config.containerId).appendChild(this.iframe);
|
|
30
48
|
this.headless.onload = () => {
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
this.headlessLoaded = true;
|
|
50
|
+
this.setListenersAndEmitReady();
|
|
51
|
+
};
|
|
52
|
+
this.iframe.onload = () => {
|
|
53
|
+
this.iframeLoaded = true;
|
|
54
|
+
this.setListenersAndEmitReady();
|
|
36
55
|
};
|
|
37
56
|
const payNowUrl = this.getPayNowUrl(config.options);
|
|
38
57
|
this.iframe.setAttribute("src", payNowUrl);
|
|
58
|
+
this.iframe.setAttribute('allow', 'payment');
|
|
39
59
|
}
|
|
40
60
|
purchase() {
|
|
41
61
|
const message = {
|