@tap-payments/apple-pay-button 1.0.0 → 1.0.2

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,54 +1,72 @@
1
- import { MerchantCapabilities } from '../constants';
2
- export var validateSupportedNetworks = function (supportedNetworksConfig, supportedNetworks) {
3
- var toLowerCase = function (item) { return item.toLowerCase(); };
4
- if (!supportedNetworks)
5
- return supportedNetworksConfig.map(toLowerCase);
6
- if (supportedNetworks.length === 0)
7
- return supportedNetworksConfig.map(toLowerCase);
8
- if (supportedNetworks.length > supportedNetworksConfig.length) {
9
- throw new Error("The supported networks list is not valid");
10
- }
11
- supportedNetworks.forEach(function (network) {
12
- var isSupported = supportedNetworksConfig.some(function (item) { return item.toLowerCase() === network.toLowerCase(); });
13
- if (!isSupported) {
14
- throw new Error("The supported network ".concat(network, " is not supported"));
15
- }
16
- });
17
- return supportedNetworks;
18
- };
19
- export var validateCurrency = function (currency, currencies) {
20
- var isSupported = currencies.some(function (item) { return item.toLowerCase() === currency.toLowerCase(); });
21
- if (!isSupported) {
22
- throw new Error("The currency \"".concat(currency, "\" is not supported, you have to use one of these currencies: ").concat(currencies));
23
- }
24
- return currency;
25
- };
26
- export var getApplePayRequest = function (_a) {
27
- var transaction = _a.transaction, billingContact = _a.billingContact, supportedNetworks = _a.supportedNetworks, countryCode = _a.countryCode, name = _a.name;
28
- return {
29
- countryCode: countryCode,
30
- currencyCode: transaction.currency,
31
- merchantCapabilities: [MerchantCapabilities.Supports3DS],
32
- supportedNetworks: supportedNetworks,
33
- billingContact: billingContact && {
34
- phoneNumber: billingContact.phone.code + billingContact.phone.number,
35
- emailAddress: billingContact.email.address,
36
- givenName: billingContact.name.first,
37
- familyName: billingContact.name.last
38
- },
39
- total: {
40
- amount: Number(transaction.amount),
41
- label: name
42
- }
43
- };
44
- };
45
- export var getApplePayPaymentMethod = function (paymentMethods) {
46
- var paymentMethod = paymentMethods.find(function (_a) {
47
- var name = _a.name, payment_type = _a.payment_type;
48
- return [name, payment_type].some(function (item) { return item.toLowerCase() === 'apple_pay'; });
49
- });
50
- if (!paymentMethod) {
51
- throw new Error('Apple Pay is not configured in your payment options');
52
- }
53
- return paymentMethod;
54
- };
1
+ import { MerchantCapabilities } from '../constants';
2
+ import { JSEncrypt } from 'jsencrypt';
3
+ export var validateSupportedNetworks = function (supportedNetworksConfig, supportedNetworks) {
4
+ var toLowerCase = function (item) { return item.toLowerCase(); };
5
+ if (!supportedNetworks)
6
+ return supportedNetworksConfig.map(toLowerCase);
7
+ if (supportedNetworks.length === 0)
8
+ return supportedNetworksConfig.map(toLowerCase);
9
+ if (supportedNetworks.length > supportedNetworksConfig.length) {
10
+ throw new Error("The supported networks list is not valid");
11
+ }
12
+ supportedNetworks.forEach(function (network) {
13
+ var isSupported = supportedNetworksConfig.some(function (item) { return item.toLowerCase() === network.toLowerCase(); });
14
+ if (!isSupported) {
15
+ throw new Error("The supported network ".concat(network, " is not supported"));
16
+ }
17
+ });
18
+ return supportedNetworks;
19
+ };
20
+ export var validateCurrency = function (currency, currencies) {
21
+ var isSupported = currencies.some(function (item) { return item.toLowerCase() === currency.toLowerCase(); });
22
+ if (!isSupported) {
23
+ throw new Error("The currency \"".concat(currency, "\" is not supported, you have to use one of these currencies: ").concat(currencies));
24
+ }
25
+ return currency;
26
+ };
27
+ export var getApplePayRequest = function (_a) {
28
+ var transaction = _a.transaction, billingContact = _a.billingContact, supportedNetworks = _a.supportedNetworks, countryCode = _a.countryCode, name = _a.name;
29
+ return {
30
+ countryCode: countryCode,
31
+ currencyCode: transaction.currency,
32
+ merchantCapabilities: [MerchantCapabilities.Supports3DS],
33
+ supportedNetworks: supportedNetworks,
34
+ billingContact: billingContact && {
35
+ phoneNumber: billingContact.phone.code + billingContact.phone.number,
36
+ emailAddress: billingContact.email.address,
37
+ givenName: billingContact.name.first,
38
+ familyName: billingContact.name.last
39
+ },
40
+ total: {
41
+ amount: Number(transaction.amount),
42
+ label: name
43
+ }
44
+ };
45
+ };
46
+ export var getApplePayPaymentMethod = function (paymentMethods) {
47
+ var paymentMethod = paymentMethods.find(function (_a) {
48
+ var name = _a.name, payment_type = _a.payment_type;
49
+ return [name, payment_type].some(function (item) { return item.toLowerCase() === 'apple_pay'; });
50
+ });
51
+ if (!paymentMethod) {
52
+ throw new Error('Apple Pay is not configured in your payment options');
53
+ }
54
+ return paymentMethod;
55
+ };
56
+ export var rsaSetup = function (key) {
57
+ var rsa = new JSEncrypt();
58
+ rsa.setPublicKey(key);
59
+ return function (string) {
60
+ if (typeof string !== 'string')
61
+ throw new Error('string should be from type string');
62
+ var encrypted = rsa.encrypt(string);
63
+ if (!encrypted)
64
+ throw new Error('encryption data reached max allowed length');
65
+ return encrypted;
66
+ };
67
+ };
68
+ export function generateApplicationHeader(obj) {
69
+ return Object.keys(obj)
70
+ .map(function (key) { return "".concat(key, "=").concat(obj[key]); })
71
+ .join('|');
72
+ }
@@ -1 +1 @@
1
- export declare const findOrCreateElementAndInject: (id: string) => HTMLElement;
1
+ export declare const findOrCreateElementAndInject: (id: string) => HTMLElement;
@@ -1,9 +1,9 @@
1
- export var findOrCreateElementAndInject = function (id) {
2
- var findElement = document.getElementById(id);
3
- if (findElement)
4
- return findElement;
5
- var element = document.createElement('div');
6
- element.setAttribute('id', id);
7
- document.body.appendChild(element);
8
- return element;
9
- };
1
+ export var findOrCreateElementAndInject = function (id) {
2
+ var findElement = document.getElementById(id);
3
+ if (findElement)
4
+ return findElement;
5
+ var element = document.createElement('div');
6
+ element.setAttribute('id', id);
7
+ document.body.appendChild(element);
8
+ return element;
9
+ };
@@ -1 +1 @@
1
- export * from './html';
1
+ export * from './html';
@@ -1 +1 @@
1
- export * from './html';
1
+ export * from './html';
package/package.json CHANGED
@@ -1,102 +1,104 @@
1
- {
2
- "name": "@tap-payments/apple-pay-button",
3
- "version": "1.0.0",
4
- "description": "Apple Pay Button React Component",
5
- "main": "build/index.js",
6
- "module": "build/index.js",
7
- "types": "build/index.d.ts",
8
- "files": [
9
- "build",
10
- "README.md"
11
- ],
12
- "scripts": {
13
- "prepare": "npx husky install",
14
- "prettier": "prettier --list-different \"src/**/*.{md,mdx,ts,js,tsx,jsx,json}\" *.json *.js",
15
- "prettier:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md,css,json}\" *.json *.js",
16
- "lint": "eslint src --color --ext .js,.jsx,.ts,.tsx,.json",
17
- "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
18
- "start": "cross-env NODE_ENV=development webpack serve",
19
- "build": "cross-env NODE_ENV=production webpack",
20
- "copy:files": "copyfiles -u 1 src/**/*.css build/",
21
- "tsc:alias": "tsc-alias -p tsconfig.json",
22
- "ts:build": "rm -rf build && tsc && yarn tsc:alias && yarn copy:files",
23
- "push": "npm publish --access public"
24
- },
25
- "keywords": [],
26
- "author": {
27
- "name": "Ahmed Elsharkawy",
28
- "email": "a.elsharkawy@tap.company"
29
- },
30
- "license": "ISC",
31
- "devDependencies": {
32
- "@babel/core": "^7.18.6",
33
- "@babel/preset-env": "^7.18.6",
34
- "@babel/preset-react": "^7.18.6",
35
- "@babel/preset-typescript": "^7.18.6",
36
- "@types/crypto-js": "^4.1.1",
37
- "@types/react": "^18.0.15",
38
- "@types/react-dom": "^18.0.6",
39
- "@typescript-eslint/eslint-plugin": "^5.30.5",
40
- "@typescript-eslint/parser": "^5.30.5",
41
- "babel-loader": "^8.2.5",
42
- "copyfiles": "^2.4.1",
43
- "cross-env": "^7.0.3",
44
- "css-loader": "^6.7.1",
45
- "css-minimizer-webpack-plugin": "^4.0.0",
46
- "eslint": "^8.19.0",
47
- "eslint-config-airbnb": "^19.0.4",
48
- "eslint-config-prettier": "^8.5.0",
49
- "eslint-plugin-import": "^2.26.0",
50
- "eslint-plugin-jsx-a11y": "^6.6.0",
51
- "eslint-plugin-node": "^11.1.0",
52
- "eslint-plugin-prettier": "^4.2.1",
53
- "eslint-plugin-react": "^7.30.1",
54
- "eslint-plugin-react-hooks": "^4.6.0",
55
- "file-loader": "^6.2.0",
56
- "fork-ts-checker-webpack-plugin": "^7.2.12",
57
- "html-loader": "^3.1.2",
58
- "html-webpack-plugin": "^5.5.0",
59
- "husky": "^8.0.1",
60
- "lint-staged": "^13.0.3",
61
- "mini-css-extract-plugin": "^2.6.1",
62
- "prettier": "^2.7.1",
63
- "sass": "^1.53.0",
64
- "sass-loader": "^13.0.2",
65
- "style-loader": "^3.3.1",
66
- "terser-webpack-plugin": "^5.3.3",
67
- "tsc-alias": "^1.6.11",
68
- "typescript": "^4.7.4",
69
- "webpack": "^5.73.0",
70
- "webpack-cli": "^4.10.0",
71
- "webpack-dev-server": "^4.9.3",
72
- "webpack-merge": "^5.8.0"
73
- },
74
- "dependencies": {
75
- "axios": "^1.2.2",
76
- "react": ">=17.0.2",
77
- "react-dom": ">=17.0.2"
78
- },
79
- "peerDependencies": {
80
- "react": ">=17.0.2",
81
- "react-dom": ">=17.0.2"
82
- },
83
- "lint-staged": {
84
- "src/**/*.{ts,tsx,json,js,jsx}": [
85
- "yarn run prettier:fix",
86
- "yarn run lint",
87
- "git add ."
88
- ]
89
- },
90
- "browserslist": {
91
- "production": [
92
- ">0.2%",
93
- "not dead",
94
- "not op_mini all"
95
- ],
96
- "development": [
97
- "last 1 chrome version",
98
- "last 1 firefox version",
99
- "last 1 safari version"
100
- ]
101
- }
102
- }
1
+ {
2
+ "name": "@tap-payments/apple-pay-button",
3
+ "version": "1.0.2",
4
+ "description": "Apple Pay Button React Component",
5
+ "main": "build/index.js",
6
+ "module": "build/index.js",
7
+ "types": "build/index.d.ts",
8
+ "files": [
9
+ "build",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "prepare": "npx husky install",
14
+ "prettier": "prettier --list-different \"src/**/*.{md,mdx,ts,js,tsx,jsx,json}\" *.json *.js",
15
+ "prettier:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md,css,json}\" *.json *.js",
16
+ "lint": "eslint src --color --ext .js,.jsx,.ts,.tsx,.json",
17
+ "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
18
+ "start": "cross-env NODE_ENV=development webpack serve",
19
+ "build": "cross-env NODE_ENV=production webpack",
20
+ "copy:files": "copyfiles -u 1 src/**/*.css build/",
21
+ "tsc:alias": "tsc-alias -p tsconfig.json",
22
+ "ts:build": "rm -rf build && tsc && yarn tsc:alias && yarn copy:files",
23
+ "push": "npm publish --access public"
24
+ },
25
+ "keywords": [],
26
+ "author": {
27
+ "name": "Ahmed Elsharkawy",
28
+ "email": "a.elsharkawy@tap.company"
29
+ },
30
+ "license": "ISC",
31
+ "devDependencies": {
32
+ "@babel/core": "^7.18.6",
33
+ "@babel/preset-env": "^7.18.6",
34
+ "@babel/preset-react": "^7.18.6",
35
+ "@babel/preset-typescript": "^7.18.6",
36
+ "@types/crypto-js": "^4.1.1",
37
+ "@types/react": "^18.0.15",
38
+ "@types/react-dom": "^18.0.6",
39
+ "@typescript-eslint/eslint-plugin": "^5.30.5",
40
+ "@typescript-eslint/parser": "^5.30.5",
41
+ "babel-loader": "^8.2.5",
42
+ "copyfiles": "^2.4.1",
43
+ "cross-env": "^7.0.3",
44
+ "css-loader": "^6.7.1",
45
+ "css-minimizer-webpack-plugin": "^4.0.0",
46
+ "eslint": "^8.19.0",
47
+ "eslint-config-airbnb": "^19.0.4",
48
+ "eslint-config-prettier": "^8.5.0",
49
+ "eslint-plugin-import": "^2.26.0",
50
+ "eslint-plugin-jsx-a11y": "^6.6.0",
51
+ "eslint-plugin-node": "^11.1.0",
52
+ "eslint-plugin-prettier": "^4.2.1",
53
+ "eslint-plugin-react": "^7.30.1",
54
+ "eslint-plugin-react-hooks": "^4.6.0",
55
+ "file-loader": "^6.2.0",
56
+ "fork-ts-checker-webpack-plugin": "^7.2.12",
57
+ "html-loader": "^3.1.2",
58
+ "html-webpack-plugin": "^5.5.0",
59
+ "husky": "^8.0.1",
60
+ "lint-staged": "^13.0.3",
61
+ "mini-css-extract-plugin": "^2.6.1",
62
+ "prettier": "^2.7.1",
63
+ "sass": "^1.53.0",
64
+ "sass-loader": "^13.0.2",
65
+ "style-loader": "^3.3.1",
66
+ "terser-webpack-plugin": "^5.3.3",
67
+ "tsc-alias": "^1.6.11",
68
+ "typescript": "^4.7.4",
69
+ "webpack": "^5.73.0",
70
+ "webpack-cli": "^4.10.0",
71
+ "webpack-dev-server": "^4.9.3",
72
+ "webpack-merge": "^5.8.0"
73
+ },
74
+ "dependencies": {
75
+ "@tap-payments/browser-info": "^1.0.2",
76
+ "axios": "^1.2.2",
77
+ "jsencrypt": "^3.3.2",
78
+ "react": ">=17.0.2",
79
+ "react-dom": ">=17.0.2"
80
+ },
81
+ "peerDependencies": {
82
+ "react": ">=17.0.2",
83
+ "react-dom": ">=17.0.2"
84
+ },
85
+ "lint-staged": {
86
+ "src/**/*.{ts,tsx,json,js,jsx}": [
87
+ "yarn run prettier:fix",
88
+ "yarn run lint",
89
+ "git add ."
90
+ ]
91
+ },
92
+ "browserslist": {
93
+ "production": [
94
+ ">0.2%",
95
+ "not dead",
96
+ "not op_mini all"
97
+ ],
98
+ "development": [
99
+ "last 1 chrome version",
100
+ "last 1 firefox version",
101
+ "last 1 safari version"
102
+ ]
103
+ }
104
+ }