@fat-zebra/sdk 1.5.3-beta.1 → 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.
@@ -0,0 +1,247 @@
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>
@@ -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.2";
1
+ export declare const version = "1.5.3-beta.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.5.2';
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-beta.1",
3
+ "version": "1.5.3-beta.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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.js"
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
  },
@@ -3,8 +3,8 @@
3
3
  "declaration": true,
4
4
  "outDir": "./dist/",
5
5
  "jsx": "react",
6
- "skipLibCheck": true,
7
6
  "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
8
  "sourceMap": false,
9
9
  "noImplicitAny": true,
10
10
  "module": "esnext",
@@ -1,113 +0,0 @@
1
- const { execSync } = require('child_process');
2
- const shell = process.env.SHELL;
3
-
4
- const readline = require('node:readline').createInterface({
5
- input: process.stdin,
6
- output: process.stdout,
7
- });
8
- const fs = require('fs');
9
- const path = require('path');
10
- /**
11
- * Builds and publishes to npm (for production)
12
- *
13
- */
14
- function publish() {
15
- console.log("running build...");
16
- try {
17
- // Running the command synchronously and inheriting the shell
18
- execSync(`${shell} -c "npm run build:package && npm publish"`, { stdio: 'inherit' });
19
- } catch (error) {
20
- // This will catch any errors that occur during the execution of the command
21
- console.error(`Execution error: ${error}`);
22
- console.error(`stderr: ${error.stderr}`);
23
- }
24
- }
25
-
26
- /**
27
- * Writes version number to package.json and to another file to read from
28
- *
29
- * @param {string} path - path to where the file will be written (package.json | version.ts).
30
- * @param {string} content - content of file (version number).
31
- */
32
- function writeToFile(path, content) {
33
- fs.writeFileSync(path, content, 'utf8', (err) => {
34
- if (err) {
35
- console.error('Error writing version to file:', err);
36
- } else {
37
- console.log(`content: ${content} written to ${path}`);
38
- }
39
- });
40
- }
41
-
42
- /**
43
- * take data from package.json and applies increment (depending on major/minor upgrade)
44
- *
45
- * @param {string} data - package.json data
46
- * @param {string} releaseType - minor or major release
47
- * @returns {Object|null} The updated package.json object with the incremented version, or null if parsing fails.
48
- */
49
- function increment(data, releaseType) {
50
- let packageJson;
51
- try {
52
- packageJson = JSON.parse(data);
53
- } catch (parseErr) {
54
- console.error('Error parsing package.json:', parseErr);
55
- return;
56
- }
57
-
58
- let [major, minor, patch] = packageJson.version.split('.').map(Number);
59
-
60
- if (releaseType === 'minor') {
61
- minor++;
62
- patch = 0; // Reset patch version on minor update
63
- } else {
64
- patch++;
65
- }
66
-
67
- packageJson.version = [major, minor, patch].join('.');
68
- return packageJson
69
- }
70
-
71
- /**
72
- * Increments the version number in package.json based on the release type.
73
- *
74
- * @param {string} releaseType - The type of release (minor or patch).
75
- */
76
- function incrementAndPublish(releaseType) {
77
- const packagePath = path.join(__dirname, '../package.json');
78
- const versionPath = path.join(__dirname, '../src/version.ts')
79
- fs.readFile(packagePath, 'utf8', (err, data) => {
80
- if (err) {
81
- console.error('Error reading package.json:', err);
82
- return;
83
- }
84
-
85
- let packageJson = increment(data, releaseType)
86
-
87
- writeToFile(packagePath, JSON.stringify(packageJson, null, 2))
88
- const fileContent = `export const version = '${packageJson.version}';\n`;
89
- writeToFile(versionPath, fileContent)
90
- publish()
91
- });
92
- }
93
-
94
- /**
95
- * Asks the user whether the release is a minor release or a patch.
96
- */
97
- function askReleaseType() {
98
- readline.question(`enter (y) for minor release or (n) for patch release `, releaseType => {
99
- releaseType = releaseType.trim().toLowerCase();
100
-
101
- if (releaseType === 'y') {
102
- incrementAndPublish('minor');
103
- } else if (releaseType === 'n') {
104
- incrementAndPublish('patch');
105
- } else {
106
- console.log("Please answer 'y' (yes) or 'n' (no).");
107
- askReleaseType(); // Recursively ask again if the input is not y/n
108
- }
109
- });
110
- }
111
-
112
- askReleaseType();
113
-