@fat-zebra/sdk 1.5.2 → 1.5.3-beta.1

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.
@@ -1,247 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8" />
5
- <title>Merchant XYZ Checkout Page</title>
6
- <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
7
- <style type="text/css">
8
- iframe {
9
- height: 600px;
10
- width: 700px;
11
- }
12
- </style>
13
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
14
- <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-md5.js"></script>
15
- <script>
16
- window.localStorage.setItem('fz-access-token', "<DO NOT USE>")
17
- // card tokens will be filled out
18
- var actionItems = {
19
- tokens: [
20
- {
21
- token: 'whatever',
22
- number: '4000000000001000',
23
- description: 'Successful Frictionless Authentication'
24
- },
25
- {
26
- token: '',
27
- number: '4000000000001026',
28
- description: 'Attempts Stand-In Frictionless'
29
- },
30
- {
31
- token: '',
32
- number: '4000000000001034',
33
- description: 'Unavailable Frictionless'
34
- },
35
- {
36
- token: '',
37
- number: '4000000000001059',
38
- description: 'Authentication Not Available on Lookup'
39
- },
40
- {
41
- token: '',
42
- number: '4000000000001067',
43
- description: 'Error on Lookup'
44
- },
45
- {
46
- token: '',
47
- number: '4000000000001075',
48
- description: 'Timeout on cmpi_lookup'
49
- },
50
- {
51
- token: '',
52
- number: '4000000000001083',
53
- description: 'Bypassed Authentication'
54
- },
55
- {
56
- token: '',
57
- number: '4000000000001018',
58
- description: 'Failed Frictionless'
59
- },
60
- {
61
- token: '',
62
- number: '4000000000001042',
63
- description: 'Rejected Frictionless'
64
- },
65
- {
66
- token: 'ahq94qb60fs0xaruga3h',
67
- number: '4000000000001091',
68
- description: 'Challenge'
69
- }
70
- ],
71
- cards: [
72
- {
73
- number: '4000000000001000',
74
- description: 'Successful Frictionless Authentication'
75
- },
76
- {
77
- number: '4000000000001026',
78
- description: 'Attempts Stand-In Frictionless'
79
- },
80
- {
81
- number: '4000000000001034',
82
- description: 'Unavailable Frictionless'
83
- },
84
- {
85
- number: '4000000000001059',
86
- description: 'Authentication Not Available on Lookup'
87
- },
88
- {
89
- number: '4000000000001067',
90
- description: 'Error on Lookup'
91
- },
92
- {
93
- number: '4000000000001075',
94
- description: 'Timeout on cmpi_lookup'
95
- },
96
- {
97
- number: '4000000000001083',
98
- description: 'Bypassed Authentication'
99
- },
100
- {
101
- number: '4000000000001018',
102
- description: 'Failed Frictionless'
103
- },
104
- {
105
- number: '4000000000001042',
106
- description: 'Rejected Frictionless'
107
- },
108
- {
109
- number: '4000000000001091',
110
- description: 'Challenge'
111
- }
112
- ]
113
- }
114
- </script>
115
- <script src="fatzebra.js"></script></head>
116
- <body>
117
- <table id="options" class="table table-bordered">
118
- <thead>
119
- <tr>
120
- <th scope="col">Card Token</th>
121
- <th scope="col">New Card</th>
122
- <th scope="col">Description</th>
123
- </tr>
124
- </thead>
125
- <tbody>
126
- </tbody>
127
- </table>
128
- <button type="button" class="btn btn-primary" id='doCheckout'>Primary</button>
129
-
130
- <script>
131
- var selectedMode = undefined
132
- var selectedValue = undefined
133
-
134
- $(document).ready(function() {
135
-
136
- for (var i = 0; i < actionItems.tokens.length; i ++ ) {
137
- const row = "<tr><td><input type='checkbox' class='option' data-mode='token' value='" + actionItems.tokens[i].token + "'><label>token for " + actionItems.tokens[i].number + "</label></td>" +
138
- "<td><input type='checkbox' class='option' data-mode='card' value='" + actionItems.cards[i].number + "'><label>" + actionItems.cards[i].number + "</label></td>" +
139
- "<td><label>" + actionItems.cards[i].description + "</label></td></tr>";
140
- $('#options').append(row)
141
- }
142
-
143
- $('.option').change(function() {
144
-
145
- if ($(this).prop("checked") == true) {
146
- if (selectedValue === undefined) {
147
- selectedMode = $(this).data('mode');
148
- selectedValue = $(this).val();
149
- } else {
150
- $(this).prop("checked", false)
151
- alert("There can only be one checkbox selected!");
152
- }
153
- } else {
154
- selectedMode = undefined;
155
- selectedValue = undefined;
156
- }
157
-
158
- console.log('selectedMode: ' + selectedMode);
159
- console.log('selectedValue: ' + selectedValue);
160
- })
161
- })
162
-
163
- </script>
164
- </body>
165
- <footer>
166
-
167
- <script>
168
- var fz = new FatZebra({
169
- username: 'TEST'
170
- });
171
-
172
- $('#doCheckout').click(function() {
173
- if (selectedMode === undefined || selectedValue == undefined) {
174
- alert('Please select an option.');
175
- return
176
- }
177
-
178
- var paymentMethod = undefined;
179
-
180
- if (selectedMode === 'card') {
181
- paymentMethod = {
182
- type: 'card',
183
- data: {
184
- number: selectedValue,
185
- holder: 'John Doe',
186
- expiryMonth: '01',
187
- expiryYear: '2022',
188
- cvv: '123'
189
- }
190
- }
191
- } else {
192
- paymentMethod = {
193
- type: 'card_on_file',
194
- data: {
195
- token: selectedValue
196
- }
197
- }
198
- }
199
-
200
- function randomString(length) {
201
- return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1);
202
- }
203
-
204
- const reference = randomString(16);
205
- const amount = 1200000;
206
- const currency = 'AUD';
207
- const message = [reference, amount, currency].join(':')
208
- const verification = CryptoJS.HmacMD5(message, "033bd94b11").toString();
209
-
210
- fz.verifyCard({
211
- customer: {
212
- firstName: 'Captain',
213
- lastName: 'America',
214
- email: 'sos@fatzebra.com.au',
215
- address: '123 Get High Blvd.',
216
- city: 'Red Light District',
217
- postcode: '6666',
218
- state: 'NSW',
219
- country: 'Australia'
220
- },
221
- paymentIntent: {
222
- payment: {
223
- amount: amount,
224
- currency: currency,
225
- reference: reference
226
- },
227
- verification: verification
228
- },
229
- paymentMethod: paymentMethod
230
- })
231
- })
232
-
233
- fz.on('fz.sca.error', function(event) {
234
- console.log(JSON.stringify(event.detail))
235
- })
236
-
237
- fz.on('fz.sca.success', function(event) {
238
- console.log(JSON.stringify(event.detail))
239
- })
240
-
241
- fz.on('fz.validation.error', function(event) {
242
- console.log(JSON.stringify(event.detail))
243
- })
244
- </script>
245
-
246
- </footer>
247
- </html>
@@ -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 += '&currency=' + 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 };