@fat-zebra/sdk 1.5.5 → 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.d.ts +22 -7
- package/dist/applepay/applepay.js +99 -21
- package/dist/applepay/clients/apple-pay-client.d.ts +9 -5
- package/dist/applepay/clients/apple-pay-client.js +10 -4
- package/dist/applepay/clients/paynow-client.d.ts +4 -2
- package/dist/applepay/clients/paynow-client.js +2 -7
- package/dist/applepay/types.d.ts +15 -0
- package/dist/applepay/types.js +1 -0
- package/dist/click_to_pay/index.d.ts +1 -0
- package/dist/click_to_pay/index.js +39 -5
- package/dist/click_to_pay/types.d.ts +12 -2
- package/dist/fatzebra.css +91 -0
- package/dist/hpp/hpp.js +1 -0
- package/dist/local/fatzebra.js.map +1 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.js +27 -5
- package/dist/react/ApplePayButton.d.ts +8 -0
- package/dist/react/ApplePayButton.js +18 -0
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/useFatZebra.js +8 -57
- package/dist/react/useMessage.d.ts +10 -0
- package/dist/react/useMessage.js +70 -0
- package/dist/sandbox/fatzebra.css +91 -0
- package/dist/sandbox/fatzebra.js +2 -0
- package/dist/sandbox/fatzebra.js.LICENSE.txt +1 -0
- 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/env.development.d.ts +3 -3
- package/dist/shared/env.development.js +3 -3
- package/dist/shared/envs/local.d.ts +3 -3
- package/dist/shared/envs/local.js +3 -3
- package/dist/shared/event-manager.d.ts +1 -1
- package/dist/shared/post-message-client.d.ts +2 -0
- package/dist/shared/post-message-client.js +1 -1
- package/dist/shared/types.d.ts +29 -4
- package/dist/shared/types.js +11 -1
- package/dist/validation/schemas/applepay/load-params.json +31 -0
- package/dist/validation/schemas/applepay/options.json +115 -0
- package/dist/validation/schemas/applepay/payment-intent.json +42 -0
- package/dist/validation/schemas/click-to-pay/options.json +33 -3
- package/dist/validation/validators/apple-pay-load-params-button-validator.d.ts +3 -0
- package/dist/validation/validators/apple-pay-load-params-button-validator.js +12 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -3
package/dist/main.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Customer, PaymentIntent, PaymentMethod, PublicEvent } from './shared/types';
|
|
2
2
|
import { HppLoadParams } from './hpp';
|
|
3
3
|
import { ChallengeWindowSize } from './sca/types';
|
|
4
|
+
import { ApplePayParams } from './applepay/types';
|
|
4
5
|
import { HppClickToPayParams } from './click_to_pay/types';
|
|
5
6
|
export interface FZConfig {
|
|
6
7
|
username: string;
|
|
@@ -31,6 +32,7 @@ export default class FatZebra {
|
|
|
31
32
|
cardDidTokenize(headless: HTMLIFrameElement, callback: (data: any) => void): void;
|
|
32
33
|
verifyCard(params: VerifyCardParams): Promise<void>;
|
|
33
34
|
renderPaymentsPage(params: HppLoadParams): void;
|
|
35
|
+
renderApplePayButton(params: ApplePayParams): void;
|
|
34
36
|
renderClickToPay(params: HppClickToPayParams): void;
|
|
35
37
|
checkout(): void;
|
|
36
38
|
on(event: PublicEvent, callback: (e: any) => void): void;
|
package/dist/main.js
CHANGED
|
@@ -11,12 +11,14 @@ import Sca from './sca';
|
|
|
11
11
|
import { PostMessageClient, } from './shared/post-message-client';
|
|
12
12
|
import { BridgeEvent, PaymentMethodType, PublicEvent, } from './shared/types';
|
|
13
13
|
import { LocalStorageAccessTokenKey } from './shared/constants';
|
|
14
|
-
import { emit,
|
|
14
|
+
import { emit, off, on, onOnce } from './shared/event-manager';
|
|
15
15
|
import * as bridge from './shared/bridge-client';
|
|
16
|
-
import {
|
|
16
|
+
import { toHumanizedErrors, validateClickToPayLoadParams, validateHppLoadParams, validateVerifyCardParams, } from './validation';
|
|
17
17
|
import GatewayClient from './shared/api-gateway-client';
|
|
18
18
|
import { Hpp } from './hpp';
|
|
19
19
|
import ClickToPay from './click_to_pay';
|
|
20
|
+
import { validateApplePayLoadParams } from "./validation/validators/apple-pay-load-params-button-validator";
|
|
21
|
+
import { ApplePay } from "./applepay";
|
|
20
22
|
export default class FatZebra {
|
|
21
23
|
constructor(config) {
|
|
22
24
|
this.fzConfig = config;
|
|
@@ -60,8 +62,8 @@ export default class FatZebra {
|
|
|
60
62
|
postMessageClient.setEventListeners(handlers);
|
|
61
63
|
}
|
|
62
64
|
verifyCard(params) {
|
|
63
|
-
var _a;
|
|
64
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a;
|
|
65
67
|
const valid = validateVerifyCardParams(params);
|
|
66
68
|
if (!valid) {
|
|
67
69
|
emit(PublicEvent.VALIDATION_ERROR, {
|
|
@@ -75,14 +77,14 @@ export default class FatZebra {
|
|
|
75
77
|
const headless = bridge.load(process.env.PAYNOW_BRIDGE_URL);
|
|
76
78
|
const card = params.paymentMethod.data;
|
|
77
79
|
this.cardDidTokenize(headless, (data) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
var
|
|
80
|
+
var _a;
|
|
79
81
|
const bin = card.number.substr(0, 6);
|
|
80
82
|
this.sca.run({
|
|
81
83
|
cardToken: data.token,
|
|
82
84
|
customer: params.customer,
|
|
83
85
|
paymentIntent: params.paymentIntent,
|
|
84
86
|
bin,
|
|
85
|
-
challengeWindowSize: (
|
|
87
|
+
challengeWindowSize: (_a = params.options) === null || _a === void 0 ? void 0 : _a.challengeWindowSize,
|
|
86
88
|
});
|
|
87
89
|
}));
|
|
88
90
|
this.tokenizeCard(card, headless);
|
|
@@ -120,6 +122,26 @@ export default class FatZebra {
|
|
|
120
122
|
});
|
|
121
123
|
window.HPP.load(params);
|
|
122
124
|
}
|
|
125
|
+
renderApplePayButton(params) {
|
|
126
|
+
const valid = validateApplePayLoadParams(params);
|
|
127
|
+
if (!valid) {
|
|
128
|
+
emit(PublicEvent.VALIDATION_ERROR, {
|
|
129
|
+
errors: toHumanizedErrors(validateApplePayLoadParams.errors),
|
|
130
|
+
data: null
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
window.ApplePayButton = new ApplePay({
|
|
135
|
+
environment: params.environment,
|
|
136
|
+
paymentIntent: params.paymentIntent,
|
|
137
|
+
username: this.fzConfig.username
|
|
138
|
+
});
|
|
139
|
+
window.ApplePayButton.load({
|
|
140
|
+
containerId: params.containerId,
|
|
141
|
+
paymentIntent: params.paymentIntent,
|
|
142
|
+
options: params.options
|
|
143
|
+
});
|
|
144
|
+
}
|
|
123
145
|
renderClickToPay(params) {
|
|
124
146
|
const valid = validateClickToPayLoadParams(params);
|
|
125
147
|
if (!valid) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as FatZebra from "../shared/types";
|
|
3
|
+
type FrameProps = {
|
|
4
|
+
handlers: FatZebra.Handlers;
|
|
5
|
+
config: FatZebra.PaymentConfig;
|
|
6
|
+
};
|
|
7
|
+
declare const ApplePayButton: ({ handlers, config }: FrameProps) => React.JSX.Element;
|
|
8
|
+
export default ApplePayButton;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { ApplePay } from "../applepay";
|
|
3
|
+
import useMessage from "./useMessage";
|
|
4
|
+
const ApplePayButton = ({ handlers, config }) => {
|
|
5
|
+
useMessage({
|
|
6
|
+
paymentIntent: config.paymentIntent,
|
|
7
|
+
handlers: handlers,
|
|
8
|
+
});
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
new ApplePay(config).load({
|
|
11
|
+
containerId: 'applePayButton',
|
|
12
|
+
paymentIntent: config.paymentIntent,
|
|
13
|
+
options: config.options
|
|
14
|
+
});
|
|
15
|
+
}, []);
|
|
16
|
+
return React.createElement("div", { id: "applePayButton", style: { height: '100%', width: '100%' } });
|
|
17
|
+
};
|
|
18
|
+
export default ApplePayButton;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import VerifyCard from "./VerifyCard";
|
|
2
2
|
import VerifyExistingCard from "./VerifyExistingCard";
|
|
3
3
|
import submitForm from "./submitForm";
|
|
4
|
-
|
|
4
|
+
import ApplePayButton from "./ApplePayButton";
|
|
5
|
+
export { VerifyCard, VerifyExistingCard, submitForm, ApplePayButton };
|
package/dist/react/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import VerifyCard from "./VerifyCard";
|
|
2
2
|
import VerifyExistingCard from "./VerifyExistingCard";
|
|
3
3
|
import submitForm from "./submitForm";
|
|
4
|
-
|
|
4
|
+
import ApplePayButton from "./ApplePayButton";
|
|
5
|
+
export { VerifyCard, VerifyExistingCard, submitForm, ApplePayButton };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from "react";
|
|
2
2
|
import * as FatZebra from "../shared/types";
|
|
3
3
|
import { generatePaymentURL } from "./paymentUrl";
|
|
4
4
|
import Sca from "../sca";
|
|
5
5
|
import GatewayClient from "../shared/api-gateway-client";
|
|
6
6
|
import { generateVerifyURL } from "./verifyUrl";
|
|
7
|
+
import useMessage from "./useMessage";
|
|
7
8
|
const useFatZebra = ({ config, handlers, cardToken }) => {
|
|
8
9
|
const { options, accessToken, paymentIntent, username } = config;
|
|
9
10
|
const sca = useMemo(() => {
|
|
@@ -14,62 +15,12 @@ const useFatZebra = ({ config, handlers, cardToken }) => {
|
|
|
14
15
|
scaObj.loadScript();
|
|
15
16
|
return scaObj;
|
|
16
17
|
}, [config, username]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
const handleTokenizeCardResponse = (data) => {
|
|
24
|
-
if (data.errors) {
|
|
25
|
-
emit(FatZebra.PublicEvent.TOKENIZATION_ERROR, {
|
|
26
|
-
message: "Card tokenization failed.",
|
|
27
|
-
errors: data.errors,
|
|
28
|
-
data: null,
|
|
29
|
-
});
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
emit(FatZebra.PublicEvent.TOKENIZATION_SUCCESS, {
|
|
34
|
-
message: "Card tokenization success.",
|
|
35
|
-
data
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (options.sca_enabled) {
|
|
39
|
-
sca.run({ paymentIntent, bin: data.bin, cardToken: data.token });
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const messageHandler = (event) => {
|
|
43
|
-
if (event.data &&
|
|
44
|
-
event.data.source &&
|
|
45
|
-
event.data.source.includes("react-devtools"))
|
|
46
|
-
return;
|
|
47
|
-
if (event.data.subject === FatZebra.BridgeEvent.BIN_LOOKUP)
|
|
48
|
-
return;
|
|
49
|
-
if (event.data.subject === FatZebra.BridgeEvent.FORM_VALIDATION_ERROR) {
|
|
50
|
-
emit(FatZebra.PublicEvent.FORM_VALIDATION_ERROR, {
|
|
51
|
-
errors: event.data.data,
|
|
52
|
-
data: null,
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (event.data.subject === FatZebra.BridgeEvent.FORM_VALIDATION_SUCCESS) {
|
|
57
|
-
emit(FatZebra.PublicEvent.FORM_VALIDATION_SUCCESS, {
|
|
58
|
-
errors: event.data.data,
|
|
59
|
-
data: null,
|
|
60
|
-
});
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (event.data.subject === FatZebra.BridgeEvent.TOKENIZE_CARD_RESPONSE) {
|
|
64
|
-
handleTokenizeCardResponse(event.data.data);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
window.addEventListener("message", messageHandler);
|
|
69
|
-
return () => {
|
|
70
|
-
window.removeEventListener("message", messageHandler);
|
|
71
|
-
};
|
|
72
|
-
}, [paymentIntent]);
|
|
18
|
+
useMessage({
|
|
19
|
+
paymentIntent,
|
|
20
|
+
options,
|
|
21
|
+
handlers,
|
|
22
|
+
sca
|
|
23
|
+
});
|
|
73
24
|
const payment = paymentIntent.payment;
|
|
74
25
|
const verifyUrl = generateVerifyURL(Object.assign({ token: cardToken, verification: paymentIntent.verification, merchant: username }, options), config.environment);
|
|
75
26
|
const paymentUrl = generatePaymentURL(Object.assign({ merchant: username, reference: payment.reference, amount: payment.amount, currency: payment.currency, hash: paymentIntent.verification }, options), config.environment);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as FatZebra from "../shared/types";
|
|
2
|
+
import Sca from "../sca";
|
|
3
|
+
type UseMessageProps = {
|
|
4
|
+
paymentIntent: FatZebra.PaymentIntent;
|
|
5
|
+
handlers: FatZebra.Handlers;
|
|
6
|
+
options?: FatZebra.OptionalUrlValues;
|
|
7
|
+
sca?: InstanceType<typeof Sca>;
|
|
8
|
+
};
|
|
9
|
+
declare const useMessage: ({ paymentIntent, options, handlers, sca }: UseMessageProps) => void;
|
|
10
|
+
export default useMessage;
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { useEffect } from 'react';
|
|
11
|
+
import * as FatZebra from "../shared/types";
|
|
12
|
+
const useMessage = ({ paymentIntent, options, handlers, sca }) => {
|
|
13
|
+
const emit = (event, data) => {
|
|
14
|
+
const handler = handlers[event];
|
|
15
|
+
if (handler) {
|
|
16
|
+
handler(new CustomEvent(event, { detail: data }));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const handleTokenizeCardResponse = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
if (data.errors) {
|
|
21
|
+
emit(FatZebra.PublicEvent.TOKENIZATION_ERROR, {
|
|
22
|
+
message: "Card tokenization failed.",
|
|
23
|
+
errors: data.errors,
|
|
24
|
+
data: null,
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
emit(FatZebra.PublicEvent.TOKENIZATION_SUCCESS, {
|
|
30
|
+
message: "Card tokenization success.",
|
|
31
|
+
data,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (options && sca && options.sca_enabled) {
|
|
35
|
+
yield sca.run({ paymentIntent, bin: data.bin, cardToken: data.token });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const messageHandler = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
if (event.data &&
|
|
40
|
+
event.data.source &&
|
|
41
|
+
event.data.source.includes("react-devtools"))
|
|
42
|
+
return;
|
|
43
|
+
if (event.data.subject === FatZebra.BridgeEvent.BIN_LOOKUP)
|
|
44
|
+
return;
|
|
45
|
+
if (event.data.subject === FatZebra.BridgeEvent.FORM_VALIDATION_ERROR) {
|
|
46
|
+
emit(FatZebra.PublicEvent.FORM_VALIDATION_ERROR, {
|
|
47
|
+
errors: event.data.data,
|
|
48
|
+
data: null,
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (event.data.subject === FatZebra.BridgeEvent.FORM_VALIDATION_SUCCESS) {
|
|
53
|
+
emit(FatZebra.PublicEvent.FORM_VALIDATION_SUCCESS, {
|
|
54
|
+
errors: event.data.data,
|
|
55
|
+
data: null,
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (event.data.subject === FatZebra.BridgeEvent.TOKENIZE_CARD_RESPONSE) {
|
|
60
|
+
yield handleTokenizeCardResponse(event.data.data);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
window.addEventListener("message", messageHandler);
|
|
65
|
+
return () => {
|
|
66
|
+
window.removeEventListener("message", messageHandler);
|
|
67
|
+
};
|
|
68
|
+
}, [paymentIntent]);
|
|
69
|
+
};
|
|
70
|
+
export default useMessage;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
.checkout-button-wrapper {
|
|
2
|
+
display: flex;
|
|
3
|
+
justify-content: center;
|
|
4
|
+
align-items: center;
|
|
5
|
+
height: 200px;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.iframe-checkout {
|
|
9
|
+
flex: 1;
|
|
10
|
+
border: none;
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
min-height: 0;
|
|
14
|
+
overflow: auto;
|
|
15
|
+
-webkit-overflow-scrolling: touch;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.iframe-foreground,
|
|
19
|
+
.iframe-background {
|
|
20
|
+
top: 0;
|
|
21
|
+
left: 0;
|
|
22
|
+
right: 0;
|
|
23
|
+
bottom: 0;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.iframe-foreground,
|
|
28
|
+
.iframe-background {
|
|
29
|
+
position: fixed;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.iframe-foreground {
|
|
33
|
+
z-index: -1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.iframe-background {
|
|
37
|
+
background: rgba(0, 0, 0, 0.5);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.iframe-foreground {
|
|
41
|
+
flex-grow: 1;
|
|
42
|
+
top: auto;
|
|
43
|
+
width: 100%;
|
|
44
|
+
max-width: 480px;
|
|
45
|
+
height: 80vh;
|
|
46
|
+
background-color: #ffffff;
|
|
47
|
+
border-radius: 25px 25px 0 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.slide-in .iframe-foreground {
|
|
51
|
+
transform: translateY(100vh);
|
|
52
|
+
transition: transform 0.4s ease, z-index 0.3s ease 0.4s;
|
|
53
|
+
z-index: -1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.slide-in .iframe-background {
|
|
57
|
+
opacity: 0;
|
|
58
|
+
z-index: -1;
|
|
59
|
+
transition: opacity 0.3s ease, z-index 0.3s ease 0.3s;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.slide-in.show .iframe-foreground {
|
|
63
|
+
transform: none;
|
|
64
|
+
transition: transform 0.4s ease;
|
|
65
|
+
z-index: 100;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.slide-in.show .iframe-background {
|
|
69
|
+
opacity: 1;
|
|
70
|
+
z-index: 0;
|
|
71
|
+
transition: opacity 0.3s ease;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@media only screen and (min-width: 480px) {
|
|
75
|
+
.iframe-foreground {
|
|
76
|
+
margin: 0 auto;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@media only screen and (min-width: 768px) {
|
|
81
|
+
.iframe-foreground {
|
|
82
|
+
margin: 0;
|
|
83
|
+
width: 400px;
|
|
84
|
+
height: 100vh;
|
|
85
|
+
left: 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.slide-in .iframe-foreground {
|
|
89
|
+
transform: translateX(-400px);
|
|
90
|
+
}
|
|
91
|
+
}
|