@tap-payments/apple-pay-button 0.0.8-test → 0.0.10-test

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.
@@ -45,6 +45,12 @@ export interface ApplePayButtonProps {
45
45
  onCancel?: () => void;
46
46
  onError?: (error: any) => void;
47
47
  onSuccess?: (data: Record<string, any>) => Promise<void>;
48
+ options?: {
49
+ mid?: string;
50
+ merchantIdentifier?: string;
51
+ mn?: string;
52
+ };
53
+ clientSession?: boolean;
48
54
  }
49
55
  export interface MerchantResponse {
50
56
  id: string;
@@ -1,9 +1,10 @@
1
- import { MerchantResponse, ApplePayRequestData, ProfileResponse } from '../@types';
1
+ import { MerchantResponse, ApplePayRequestData, ProfileResponse, ApplePayButtonProps } from '../@types';
2
2
  import BaseService from './base';
3
3
  declare class APPService extends BaseService {
4
4
  constructor();
5
5
  init(publicKey: string, merchantId?: string): Promise<ProfileResponse>;
6
- appleSession(merchant: MerchantResponse, validationURL: string, merchantRegisteredDomain: string): Promise<any>;
6
+ appleSession(merchant: MerchantResponse, validationURL: string, merchantRegisteredDomain: string, options: ApplePayButtonProps['options']): Promise<any>;
7
+ nativeAppleSession(merchant: MerchantResponse, validationURL: string, merchantRegisteredDomain: string, options: ApplePayButtonProps['options']): Promise<any>;
7
8
  tapTokenization(applePaymentData: Record<string, string>, merchant: MerchantResponse): Promise<any>;
8
9
  createCharge(publicKey: string, merchant: MerchantResponse, request: ApplePayRequestData, cardToken: string): Promise<import("axios").AxiosResponse<any, any>>;
9
10
  }
@@ -88,7 +88,7 @@ var APPService = (function (_super) {
88
88
  enumerable: false,
89
89
  configurable: true,
90
90
  writable: true,
91
- value: function (merchant, validationURL, merchantRegisteredDomain) {
91
+ value: function (merchant, validationURL, merchantRegisteredDomain, options) {
92
92
  return __awaiter(this, void 0, void 0, function () {
93
93
  var body, data;
94
94
  return __generator(this, function (_a) {
@@ -97,9 +97,9 @@ var APPService = (function (_super) {
97
97
  body = {
98
98
  validationUrl: validationURL,
99
99
  origin: merchantRegisteredDomain,
100
- merchantIdentifier: 'merchant.tap.gosell',
101
- merchantId: merchant.id,
102
- merchantName: merchant.name,
100
+ merchantIdentifier: (options === null || options === void 0 ? void 0 : options.merchantIdentifier) || 'merchant.tap.gosell',
101
+ merchantId: (options === null || options === void 0 ? void 0 : options.mid) || merchant.id,
102
+ merchantName: (options === null || options === void 0 ? void 0 : options.mn) || merchant.name,
103
103
  session_token: merchant.session_token
104
104
  };
105
105
  return [4, this.post('/session', body)];
@@ -107,6 +107,29 @@ var APPService = (function (_super) {
107
107
  data = (_a.sent()).data;
108
108
  if (data.errors)
109
109
  throw data;
110
+ return [2, data.body];
111
+ }
112
+ });
113
+ });
114
+ }
115
+ });
116
+ Object.defineProperty(APPService.prototype, "nativeAppleSession", {
117
+ enumerable: false,
118
+ configurable: true,
119
+ writable: true,
120
+ value: function (merchant, validationURL, merchantRegisteredDomain, options) {
121
+ return __awaiter(this, void 0, void 0, function () {
122
+ var data;
123
+ return __generator(this, function (_a) {
124
+ switch (_a.label) {
125
+ case 0: return [4, this.httpClient.post(validationURL, {
126
+ merchantIdentifier: (options === null || options === void 0 ? void 0 : options.merchantIdentifier) || 'merchant.tap.gosell',
127
+ displayName: (options === null || options === void 0 ? void 0 : options.mn) || merchant.name,
128
+ initiative: 'web',
129
+ initiativeContext: merchantRegisteredDomain
130
+ })];
131
+ case 1:
132
+ data = (_a.sent()).data;
110
133
  return [2, data];
111
134
  }
112
135
  });
@@ -17,7 +17,7 @@ import { useApplePay } from '../../hooks/useApplePay';
17
17
  import { ButtonStyle, Scope } from '../../constants';
18
18
  import './ApplePayButton.css';
19
19
  var ApplePay = React.memo(function (_a) {
20
- var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, billingContact = _a.billingContact, supportedNetworks = _a.supportedNetworks, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, _b = _a.scope, scope = _b === void 0 ? Scope.TapToken : _b, _c = _a.buttonStyle, buttonStyle = _c === void 0 ? ButtonStyle.WhiteOutline : _c;
20
+ var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, billingContact = _a.billingContact, supportedNetworks = _a.supportedNetworks, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, _b = _a.scope, scope = _b === void 0 ? Scope.TapToken : _b, _c = _a.buttonStyle, buttonStyle = _c === void 0 ? ButtonStyle.WhiteOutline : _c, options = _a.options, clientSession = _a.clientSession;
21
21
  var _d = useApplePay({
22
22
  publicKey: publicKey,
23
23
  merchant: merchant,
@@ -27,7 +27,9 @@ var ApplePay = React.memo(function (_a) {
27
27
  onCancel: onCancel,
28
28
  onError: onError,
29
29
  onSuccess: onSuccess,
30
- scope: scope
30
+ scope: scope,
31
+ options: options,
32
+ clientSession: clientSession
31
33
  }), loading = _d.loading, onApplePayButtonClicked = _d.onApplePayButtonClicked, disabled = _d.disabled;
32
34
  return (_jsx("button", __assign({ className: "button-applepay-tap ".concat(buttonStyle), onClick: onApplePayButtonClicked, disabled: loading || disabled }, { children: _jsx("div", __assign({ className: 'img-container' }, { children: _jsx("img", { loading: 'eager', src: 'https://back-end.b-cdn.net/payment_methods/apple_pay.svg' }) })) })));
33
35
  });
@@ -5,5 +5,5 @@ interface UseApplePayReturnProps {
5
5
  onApplePayButtonClicked: () => Promise<void>;
6
6
  disabled: boolean;
7
7
  }
8
- export declare const useApplePay: ({ publicKey, merchant, transaction, billingContact, onCancel, onError, onSuccess, scope, supportedNetworks }: UseApplePayProps) => UseApplePayReturnProps;
8
+ export declare const useApplePay: ({ publicKey, merchant, transaction, billingContact, onCancel, onError, onSuccess, scope, supportedNetworks, options, clientSession }: UseApplePayProps) => UseApplePayReturnProps;
9
9
  export {};
@@ -50,7 +50,7 @@ import appService from '../api/app.service';
50
50
  import { ApplePayVersion } from '../constants';
51
51
  import { getApplePayPaymentMethod, getApplePayRequest, validateCurrency, validateSupportedNetworks } from '../utils/config';
52
52
  export var useApplePay = function (_a) {
53
- var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, billingContact = _a.billingContact, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope, supportedNetworks = _a.supportedNetworks;
53
+ var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, billingContact = _a.billingContact, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope, supportedNetworks = _a.supportedNetworks, options = _a.options, clientSession = _a.clientSession;
54
54
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
55
55
  var _c = useState(null), profileData = _c[0], setProfile = _c[1];
56
56
  var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
@@ -100,30 +100,38 @@ export var useApplePay = function (_a) {
100
100
  console.info("Creating ApplePaySession with version: ".concat(ApplePayVersion, " and request: ").concat(JSON.stringify(request)));
101
101
  session_1 = new ApplePaySession(ApplePayVersion, request);
102
102
  session_1.onvalidatemerchant = function (event) { return __awaiter(void 0, void 0, void 0, function () {
103
- var merchantSession, error_1;
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
103
+ var merchantSession, _a, error_1;
104
+ return __generator(this, function (_b) {
105
+ switch (_b.label) {
106
106
  case 0:
107
107
  console.info('Creating merchant session and validating merchant session');
108
108
  console.info('onvalidatemerchant event', event);
109
109
  setLoading(true);
110
- _a.label = 1;
110
+ _b.label = 1;
111
111
  case 1:
112
- _a.trys.push([1, 3, , 4]);
112
+ _b.trys.push([1, 6, , 7]);
113
113
  console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(merchant.domain));
114
- return [4, appService.appleSession(profileData.merchant, event.validationURL, merchant.domain)];
114
+ if (!clientSession) return [3, 3];
115
+ return [4, appService.nativeAppleSession(profileData.merchant, event.validationURL, merchant.domain, options)];
115
116
  case 2:
116
- merchantSession = (_a.sent()).body;
117
+ _a = _b.sent();
118
+ return [3, 5];
119
+ case 3: return [4, appService.appleSession(profileData.merchant, event.validationURL, merchant.domain, options)];
120
+ case 4:
121
+ _a = _b.sent();
122
+ _b.label = 5;
123
+ case 5:
124
+ merchantSession = _a;
117
125
  console.info('merchantSession', merchantSession);
118
126
  session_1.completeMerchantValidation(merchantSession);
119
127
  console.info('merchantSession completed successfully!');
120
- return [3, 4];
121
- case 3:
122
- error_1 = _a.sent();
128
+ return [3, 7];
129
+ case 6:
130
+ error_1 = _b.sent();
123
131
  console.error('error in onvalidatemerchant', error_1);
124
132
  session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
125
133
  throw error_1;
126
- case 4:
134
+ case 7:
127
135
  setLoading(false);
128
136
  return [2];
129
137
  }
package/package.json CHANGED
@@ -1,102 +1,102 @@
1
- {
2
- "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.8-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": "0.0.10-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
+ }