@tap-payments/apple-pay-button 0.0.7-test → 1.0.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/README.md CHANGED
@@ -22,7 +22,7 @@ yarn add @tap-payments/apple-pay-button
22
22
 
23
23
  ### ES6
24
24
 
25
- ```js
25
+ ```javascript
26
26
  import React from 'react'
27
27
  import { ApplePayButton, ButtonStyle, SupportedNetworks, Scope } from '@tap-payments/apple-pay-button'
28
28
 
@@ -30,7 +30,7 @@ const App = () => {
30
30
  return (
31
31
  <ApplePayButton
32
32
  // required (The public Key provided by Tap)
33
- publicKey={'pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxzh'}
33
+ publicKey={'pk_test_xxxxxxxxxxxxxxxzh'}
34
34
  // required
35
35
  merchant={{
36
36
  // required (The merchant domain name)
@@ -95,8 +95,85 @@ const App = () => {
95
95
 
96
96
  ### Vanilla JS
97
97
 
98
- ```js
99
- // coming soon...
98
+ ```html
99
+ <!DOCTYPE html>
100
+ <html lang="en">
101
+ <head>
102
+ <meta charset="UTF-8" />
103
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
104
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
105
+ <title>apple pay button</title>
106
+ <link rel="stylesheet" href="https://apple-pay-button.b-cdn.net/build-1.0.0/main.css" />
107
+ <script src="https://apple-pay-button.b-cdn.net/build-1.0.0/main.js"></script>
108
+ </head>
109
+ <body>
110
+ <div id="apple-pay-button"></div>
111
+ <script type="text/javascript">
112
+ const { renderApplePayButton, ButtonStyle, Scope, SupportedNetworks } = window.TapSDKs
113
+ renderApplePayButton(
114
+ {
115
+ // required
116
+ publicKey: 'pk_test_xxxxxxxxxxxxxxxzh',
117
+ // required
118
+ merchant: {
119
+ // required
120
+ domain: 'example.com'
121
+ // optional
122
+ // id: '123...'
123
+ },
124
+ // required
125
+ transaction: {
126
+ // required
127
+ currency: 'USD',
128
+ // required
129
+ amount: '100'
130
+ },
131
+ // optional
132
+ scope: Scope.TapToken,
133
+ // optional
134
+ buttonStyle: ButtonStyle.WhiteOutline,
135
+ // optional
136
+ supportedNetworks: [SupportedNetworks.Visa, SupportedNetworks.MasterCard],
137
+ // optional (The billing contact information)
138
+ billingContact: {
139
+ // required
140
+ email: {
141
+ // required
142
+ address: 'test@gmail.com'
143
+ },
144
+ // required
145
+ name: {
146
+ // required
147
+ first: 'test',
148
+ // required
149
+ last: 'tester',
150
+ // optional
151
+ middle: 'test'
152
+ },
153
+ // required
154
+ phone: {
155
+ number: '10XXXXXX56',
156
+ code: '+20'
157
+ }
158
+ },
159
+ // optional
160
+ onCancel: () => {
161
+ console.log('onCancel')
162
+ },
163
+ // optional
164
+ onError: (error) => {
165
+ console.log('onError', error)
166
+ },
167
+ // optional
168
+ onSuccess: async (data) => {
169
+ console.log('onSuccess', data)
170
+ }
171
+ },
172
+ 'apple-pay-button'
173
+ )
174
+ </script>
175
+ </body>
176
+ </html>
100
177
  ```
101
178
 
102
179
  ## Configurations
@@ -1,51 +1,51 @@
1
- .button-applepay-tap {
2
- appearance: none;
3
- border: none;
4
- cursor: pointer;
5
- -webkit-user-select: none;
6
- user-select: none;
7
- display: flex;
8
- position: relative;
9
- -webkit-box-pack: center;
10
- -ms-flex-pack: center;
11
- -webkit-justify-content: center;
12
- justify-content: center;
13
- -webkit-align-items: center;
14
- -webkit-box-align: center;
15
- -ms-flex-align: center;
16
- align-items: center;
17
- -webkit-margin-end: 8px;
18
- margin-inline-end: 8px;
19
- min-width: 96px;
20
- max-width: 300px;
21
- min-height: 40px;
22
- border-radius: 9px;
23
- background-color: white;
24
- width: 100%;
25
- }
26
-
27
- .button-applepay-tap:disabled {
28
- cursor: default;
29
- }
30
-
31
- .img-container {
32
- height: 24px;
33
- max-width: 80px;
34
- }
35
-
36
- .img-container img {
37
- height: 100%;
38
- width: 100%;
39
- transform: scale(1.5);
40
- filter: invert(0);
41
- }
42
-
43
- .whiteOutline {
44
- border: solid 1px gray;
45
- }
46
- .dark {
47
- background-color: black;
48
- }
49
- .dark .img-container img {
50
- filter: invert(1);
51
- }
1
+ .button-applepay-tap {
2
+ appearance: none;
3
+ border: none;
4
+ cursor: pointer;
5
+ -webkit-user-select: none;
6
+ user-select: none;
7
+ display: flex;
8
+ position: relative;
9
+ -webkit-box-pack: center;
10
+ -ms-flex-pack: center;
11
+ -webkit-justify-content: center;
12
+ justify-content: center;
13
+ -webkit-align-items: center;
14
+ -webkit-box-align: center;
15
+ -ms-flex-align: center;
16
+ align-items: center;
17
+ -webkit-margin-end: 8px;
18
+ margin-inline-end: 8px;
19
+ min-width: 96px;
20
+ max-width: 300px;
21
+ min-height: 40px;
22
+ border-radius: 9px;
23
+ background-color: white;
24
+ width: 100%;
25
+ }
26
+
27
+ .button-applepay-tap:disabled {
28
+ cursor: default;
29
+ }
30
+
31
+ .img-container {
32
+ height: 24px;
33
+ max-width: 80px;
34
+ }
35
+
36
+ .img-container img {
37
+ height: 100%;
38
+ width: 100%;
39
+ transform: scale(1.5);
40
+ filter: invert(0);
41
+ }
42
+
43
+ .whiteOutline {
44
+ border: solid 1px gray;
45
+ }
46
+ .dark {
47
+ background-color: black;
48
+ }
49
+ .dark .img-container img {
50
+ filter: invert(1);
51
+ }
@@ -3,6 +3,4 @@ import { ApplePayButtonProps } from '../../@types';
3
3
  import './ApplePayButton.css';
4
4
  export type { ApplePayButtonProps };
5
5
  export declare function ApplePayButton(props: ApplePayButtonProps): JSX.Element;
6
- export declare function renderApplePayButton(config: ApplePayButtonProps, elementId: string): {
7
- unmount: () => void;
8
- };
6
+ export declare const renderApplePayButton: (props: ApplePayButtonProps, elementId: string) => any;
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import React from 'react';
14
14
  import { createRoot } from 'react-dom/client';
15
- import { createElementAndInject } from '../../utils';
15
+ import { findOrCreateElementAndInject } from '../../utils';
16
16
  import { useApplePay } from '../../hooks/useApplePay';
17
17
  import { ButtonStyle, Scope } from '../../constants';
18
18
  import './ApplePayButton.css';
@@ -34,10 +34,18 @@ var ApplePay = React.memo(function (_a) {
34
34
  export function ApplePayButton(props) {
35
35
  return _jsx(ApplePay, __assign({}, props));
36
36
  }
37
- export function renderApplePayButton(config, elementId) {
38
- var el = createElementAndInject(elementId);
37
+ var tapConnectInstance = null;
38
+ export var renderApplePayButton = function (props, elementId) {
39
+ if (tapConnectInstance) {
40
+ return tapConnectInstance;
41
+ }
42
+ var el = findOrCreateElementAndInject(elementId);
39
43
  var root = createRoot(el);
40
- root.render(_jsx(ApplePay, __assign({}, config)));
41
- var unmount = function () { return root.unmount(); };
42
- return { unmount: unmount };
43
- }
44
+ root.render(_jsx(ApplePayButton, __assign({}, props)));
45
+ var unmount = function () {
46
+ root.unmount();
47
+ tapConnectInstance = null;
48
+ };
49
+ tapConnectInstance = { unmount: unmount };
50
+ return tapConnectInstance;
51
+ };
@@ -1,3 +1 @@
1
- export declare const createElementAndInject: (id: string) => HTMLDivElement;
2
- export declare const reactElement: (elementId: string) => import("react-dom/client").Root;
3
- export declare const removeElement: (elementId: string) => void;
1
+ export declare const findOrCreateElementAndInject: (id: string) => HTMLElement;
@@ -1,20 +1,9 @@
1
- import { createRoot } from 'react-dom/client';
2
- export var createElementAndInject = function (id) {
1
+ export var findOrCreateElementAndInject = function (id) {
2
+ var findElement = document.getElementById(id);
3
+ if (findElement)
4
+ return findElement;
3
5
  var element = document.createElement('div');
4
6
  element.setAttribute('id', id);
5
7
  document.body.appendChild(element);
6
8
  return element;
7
9
  };
8
- export var reactElement = function (elementId) {
9
- var element = document.getElementById(elementId);
10
- if (!element) {
11
- element = createElementAndInject('tap-apple-pay-sdk-element');
12
- }
13
- return createRoot(element);
14
- };
15
- export var removeElement = function (elementId) {
16
- var el = document.getElementById(elementId);
17
- if (!el)
18
- return;
19
- el.remove();
20
- };
package/package.json CHANGED
@@ -1,102 +1,102 @@
1
- {
2
- "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.7-test",
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.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
+ }