@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
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 {};
|
package/dist/paypal/types.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { PayPalConfig, PayPalOrderParams } from './types';
|
|
2
|
-
import { ValidationResult } from '../shared/types';
|
|
3
|
-
export declare const validatePayPalSetup: (props: PayPalConfig) => ValidationResult;
|
|
4
|
-
export declare const validatePayPalRequest: (props: PayPalOrderParams, billing?: boolean) => ValidationResult;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { PayPalIntent } from './types';
|
|
2
|
-
const PaypalConfigRequiredProps = ['currency', 'containerId', 'payment'];
|
|
3
|
-
const PaypalOrderRequiredProps = ['intent', 'purchases'];
|
|
4
|
-
const PaypalBillingRequiredProps = ['shippingAddress'];
|
|
5
|
-
export const validatePayPalSetup = (props) => {
|
|
6
|
-
let errors = [];
|
|
7
|
-
const keys = Object.keys(props);
|
|
8
|
-
for (let requiredProp of PaypalConfigRequiredProps) {
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
if (!keys.includes(requiredProp) || props[requiredProp] === undefined) {
|
|
11
|
-
errors.push(`${requiredProp} is missing.`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
valid: errors.length == 0,
|
|
16
|
-
errors
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export const validatePayPalRequest = (props, billing) => {
|
|
20
|
-
let errors = [];
|
|
21
|
-
const keys = Object.keys(props);
|
|
22
|
-
if (!keys.includes('paymentMethod')) {
|
|
23
|
-
errors.push(`paymentMethod is missing.`);
|
|
24
|
-
}
|
|
25
|
-
if (!keys.includes('paymentIntent') && !billing) {
|
|
26
|
-
errors.push(`paymentIntent is missing.`);
|
|
27
|
-
}
|
|
28
|
-
if (props.paymentMethod) {
|
|
29
|
-
const orderKeys = Object.keys(props.paymentMethod.data);
|
|
30
|
-
if (orderKeys.includes('intent')) {
|
|
31
|
-
const intent = props.paymentMethod.data.intent.toLowerCase();
|
|
32
|
-
const intents = Object.values(PayPalIntent).map(v => v.toLowerCase());
|
|
33
|
-
if (!intents.includes(intent)) {
|
|
34
|
-
errors.push(`intent is invalid, must be one of [${intents.join(', ')}].`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (!props.paymentMethod.type) {
|
|
38
|
-
errors.push(`paymentMethod.type is missing.`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (errors.length > 0) {
|
|
42
|
-
return {
|
|
43
|
-
valid: errors.length == 0,
|
|
44
|
-
errors
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const paymentMethod = props.paymentMethod.data;
|
|
48
|
-
const providedKeys = Object.keys(paymentMethod);
|
|
49
|
-
let requiredProps;
|
|
50
|
-
if (billing === true) {
|
|
51
|
-
requiredProps = PaypalBillingRequiredProps;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
requiredProps = PaypalOrderRequiredProps;
|
|
55
|
-
}
|
|
56
|
-
for (let requiredProp of requiredProps) {
|
|
57
|
-
if (!providedKeys.includes(requiredProp)) {
|
|
58
|
-
errors.push(`${requiredProp} is missing.`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
valid: errors.length == 0,
|
|
63
|
-
errors
|
|
64
|
-
};
|
|
65
|
-
};
|
package/dist/react/url.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { parseTemplate } from 'url-template';
|
|
2
|
-
import env, { Environment } from "../shared/env";
|
|
3
|
-
const generatePaymentURL = (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
|
-
];
|
|
14
|
-
const environmentConfig = env[environment || Environment.sandbox];
|
|
15
|
-
const urlTemplate = parseTemplate(`${environmentConfig.payNowUrl}/sdk/v3/{merchant}/{reference}/{currency}/{amount}/{verification}{?${queryParts.join(",")}}`);
|
|
16
|
-
const url = urlTemplate.expand({
|
|
17
|
-
merchant: values.merchant,
|
|
18
|
-
reference: values.reference,
|
|
19
|
-
currency: values.currency,
|
|
20
|
-
amount: values.amount,
|
|
21
|
-
verification: values.hash,
|
|
22
|
-
sca_enabled: values.sca_enabled,
|
|
23
|
-
css: values.css,
|
|
24
|
-
css_signature: values.css_signature,
|
|
25
|
-
iframe: true,
|
|
26
|
-
postmessage: true,
|
|
27
|
-
tokenize_only: values.tokenize_only,
|
|
28
|
-
hide_card_holder: values.hide_card_holder,
|
|
29
|
-
hide_button: values.hide_button,
|
|
30
|
-
});
|
|
31
|
-
return url;
|
|
32
|
-
};
|
|
33
|
-
export { generatePaymentURL };
|
|
@@ -1,311 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paypal-button.js","sourceRoot":"","sources":["../../../src/paypal/paypal-button.ts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AE,IAAI,CAAC,WAAW,CAAC,OAAK,CAAC;4BAC/B,IAAI,EAAE,IAAI;yBACX,CAAC,CAAA;wBACF,sBAAM;;;;;KAET;IAEO,kCAAW,GAAnB,UAAoB,KAAU;;QAC5B,IAAI,OAAO,GAAG,CAAC,MAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,0CAAE,QAAQ,0CAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;QACvD,IAAI,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;YAAE,OAAO,GAAG,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAA;QACxE,IAAI,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;YAAE,OAAO,GAAG,CAAC,eAAe,CAAC,CAAA;QAElE,OAAO,OAAO,CAAA;IAChB,CAAC;IACH,mBAAC;AAAD,CAAC,AA9MD,IA8MC;AAEQ,oCAAY"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paypal-button.test.js","sourceRoot":"","sources":["../../../src/paypal/paypal-button.test.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,yCAA6C;AAC7C,iDAA8C;AAC9C,IAAM,YAAY,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAA;AAC9D,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;AAE7B,QAAQ,CAAC,cAAc,EAAE;IACvB,IAAI,QAAsB,CAAA;IAE1B,UAAU,CAAC;QACT,IAAI,CAAC,aAAa,EAAE,CAAA;QAEpB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;QACzB,MAAM,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC;YACnD,OAAO;gBACL,MAAM,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI;aACnB,CAAA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