@fat-zebra/sdk 1.5.2 → 1.5.3-beta.3
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/README.dev.md +5 -0
- package/build-styles.js +8 -1
- package/dist/index.js +3 -2
- package/dist/local/fatzebra.js +6 -5
- package/dist/local/fatzebra.js.map +1 -1
- package/dist/react/ApplePay.d.ts +9 -0
- package/dist/react/ApplePay.js +11 -0
- package/dist/react/applePayUrl.d.ts +12 -0
- package/dist/react/applePayUrl.js +35 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -3
- package/tsconfig.package.json +2 -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/production/fatzebra.css +0 -91
- package/dist/production/fatzebra.js +0 -2
- package/dist/production/fatzebra.js.LICENSE.txt +0 -1
- package/dist/staging/fatzebra.css +0 -91
- package/dist/staging/fatzebra.js +0 -17717
- package/dist/staging/fatzebra.js.map +0 -1
- package/dist/staging/index.html +0 -247
- package/scripts/release-package.js +0 -113
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React, { HTMLProps } from "react";
|
|
2
|
+
import * as FatZebra from "../shared/types";
|
|
3
|
+
type FrameProps = {
|
|
4
|
+
handlers: FatZebra.Handlers;
|
|
5
|
+
config: FatZebra.PaymentConfig;
|
|
6
|
+
iframeProps?: HTMLProps<HTMLIFrameElement>;
|
|
7
|
+
};
|
|
8
|
+
declare const ApplePay: ({ handlers, config, iframeProps }: FrameProps) => React.JSX.Element;
|
|
9
|
+
export default ApplePay;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import useFatZebra from "./useFatZebra";
|
|
3
|
+
const ApplePay = ({ handlers, config, iframeProps }) => {
|
|
4
|
+
const { applePayUrl } = useFatZebra({
|
|
5
|
+
config: Object.assign(Object.assign({}, config), { options: Object.assign(Object.assign({}, config.options), { applepay: true }) }),
|
|
6
|
+
handlers: handlers,
|
|
7
|
+
});
|
|
8
|
+
return (React.createElement("div", null,
|
|
9
|
+
React.createElement("iframe", Object.assign({ src: applePayUrl, allow: "payment", "data-test-id": "apple-pay", title: "apple-pay-button" }, iframeProps))));
|
|
10
|
+
};
|
|
11
|
+
export default ApplePay;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Environment } from "../shared/env";
|
|
2
|
+
import { OptionalUrlValues } from '../shared/types';
|
|
3
|
+
type RequiredURLValues = {
|
|
4
|
+
merchant: string;
|
|
5
|
+
hash: string;
|
|
6
|
+
reference: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
currency: string;
|
|
9
|
+
};
|
|
10
|
+
type UrlValues = RequiredURLValues & OptionalUrlValues;
|
|
11
|
+
declare const generateApplePayUrl: (values: UrlValues, environment?: Environment) => string;
|
|
12
|
+
export { generateApplePayUrl };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parseTemplate } from 'url-template';
|
|
2
|
+
import env, { Environment } from "../shared/env";
|
|
3
|
+
const generateApplePayUrl = (values, environment) => {
|
|
4
|
+
const queryParts = [
|
|
5
|
+
"tokenize_only",
|
|
6
|
+
"css",
|
|
7
|
+
"css_signature",
|
|
8
|
+
"iframe",
|
|
9
|
+
"postmessage",
|
|
10
|
+
"hide_card_holder",
|
|
11
|
+
"hide_button",
|
|
12
|
+
"sca_enabled",
|
|
13
|
+
"applepay"
|
|
14
|
+
];
|
|
15
|
+
const environmentConfig = env[environment || Environment.sandbox];
|
|
16
|
+
const urlTemplate = parseTemplate(`${environmentConfig.payNowUrl}/sdk/{merchant}/{reference}/{currency}/{amount}/{verification}{?${queryParts.join(",")}}`);
|
|
17
|
+
const url = urlTemplate.expand({
|
|
18
|
+
merchant: values.merchant,
|
|
19
|
+
reference: values.reference,
|
|
20
|
+
currency: values.currency,
|
|
21
|
+
amount: values.amount,
|
|
22
|
+
verification: values.hash,
|
|
23
|
+
sca_enabled: values.sca_enabled,
|
|
24
|
+
css: values.css,
|
|
25
|
+
css_signature: values.css_signature,
|
|
26
|
+
iframe: true,
|
|
27
|
+
postmessage: true,
|
|
28
|
+
tokenize_only: values.tokenize_only,
|
|
29
|
+
hide_card_holder: values.hide_card_holder,
|
|
30
|
+
hide_button: values.hide_button,
|
|
31
|
+
applepay: values.applepay
|
|
32
|
+
});
|
|
33
|
+
return url;
|
|
34
|
+
};
|
|
35
|
+
export { generateApplePayUrl };
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.5.
|
|
1
|
+
export declare const version = "1.5.3-beta.3";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.5.
|
|
1
|
+
export const version = '1.5.3-beta.3';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fat-zebra/sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3-beta.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"build:staging": "cp .env.staging .env && export ENVIRONMENT=staging && npx webpack --config webpack.config.dev.js && node build-styles.js",
|
|
10
10
|
"build:sandbox": "cp .env.sandbox .env && export ENVIRONMENT=sandbox && npx webpack --config webpack.config.prod.js && node build-styles.js",
|
|
11
11
|
"build:production": "cp .env.production .env && export ENVIRONMENT=production && npx webpack --config webpack.config.prod.js && node build-styles.js",
|
|
12
|
-
"build:package": "tsc -p tsconfig.package.json && ENVIRONMENT=production node build-styles.js",
|
|
12
|
+
"build:package": "tsc -p tsconfig.package.json && REACT=true ENVIRONMENT=production node build-styles.js",
|
|
13
13
|
"start:local:api": "export MERCHANT_MODE=api && npm run build:local --watch && webpack serve --config webpack.config.dev.js --open 'Google Chrome'",
|
|
14
14
|
"start:local:hpp": "export MERCHANT_MODE=hpp && npm run build:local --watch && webpack serve --config webpack.config.dev.js --open 'Google Chrome'",
|
|
15
15
|
"start:staging:api": "export MERCHANT_MODE=api && npm run build:staging --watch && webpack serve --config webpack.config.dev.js --open 'Google Chrome'",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"start:staging:es5": "export MERCHANT_MODE=es5 && npm run build:staging --watch && webpack serve --config webpack.config.dev.js --open 'Google Chrome'",
|
|
18
18
|
"start:docker": "npm run build:dev --watch && webpack serve --config webpack.config.dev.js --host 0.0.0.0",
|
|
19
19
|
"generate:jwt": "node scripts/generate-access-token.js",
|
|
20
|
-
"npm:publish": "node scripts/release-package.
|
|
20
|
+
"npm:publish": "ts-node scripts/release-package.ts"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [],
|
|
23
23
|
"author": "",
|
|
@@ -55,6 +55,9 @@
|
|
|
55
55
|
"ajv": "^6.12.3",
|
|
56
56
|
"axios": "^1.6.4",
|
|
57
57
|
"custom-event-polyfill": "^1.0.7",
|
|
58
|
+
"inquirer": "^10.0.1",
|
|
59
|
+
"simple-git": "^3.25.0",
|
|
60
|
+
"ts-node": "^10.9.2",
|
|
58
61
|
"ts-polyfill": "^3.8.2",
|
|
59
62
|
"url-template": "^3.1.0"
|
|
60
63
|
},
|
package/tsconfig.package.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"outDir": "./dist/",
|
|
5
5
|
"jsx": "react",
|
|
6
6
|
"esModuleInterop": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
7
8
|
"sourceMap": false,
|
|
8
9
|
"noImplicitAny": true,
|
|
9
10
|
"module": "esnext",
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
"isolatedModules": true,
|
|
17
18
|
},
|
|
18
19
|
"include": [
|
|
19
|
-
"./src/**/*"
|
|
20
|
+
"./src/**/*",
|
|
20
21
|
],
|
|
21
22
|
"exclude": [
|
|
22
23
|
"node_modules",
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { PayPalPaymentMethod } from './types';
|
|
2
|
-
import { PaymentIntent } from '../shared/types';
|
|
3
|
-
interface PayPal {
|
|
4
|
-
render(containerId: string): void;
|
|
5
|
-
}
|
|
6
|
-
interface PayPalButtonStyle {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}
|
|
9
|
-
export default class PayPalButton {
|
|
10
|
-
private validationErrorRaised;
|
|
11
|
-
private _paypalButtons;
|
|
12
|
-
private paymentMethod;
|
|
13
|
-
private paymentIntent;
|
|
14
|
-
private buttonStyle;
|
|
15
|
-
private billingAgreement;
|
|
16
|
-
private client;
|
|
17
|
-
private actions;
|
|
18
|
-
constructor(paymentMethod?: PayPalPaymentMethod, paymentIntent?: PaymentIntent, billingAgreement?: boolean, buttonStyle?: PayPalButtonStyle);
|
|
19
|
-
get paypalButtons(): any;
|
|
20
|
-
get paypalActions(): any;
|
|
21
|
-
render(containerId: string): void;
|
|
22
|
-
getContainer(containerId: string): any;
|
|
23
|
-
private createButton;
|
|
24
|
-
private createOrder;
|
|
25
|
-
private approveOrder;
|
|
26
|
-
private createBillingAgreement;
|
|
27
|
-
private approveBillingAgreement;
|
|
28
|
-
private formatError;
|
|
29
|
-
}
|
|
30
|
-
export { PayPalButton };
|
|
31
|
-
export type { PayPal, PayPalButtonStyle, };
|
|
@@ -1,199 +0,0 @@
|
|
|
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 { emit } from '../shared/event-manager';
|
|
11
|
-
import { PayPalIntent } from './types';
|
|
12
|
-
import GatewayClient from '../shared/api-gateway-client';
|
|
13
|
-
import { PublicEvent } from '../shared/types';
|
|
14
|
-
import * as util from '../shared/util';
|
|
15
|
-
import { LocalStorageAccessTokenKey } from '../shared/constants';
|
|
16
|
-
const defaultStyle = {
|
|
17
|
-
layout: 'horizontal',
|
|
18
|
-
color: 'gold',
|
|
19
|
-
shape: 'pill',
|
|
20
|
-
label: 'paypal',
|
|
21
|
-
};
|
|
22
|
-
export default class PayPalButton {
|
|
23
|
-
constructor(paymentMethod, paymentIntent, billingAgreement, buttonStyle) {
|
|
24
|
-
this.paymentMethod = paymentMethod;
|
|
25
|
-
this.paymentIntent = paymentIntent;
|
|
26
|
-
this.billingAgreement = billingAgreement;
|
|
27
|
-
this.buttonStyle = buttonStyle;
|
|
28
|
-
this.client = new GatewayClient({ accessToken: window.localStorage.getItem(LocalStorageAccessTokenKey),
|
|
29
|
-
username: window.MerchantUsername,
|
|
30
|
-
});
|
|
31
|
-
this.createButton();
|
|
32
|
-
}
|
|
33
|
-
get paypalButtons() {
|
|
34
|
-
return this._paypalButtons;
|
|
35
|
-
}
|
|
36
|
-
get paypalActions() {
|
|
37
|
-
return this.actions;
|
|
38
|
-
}
|
|
39
|
-
render(containerId) {
|
|
40
|
-
let container = this.getContainer(containerId);
|
|
41
|
-
if (typeof (container) != 'undefined' && container != null) {
|
|
42
|
-
this._paypalButtons.render('#' + container.id);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
emit(PublicEvent.PAYPAL_ERROR, {
|
|
46
|
-
errors: [`Container with id #${containerId} does not exist.`],
|
|
47
|
-
data: null
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
getContainer(containerId) {
|
|
52
|
-
return document.getElementById(containerId);
|
|
53
|
-
}
|
|
54
|
-
createButton() {
|
|
55
|
-
let button = ({});
|
|
56
|
-
button.style = (this.buttonStyle ? this.buttonStyle : defaultStyle);
|
|
57
|
-
if (this.billingAgreement === true) {
|
|
58
|
-
button.createBillingAgreement = () => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
return this.createBillingAgreement();
|
|
60
|
-
});
|
|
61
|
-
button.onApprove = (data, actions) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
emit(PublicEvent.PAYPAL_PROCESSESING, { data: {}, message: 'The request is being processed.' });
|
|
63
|
-
return this.approveBillingAgreement(data);
|
|
64
|
-
});
|
|
65
|
-
button.onCancel = (data, actions) => {
|
|
66
|
-
emit(PublicEvent.PAYPAL_CANCEL, { data: { id: data.orderID }, message: 'PayPal Billing Agreement cancelled.' });
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
button.createOrder = () => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
return this.createOrder();
|
|
72
|
-
});
|
|
73
|
-
button.onApprove = (data, actions) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
emit(PublicEvent.PAYPAL_PROCESSESING, { data: {}, message: 'The request is being processed.' });
|
|
75
|
-
return this.approveOrder(data);
|
|
76
|
-
});
|
|
77
|
-
button.onCancel = (data, actions) => {
|
|
78
|
-
emit(PublicEvent.PAYPAL_CANCEL, { data: { id: data.orderID }, message: 'PayPal Order cancelled.' });
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
button.onError = (error) => {
|
|
82
|
-
// This flag is used to prevent emitting general error from PayPal
|
|
83
|
-
// if an error has already been raised and emitted.
|
|
84
|
-
if (this.validationErrorRaised === false) {
|
|
85
|
-
emit(PublicEvent.PAYPAL_ERROR, {
|
|
86
|
-
errors: ['PayPal Checkout failed.'],
|
|
87
|
-
data: null
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
this._paypalButtons = window.paypal.Buttons(button);
|
|
92
|
-
}
|
|
93
|
-
createOrder() {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
try {
|
|
96
|
-
this.validationErrorRaised = false;
|
|
97
|
-
let payload = util.toObjectWithSnakeCaseKeys(this.paymentMethod);
|
|
98
|
-
payload.payment_intent = this.paymentIntent;
|
|
99
|
-
const response = (yield this.client.createPayPalOrder({
|
|
100
|
-
order: payload
|
|
101
|
-
})).data;
|
|
102
|
-
return response.id;
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
this.validationErrorRaised = true;
|
|
106
|
-
emit(PublicEvent.PAYPAL_ERROR, {
|
|
107
|
-
errors: this.formatError(error),
|
|
108
|
-
data: null
|
|
109
|
-
});
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
approveOrder(data) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
try {
|
|
117
|
-
this.validationErrorRaised = false;
|
|
118
|
-
let response = undefined;
|
|
119
|
-
if (this.paymentMethod.intent.toUpperCase() === PayPalIntent.CAPTURE) {
|
|
120
|
-
response = (yield this.client.capturePayPalOrder({
|
|
121
|
-
id: data.orderID
|
|
122
|
-
})).data;
|
|
123
|
-
}
|
|
124
|
-
else if (this.paymentMethod.intent.toUpperCase() === PayPalIntent.AUTHORIZE) {
|
|
125
|
-
response = (yield this.client.authorizePayPalOrder({
|
|
126
|
-
id: data.orderID
|
|
127
|
-
})).data;
|
|
128
|
-
}
|
|
129
|
-
emit(PublicEvent.PAYPAL_SUCCESS, {
|
|
130
|
-
data: util.toObjectWithCamelCaseKeys(response),
|
|
131
|
-
message: 'PayPal order approved.'
|
|
132
|
-
});
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
this.validationErrorRaised = true;
|
|
137
|
-
emit(PublicEvent.PAYPAL_ERROR, {
|
|
138
|
-
errors: this.formatError(error),
|
|
139
|
-
data: null
|
|
140
|
-
});
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
createBillingAgreement() {
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
try {
|
|
148
|
-
this.validationErrorRaised = false;
|
|
149
|
-
let payload = util.toObjectWithSnakeCaseKeys(this.paymentMethod);
|
|
150
|
-
delete payload.billing_agreement;
|
|
151
|
-
let response = (yield this.client.createPayPalBillingAgreement({
|
|
152
|
-
billing: payload
|
|
153
|
-
})).data;
|
|
154
|
-
return response.token_id;
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
this.validationErrorRaised = true;
|
|
158
|
-
emit(PublicEvent.PAYPAL_ERROR, {
|
|
159
|
-
errors: this.formatError(error),
|
|
160
|
-
data: null
|
|
161
|
-
});
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
approveBillingAgreement(data) {
|
|
167
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
-
try {
|
|
169
|
-
this.validationErrorRaised = false;
|
|
170
|
-
let response = (yield this.client.approvePayPalBillingAgreement({
|
|
171
|
-
id: data.billingToken
|
|
172
|
-
})).data;
|
|
173
|
-
emit(PublicEvent.PAYPAL_SUCCESS, {
|
|
174
|
-
data: util.toObjectWithCamelCaseKeys(response),
|
|
175
|
-
message: 'PayPal Billing Agreement created.'
|
|
176
|
-
});
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
this.validationErrorRaised = true;
|
|
181
|
-
emit(PublicEvent.PAYPAL_ERROR, {
|
|
182
|
-
errors: this.formatError(error),
|
|
183
|
-
data: null
|
|
184
|
-
});
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
formatError(error) {
|
|
190
|
-
var _a, _b;
|
|
191
|
-
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();
|
|
192
|
-
if (typeof message[0] === 'undefined')
|
|
193
|
-
message = [error === null || error === void 0 ? void 0 : error.message].flat();
|
|
194
|
-
if (typeof message[0] === 'undefined')
|
|
195
|
-
message = ['Unknown error'];
|
|
196
|
-
return message;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
export { PayPalButton };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PayPalButton } from './paypal-button';
|
|
2
|
-
import { PayPalConfig } from './types';
|
|
3
|
-
export default class PayPalCheckout {
|
|
4
|
-
private paypalButton;
|
|
5
|
-
private validationErrors;
|
|
6
|
-
private intent;
|
|
7
|
-
private currency;
|
|
8
|
-
private payment;
|
|
9
|
-
private billingAgreement;
|
|
10
|
-
private containerId;
|
|
11
|
-
private buttonStyle;
|
|
12
|
-
constructor(config: PayPalConfig);
|
|
13
|
-
get paypal(): PayPalButton;
|
|
14
|
-
set paypal(paypal: PayPalButton);
|
|
15
|
-
load(): Promise<any>;
|
|
16
|
-
render(): void;
|
|
17
|
-
private validatePayPalSetup;
|
|
18
|
-
private validatePayPalRequest;
|
|
19
|
-
private errors;
|
|
20
|
-
}
|
|
21
|
-
export { PayPalCheckout };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
// This is the implementation of PayPal Checkout
|
|
2
|
-
//
|
|
3
|
-
// https://developer.paypal.com/docs/checkout/
|
|
4
|
-
import { emit } from '../shared/event-manager';
|
|
5
|
-
import { PaymentMethodType, PublicEvent } from '../shared/types';
|
|
6
|
-
import { PayPalButton, } from './paypal-button';
|
|
7
|
-
import { validatePayPalSetup, validatePayPalRequest, } from './validation';
|
|
8
|
-
export default class PayPalCheckout {
|
|
9
|
-
constructor(config) {
|
|
10
|
-
var _a, _b, _c, _d, _e;
|
|
11
|
-
if (!this.validatePayPalSetup(config)) {
|
|
12
|
-
emit(PublicEvent.PAYPAL_ERROR, {
|
|
13
|
-
errors: this.errors(),
|
|
14
|
-
data: null
|
|
15
|
-
});
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
this.billingAgreement = (((_b = (_a = config === null || config === void 0 ? void 0 : config.payment) === null || _a === void 0 ? void 0 : _a.paymentMethod) === null || _b === void 0 ? void 0 : _b.type) === PaymentMethodType.PAYPAL_BILLING);
|
|
19
|
-
this.payment = config === null || config === void 0 ? void 0 : config.payment;
|
|
20
|
-
this.intent = (_e = (_d = (_c = config === null || config === void 0 ? void 0 : config.payment) === null || _c === void 0 ? void 0 : _c.paymentMethod) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.intent;
|
|
21
|
-
this.currency = config === null || config === void 0 ? void 0 : config.currency;
|
|
22
|
-
this.containerId = config === null || config === void 0 ? void 0 : config.containerId;
|
|
23
|
-
this.buttonStyle = config === null || config === void 0 ? void 0 : config.style;
|
|
24
|
-
if (!this.validatePayPalRequest()) {
|
|
25
|
-
emit(PublicEvent.PAYPAL_ERROR, {
|
|
26
|
-
errors: this.errors(),
|
|
27
|
-
data: null
|
|
28
|
-
});
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
get paypal() {
|
|
33
|
-
return this.paypalButton;
|
|
34
|
-
}
|
|
35
|
-
set paypal(paypal) {
|
|
36
|
-
this.paypalButton = paypal;
|
|
37
|
-
}
|
|
38
|
-
load() {
|
|
39
|
-
if (this.errors()) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (this.intent && !this.billingAgreement) {
|
|
43
|
-
let data = this.payment.paymentMethod.data;
|
|
44
|
-
data.intent = this.intent.toUpperCase();
|
|
45
|
-
}
|
|
46
|
-
let self = this;
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
const script = document.createElement('script');
|
|
49
|
-
script.type = 'text/javascript';
|
|
50
|
-
let source = process.env.PAYPAL_SDK_URL + '&client-id=' + process.env.PAYPAL_CLIENT_ID + '&debug=' + process.env.PAYPAL_DEBUG;
|
|
51
|
-
if (this.currency)
|
|
52
|
-
source += '¤cy=' + this.currency;
|
|
53
|
-
if (this.intent && !this.billingAgreement)
|
|
54
|
-
source += '&intent=' + this.intent;
|
|
55
|
-
if (this.billingAgreement === true)
|
|
56
|
-
source += '&vault=true';
|
|
57
|
-
script.setAttribute('data-partner-attribution-id', process.env.PAYPAL_PARTNER_ID);
|
|
58
|
-
script.src = source;
|
|
59
|
-
script.async = true;
|
|
60
|
-
document.body.appendChild(script);
|
|
61
|
-
script.onload = () => {
|
|
62
|
-
self.paypalButton = new PayPalButton(self.payment.paymentMethod.data, self.payment.paymentIntent, self.billingAgreement, self.buttonStyle);
|
|
63
|
-
resolve(null);
|
|
64
|
-
};
|
|
65
|
-
script.onerror = () => {
|
|
66
|
-
reject(['Loading PayPal failed']);
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
render() {
|
|
71
|
-
if (this.errors()) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
this.paypalButton.render(this.containerId);
|
|
75
|
-
}
|
|
76
|
-
validatePayPalSetup(config) {
|
|
77
|
-
const validations = validatePayPalSetup(config);
|
|
78
|
-
this.validationErrors = null;
|
|
79
|
-
if (!validations.valid) {
|
|
80
|
-
this.validationErrors = validations.errors;
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
validatePayPalRequest() {
|
|
86
|
-
const validations = validatePayPalRequest(this.payment, this.billingAgreement);
|
|
87
|
-
this.validationErrors = null;
|
|
88
|
-
if (!validations.valid) {
|
|
89
|
-
this.validationErrors = validations.errors;
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
errors() {
|
|
95
|
-
if (this.validationErrors !== null)
|
|
96
|
-
return this.validationErrors;
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
export { PayPalCheckout };
|
package/dist/paypal/types.d.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { PaymentMethod, PaymentIntent } from '../shared/types';
|
|
2
|
-
export interface PayPalConfig {
|
|
3
|
-
currency: string;
|
|
4
|
-
payment: PayPalOrderParams;
|
|
5
|
-
containerId: string;
|
|
6
|
-
style?: {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export interface PayPalOrderParams {
|
|
11
|
-
paymentIntent?: PaymentIntent;
|
|
12
|
-
paymentMethod: PaymentMethod;
|
|
13
|
-
}
|
|
14
|
-
export declare enum PayPalIntent {
|
|
15
|
-
CAPTURE = "CAPTURE",
|
|
16
|
-
AUTHORIZE = "AUTHORIZE"
|
|
17
|
-
}
|
|
18
|
-
export type PayPalPaymentMethod = PayPalOrderRequest | PayPalBillingAgreementRequest;
|
|
19
|
-
/***************** PayPal Order Object ******************/
|
|
20
|
-
export interface PayPalOrderRequest {
|
|
21
|
-
intent: 'capture' | 'authorize';
|
|
22
|
-
options?: {
|
|
23
|
-
brandName?: string;
|
|
24
|
-
landingPage?: string;
|
|
25
|
-
payeePreferredPayment?: string;
|
|
26
|
-
shippingPreference?: string;
|
|
27
|
-
};
|
|
28
|
-
purchases: Purchases[];
|
|
29
|
-
}
|
|
30
|
-
interface Purchases {
|
|
31
|
-
description?: string;
|
|
32
|
-
softDescriptor?: string;
|
|
33
|
-
amount: Amount;
|
|
34
|
-
items?: Item[];
|
|
35
|
-
shippingAddress: {
|
|
36
|
-
name?: string;
|
|
37
|
-
method?: string;
|
|
38
|
-
address: Address;
|
|
39
|
-
};
|
|
40
|
-
payee?: {
|
|
41
|
-
emailAddress: string;
|
|
42
|
-
merchantId: string;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
interface Amount {
|
|
46
|
-
itemTotal?: number;
|
|
47
|
-
shipping?: number;
|
|
48
|
-
handling?: number;
|
|
49
|
-
taxTotal?: number;
|
|
50
|
-
shippingDiscount?: number;
|
|
51
|
-
insurance?: number;
|
|
52
|
-
discount?: number;
|
|
53
|
-
}
|
|
54
|
-
interface Address {
|
|
55
|
-
firstName?: string;
|
|
56
|
-
lastName?: string;
|
|
57
|
-
address_1?: string;
|
|
58
|
-
address_2?: string;
|
|
59
|
-
city?: string;
|
|
60
|
-
state?: string;
|
|
61
|
-
postcode?: string;
|
|
62
|
-
country: string;
|
|
63
|
-
}
|
|
64
|
-
interface Item {
|
|
65
|
-
name: string;
|
|
66
|
-
description?: string;
|
|
67
|
-
sku?: string;
|
|
68
|
-
unitAmount: number;
|
|
69
|
-
tax?: number;
|
|
70
|
-
qty: string;
|
|
71
|
-
category?: string;
|
|
72
|
-
}
|
|
73
|
-
export interface CreatePayPalOrderRequest {
|
|
74
|
-
order: PayPalOrderRequest;
|
|
75
|
-
}
|
|
76
|
-
export interface PayPalOrderResponse {
|
|
77
|
-
id: string;
|
|
78
|
-
intent: PayPalIntent;
|
|
79
|
-
}
|
|
80
|
-
/***************** PayPal Capture Object ******************/
|
|
81
|
-
export interface CapturePayPalOrderRequest {
|
|
82
|
-
id: string;
|
|
83
|
-
}
|
|
84
|
-
export interface CapturePayPalOrderResponse {
|
|
85
|
-
id: string;
|
|
86
|
-
intent: string;
|
|
87
|
-
reference: string;
|
|
88
|
-
paypal_reference: string;
|
|
89
|
-
invoice_id: string;
|
|
90
|
-
amount: number;
|
|
91
|
-
decimal_amount: number;
|
|
92
|
-
captured_amount: number;
|
|
93
|
-
captured: boolean;
|
|
94
|
-
successful: boolean;
|
|
95
|
-
status: string;
|
|
96
|
-
message: string;
|
|
97
|
-
currency: string;
|
|
98
|
-
transaction_id: string;
|
|
99
|
-
transaction_date: Date;
|
|
100
|
-
response_code: string;
|
|
101
|
-
paypal_fee: number;
|
|
102
|
-
seller_receivable_net_amount: number;
|
|
103
|
-
note_to_payer: string;
|
|
104
|
-
is_final_capture: boolean;
|
|
105
|
-
refunded_amount: number;
|
|
106
|
-
balance_available_for_refund: number;
|
|
107
|
-
balance_available_for_capture: number;
|
|
108
|
-
authorization: string;
|
|
109
|
-
order: string;
|
|
110
|
-
}
|
|
111
|
-
/***************** PayPal Authorize Object ******************/
|
|
112
|
-
export interface AuthorizePayPalOrderRequest {
|
|
113
|
-
id: string;
|
|
114
|
-
}
|
|
115
|
-
export interface AuthorizePayPalOrderResponse {
|
|
116
|
-
id: string;
|
|
117
|
-
intent: string;
|
|
118
|
-
reference: string;
|
|
119
|
-
paypal_reference: string;
|
|
120
|
-
invoice_id: string;
|
|
121
|
-
amount: number;
|
|
122
|
-
decimal_amount: number;
|
|
123
|
-
captured_amount: number;
|
|
124
|
-
captured: boolean;
|
|
125
|
-
successful: boolean;
|
|
126
|
-
status: string;
|
|
127
|
-
message: string;
|
|
128
|
-
currency: string;
|
|
129
|
-
transaction_id: string;
|
|
130
|
-
transaction_date: Date;
|
|
131
|
-
response_code: string;
|
|
132
|
-
refunded_amount: number;
|
|
133
|
-
balance_available_for_capture: number;
|
|
134
|
-
order: string;
|
|
135
|
-
}
|
|
136
|
-
/***************** PayPal Billing Agreement Object ******************/
|
|
137
|
-
export interface PayPalBillingAgreementRequest {
|
|
138
|
-
name?: string;
|
|
139
|
-
description?: string;
|
|
140
|
-
shippingAddress: BillingAddress;
|
|
141
|
-
merchantCustomData?: string;
|
|
142
|
-
}
|
|
143
|
-
export interface CreatePayPalBillingAgreementRequest {
|
|
144
|
-
billing: PayPalBillingAgreementRequest;
|
|
145
|
-
}
|
|
146
|
-
interface BillingAddress {
|
|
147
|
-
firstName?: string;
|
|
148
|
-
lastName?: string;
|
|
149
|
-
address_1: string;
|
|
150
|
-
address_2?: string;
|
|
151
|
-
city: string;
|
|
152
|
-
state: string;
|
|
153
|
-
postcode: string;
|
|
154
|
-
country: string;
|
|
155
|
-
}
|
|
156
|
-
export interface PayPalBillingAgreementResponse {
|
|
157
|
-
token_id: string;
|
|
158
|
-
}
|
|
159
|
-
export interface ApprovePayPalBillingAgreementRequest {
|
|
160
|
-
id: string;
|
|
161
|
-
}
|
|
162
|
-
export interface ApprovePayPalBillingAgreementResponse {
|
|
163
|
-
token: string;
|
|
164
|
-
name?: string;
|
|
165
|
-
description?: string;
|
|
166
|
-
state: string;
|
|
167
|
-
payer?: {
|
|
168
|
-
payer_info: {
|
|
169
|
-
email: string;
|
|
170
|
-
first_name: string;
|
|
171
|
-
last_name: string;
|
|
172
|
-
payer_id: string;
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
shipping_address?: {
|
|
176
|
-
first_name?: string;
|
|
177
|
-
last_name?: string;
|
|
178
|
-
address_1: string;
|
|
179
|
-
address_2?: string;
|
|
180
|
-
city: string;
|
|
181
|
-
state: string;
|
|
182
|
-
postcode: string;
|
|
183
|
-
country: string;
|
|
184
|
-
};
|
|
185
|
-
merchant_custom_data?: string;
|
|
186
|
-
created_at: Date;
|
|
187
|
-
}
|
|
188
|
-
export {};
|