@tap-payments/apple-pay-button 0.0.1 → 0.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.
- package/build/@types/index.d.ts +6 -3
- package/build/api/app.service.d.ts +16 -4
- package/build/api/app.service.js +131 -95
- package/build/api/httpClient.d.ts +6 -0
- package/build/api/httpClient.js +19 -2
- package/build/constants/index.d.ts +12 -0
- package/build/constants/index.js +12 -0
- package/build/features/ApplePayButton/ApplePayButton.css +0 -2
- package/build/features/ApplePayButton/ApplePayButton.js +5 -2
- package/build/hooks/useApplePay.d.ts +1 -1
- package/build/hooks/useApplePay.js +48 -28
- package/build/index.d.ts +2 -2
- package/build/index.js +4 -3
- package/build/utils/config.d.ts +2 -0
- package/build/utils/config.js +18 -0
- package/package.json +3 -1
package/build/@types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Scope, ButtonStyle, MerchantCapabilities, SupportedNetworks, ButtonType, Locale } from '../constants';
|
|
1
|
+
import { Scope, ButtonStyle, MerchantCapabilities, SupportedNetworks, ButtonType, Locale, Environment } from '../constants';
|
|
2
2
|
export interface ApplePayRequestData {
|
|
3
3
|
countryCode: string;
|
|
4
4
|
currencyCode: string;
|
|
@@ -17,6 +17,7 @@ export interface ApplePayRequestData {
|
|
|
17
17
|
}
|
|
18
18
|
export interface ApplePayButtonProps {
|
|
19
19
|
publicKey: string;
|
|
20
|
+
environment: typeof Environment[keyof typeof Environment];
|
|
20
21
|
merchantIdentifier: string;
|
|
21
22
|
merchant: {
|
|
22
23
|
id?: string;
|
|
@@ -47,7 +48,8 @@ export interface ApplePayButtonProps {
|
|
|
47
48
|
onError?: (error: any) => void;
|
|
48
49
|
onSuccess?: (data: Record<string, any>) => Promise<void>;
|
|
49
50
|
onClick?: () => void;
|
|
50
|
-
|
|
51
|
+
onReady?: () => void;
|
|
52
|
+
metaData?: MetaData;
|
|
51
53
|
type?: typeof ButtonType[keyof typeof ButtonType];
|
|
52
54
|
locale?: typeof Locale[keyof typeof Locale];
|
|
53
55
|
debug?: boolean;
|
|
@@ -73,7 +75,8 @@ export interface PaymentOptionsResponse {
|
|
|
73
75
|
currency: string;
|
|
74
76
|
payment_methods: PaymentMethod[];
|
|
75
77
|
}
|
|
76
|
-
export interface
|
|
78
|
+
export interface MetaData {
|
|
77
79
|
merchant: MerchantResponse;
|
|
78
80
|
payment_options: PaymentOptionsResponse;
|
|
81
|
+
headers: Record<string, string>;
|
|
79
82
|
}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { MerchantResponse,
|
|
1
|
+
import { MerchantResponse, ApplePayButtonProps } from '../@types';
|
|
2
2
|
import BaseService from './base';
|
|
3
3
|
declare class APPService extends BaseService {
|
|
4
|
+
private baseUrl;
|
|
5
|
+
private env;
|
|
4
6
|
constructor();
|
|
5
|
-
|
|
7
|
+
setEnv(env: ApplePayButtonProps['environment']): void;
|
|
8
|
+
setBaseUrl(): void;
|
|
9
|
+
getHeaderPublicKey(): "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----" | "" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
|
|
10
|
+
setBrowserHeaders({ locale, pk, domain }: {
|
|
11
|
+
locale: string;
|
|
12
|
+
pk: string;
|
|
13
|
+
domain: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
checkoutProfile(merchantId?: string): Promise<{
|
|
16
|
+
merchant: any;
|
|
17
|
+
payment_options: any;
|
|
18
|
+
}>;
|
|
6
19
|
appleSession(merchant: MerchantResponse, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string): Promise<any>;
|
|
7
|
-
tapTokenization(applePaymentData: Record<string, string
|
|
8
|
-
createCharge(publicKey: string, merchant: MerchantResponse, request: ApplePayRequestData, cardToken: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
20
|
+
tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
|
|
9
21
|
}
|
|
10
22
|
declare const appService: APPService;
|
|
11
23
|
export default appService;
|
package/build/api/app.service.js
CHANGED
|
@@ -49,36 +49,146 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
53
|
+
var t = {};
|
|
54
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
55
|
+
t[p] = s[p];
|
|
56
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
57
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
58
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
59
|
+
t[p[i]] = s[p[i]];
|
|
60
|
+
}
|
|
61
|
+
return t;
|
|
62
|
+
};
|
|
52
63
|
import BaseService from './base';
|
|
53
|
-
import httpClient from './httpClient';
|
|
64
|
+
import httpClient, { setAxiosGlobalHeaders, MW_BASE_BETA_URL, MW_BASE_DEV_URL, MW_BASE_LIVE_URL, MW_BASE_STAGING_URL, MW_BASE_SANDBOX_URL } from './httpClient';
|
|
65
|
+
import BrowserInfo from '@tap-payments/browser-info';
|
|
66
|
+
import { generateApplicationHeader, rsaSetup } from '../utils/config';
|
|
67
|
+
import { RSA_BETA_MW_PUBLIC_KEY, RSA_DEV_MW_PUBLIC_KEY, RSA_PRODUCTION_MW_PUBLIC_KEY, RSA_SANDBOX_MW_PUBLIC_KEY, RSA_STAGING_MW_PUBLIC_KEY } from '../constants';
|
|
54
68
|
var APPService = (function (_super) {
|
|
55
69
|
__extends(APPService, _super);
|
|
56
70
|
function APPService() {
|
|
57
|
-
|
|
71
|
+
var _this = _super.call(this, httpClient) || this;
|
|
72
|
+
Object.defineProperty(_this, "baseUrl", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(_this, "env", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: void 0
|
|
83
|
+
});
|
|
84
|
+
_this.baseUrl = MW_BASE_LIVE_URL;
|
|
85
|
+
_this.env = 'production';
|
|
86
|
+
return _this;
|
|
58
87
|
}
|
|
59
|
-
Object.defineProperty(APPService.prototype, "
|
|
88
|
+
Object.defineProperty(APPService.prototype, "setEnv", {
|
|
89
|
+
enumerable: false,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: function (env) {
|
|
93
|
+
this.env = env;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(APPService.prototype, "setBaseUrl", {
|
|
97
|
+
enumerable: false,
|
|
98
|
+
configurable: true,
|
|
99
|
+
writable: true,
|
|
100
|
+
value: function () {
|
|
101
|
+
if (!this.env)
|
|
102
|
+
throw new Error('Environment is not set');
|
|
103
|
+
switch (this.env) {
|
|
104
|
+
case 'staging':
|
|
105
|
+
this.baseUrl = MW_BASE_STAGING_URL;
|
|
106
|
+
break;
|
|
107
|
+
case 'beta':
|
|
108
|
+
this.baseUrl = MW_BASE_BETA_URL;
|
|
109
|
+
break;
|
|
110
|
+
case 'development':
|
|
111
|
+
this.baseUrl = MW_BASE_DEV_URL;
|
|
112
|
+
break;
|
|
113
|
+
case 'sandbox':
|
|
114
|
+
this.baseUrl = MW_BASE_SANDBOX_URL;
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
this.baseUrl = MW_BASE_LIVE_URL;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(APPService.prototype, "getHeaderPublicKey", {
|
|
123
|
+
enumerable: false,
|
|
124
|
+
configurable: true,
|
|
125
|
+
writable: true,
|
|
126
|
+
value: function () {
|
|
127
|
+
if (!this.env)
|
|
128
|
+
throw new Error('Environment is not set');
|
|
129
|
+
switch (this.env) {
|
|
130
|
+
case 'staging':
|
|
131
|
+
return RSA_STAGING_MW_PUBLIC_KEY;
|
|
132
|
+
case 'beta':
|
|
133
|
+
return RSA_BETA_MW_PUBLIC_KEY;
|
|
134
|
+
case 'development':
|
|
135
|
+
return RSA_DEV_MW_PUBLIC_KEY;
|
|
136
|
+
case 'sandbox':
|
|
137
|
+
return RSA_SANDBOX_MW_PUBLIC_KEY;
|
|
138
|
+
default:
|
|
139
|
+
return RSA_PRODUCTION_MW_PUBLIC_KEY;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(APPService.prototype, "setBrowserHeaders", {
|
|
60
144
|
enumerable: false,
|
|
61
145
|
configurable: true,
|
|
62
146
|
writable: true,
|
|
63
|
-
value: function (
|
|
147
|
+
value: function (_a) {
|
|
148
|
+
var locale = _a.locale, pk = _a.pk, domain = _a.domain;
|
|
64
149
|
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var
|
|
150
|
+
var encryptString, encryptedHeaders, mdn, authorization, rest, application;
|
|
151
|
+
return __generator(this, function (_b) {
|
|
152
|
+
switch (_b.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
encryptString = rsaSetup(this.getHeaderPublicKey());
|
|
155
|
+
return [4, new BrowserInfo.BrowserInfo({
|
|
156
|
+
app: { name: '@tap-payments/apple-pay-button', language: locale },
|
|
157
|
+
credentials: { mdn: domain, pk: pk },
|
|
158
|
+
encrypt: function (_key, value) { return encryptString(value); }
|
|
159
|
+
}).get()];
|
|
160
|
+
case 1:
|
|
161
|
+
encryptedHeaders = _b.sent();
|
|
162
|
+
mdn = encryptedHeaders.mdn, authorization = encryptedHeaders.authorization, rest = __rest(encryptedHeaders, ["mdn", "authorization"]);
|
|
163
|
+
application = generateApplicationHeader(rest);
|
|
164
|
+
setAxiosGlobalHeaders({
|
|
165
|
+
authorization: pk,
|
|
166
|
+
mdn: mdn,
|
|
167
|
+
application: application
|
|
168
|
+
});
|
|
169
|
+
return [2];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
Object.defineProperty(APPService.prototype, "checkoutProfile", {
|
|
176
|
+
enumerable: false,
|
|
177
|
+
configurable: true,
|
|
178
|
+
writable: true,
|
|
179
|
+
value: function (merchantId) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
+
var data, merchant, payment_options, session;
|
|
66
182
|
return __generator(this, function (_a) {
|
|
67
183
|
switch (_a.label) {
|
|
68
|
-
case 0:
|
|
69
|
-
body = {
|
|
70
|
-
headers: { authorization: "Bearer ".concat(publicKey) },
|
|
71
|
-
reqBody: { public_key: publicKey, merchant_id: merchantId }
|
|
72
|
-
};
|
|
73
|
-
return [4, this.post('/init', body)];
|
|
184
|
+
case 0: return [4, this.post(this.baseUrl + '/checkoutprofile', { merchant_id: merchantId !== null && merchantId !== void 0 ? merchantId : '' })];
|
|
74
185
|
case 1:
|
|
75
186
|
data = (_a.sent()).data;
|
|
76
187
|
if (data.errors)
|
|
77
188
|
throw data;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}];
|
|
189
|
+
merchant = data.merchant, payment_options = data.payment_options, session = data.session;
|
|
190
|
+
setAxiosGlobalHeaders({ session: session });
|
|
191
|
+
return [2, { merchant: merchant, payment_options: payment_options }];
|
|
82
192
|
}
|
|
83
193
|
});
|
|
84
194
|
});
|
|
@@ -99,10 +209,9 @@ var APPService = (function (_super) {
|
|
|
99
209
|
origin: merchantRegisteredDomain,
|
|
100
210
|
merchantIdentifier: merchantIdentifier,
|
|
101
211
|
merchantId: merchant.id,
|
|
102
|
-
merchantName: merchant.name
|
|
103
|
-
session_token: merchant.session_token
|
|
212
|
+
merchantName: merchant.name
|
|
104
213
|
};
|
|
105
|
-
return [4, this.post('/
|
|
214
|
+
return [4, this.post(this.baseUrl + '/validatemerchant', body)];
|
|
106
215
|
case 1:
|
|
107
216
|
data = (_a.sent()).data;
|
|
108
217
|
if (data.errors)
|
|
@@ -117,24 +226,17 @@ var APPService = (function (_super) {
|
|
|
117
226
|
enumerable: false,
|
|
118
227
|
configurable: true,
|
|
119
228
|
writable: true,
|
|
120
|
-
value: function (applePaymentData
|
|
229
|
+
value: function (applePaymentData) {
|
|
121
230
|
return __awaiter(this, void 0, void 0, function () {
|
|
122
231
|
var body, data;
|
|
123
232
|
return __generator(this, function (_a) {
|
|
124
233
|
switch (_a.label) {
|
|
125
234
|
case 0:
|
|
126
235
|
body = {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
headers: {
|
|
130
|
-
session_token: merchant.session_token
|
|
131
|
-
},
|
|
132
|
-
reqBody: {
|
|
133
|
-
type: 'applepay',
|
|
134
|
-
token_data: applePaymentData
|
|
135
|
-
}
|
|
236
|
+
type: 'applepay',
|
|
237
|
+
token_data: applePaymentData
|
|
136
238
|
};
|
|
137
|
-
return [4, this.post('/
|
|
239
|
+
return [4, this.post(this.baseUrl + '/token', body)];
|
|
138
240
|
case 1:
|
|
139
241
|
data = (_a.sent()).data;
|
|
140
242
|
if (data.errors)
|
|
@@ -145,72 +247,6 @@ var APPService = (function (_super) {
|
|
|
145
247
|
});
|
|
146
248
|
}
|
|
147
249
|
});
|
|
148
|
-
Object.defineProperty(APPService.prototype, "createCharge", {
|
|
149
|
-
enumerable: false,
|
|
150
|
-
configurable: true,
|
|
151
|
-
writable: true,
|
|
152
|
-
value: function (publicKey, merchant, request, cardToken) {
|
|
153
|
-
var body = {
|
|
154
|
-
method: 'POST',
|
|
155
|
-
path: '/v2/charge',
|
|
156
|
-
headers: {
|
|
157
|
-
session_token: merchant.session_token
|
|
158
|
-
},
|
|
159
|
-
reqBody: {
|
|
160
|
-
id: null,
|
|
161
|
-
amount: request.total.amount,
|
|
162
|
-
currency: request.currencyCode,
|
|
163
|
-
public_key: publicKey,
|
|
164
|
-
product: 'GOSELL',
|
|
165
|
-
threeDSecure: true,
|
|
166
|
-
save_card: false,
|
|
167
|
-
fee: 0,
|
|
168
|
-
statement_descriptor: 'Sample',
|
|
169
|
-
description: 'Test Description',
|
|
170
|
-
metadata: {},
|
|
171
|
-
reference: {
|
|
172
|
-
transaction: 'txn_0001',
|
|
173
|
-
order: 'ord_0001'
|
|
174
|
-
},
|
|
175
|
-
receipt: {
|
|
176
|
-
email: false,
|
|
177
|
-
sms: true
|
|
178
|
-
},
|
|
179
|
-
customer: {
|
|
180
|
-
id: null,
|
|
181
|
-
first_name: 'Hala',
|
|
182
|
-
middle_name: null,
|
|
183
|
-
last_name: 'Q.',
|
|
184
|
-
email: 'email@email.com',
|
|
185
|
-
phone: {
|
|
186
|
-
country_code: '965',
|
|
187
|
-
number: '00000000'
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
source: {
|
|
191
|
-
id: cardToken
|
|
192
|
-
},
|
|
193
|
-
hashstring: null,
|
|
194
|
-
post: {
|
|
195
|
-
url: null
|
|
196
|
-
},
|
|
197
|
-
redirect: {
|
|
198
|
-
url: 'https://jslib.gosell.io/demo?token=63cce645332aa501e6cf768f&mode=popup'
|
|
199
|
-
},
|
|
200
|
-
ipaddress: null,
|
|
201
|
-
selected_currency: request.currencyCode,
|
|
202
|
-
selected_amount: request.total.amount,
|
|
203
|
-
merchant: {
|
|
204
|
-
id: merchant.id
|
|
205
|
-
},
|
|
206
|
-
order: {
|
|
207
|
-
id: 'ord_06CO2023731xt7V22SC0X487'
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
return this.post('/api', body);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
250
|
return APPService;
|
|
215
251
|
}(BaseService));
|
|
216
252
|
var appService = new APPService();
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
export declare const MW_BASE_LIVE_URL = "https://mw-sdk.tap.company/v2/checkout";
|
|
2
|
+
export declare const MW_BASE_STAGING_URL = "https://mw-sdk.staing.tap.company/v2/checkout";
|
|
3
|
+
export declare const MW_BASE_DEV_URL = "https://mw-sdk.dev.tap.company/v2/checkout";
|
|
4
|
+
export declare const MW_BASE_BETA_URL = "https://mw-sdk.dev.tap.company/v2/checkout";
|
|
5
|
+
export declare const MW_BASE_SANDBOX_URL = "https://mw-sdk.sandbox.tap.company/v2/checkout";
|
|
1
6
|
declare const httpClient: import("axios").AxiosInstance;
|
|
7
|
+
export declare const setAxiosGlobalHeaders: (headers: Record<string, string>) => void;
|
|
2
8
|
export default httpClient;
|
package/build/api/httpClient.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
1
12
|
import axios from 'axios';
|
|
2
|
-
var
|
|
13
|
+
export var MW_BASE_LIVE_URL = 'https://mw-sdk.tap.company/v2/checkout';
|
|
14
|
+
export var MW_BASE_STAGING_URL = 'https://mw-sdk.staing.tap.company/v2/checkout';
|
|
15
|
+
export var MW_BASE_DEV_URL = 'https://mw-sdk.dev.tap.company/v2/checkout';
|
|
16
|
+
export var MW_BASE_BETA_URL = 'https://mw-sdk.dev.tap.company/v2/checkout';
|
|
17
|
+
export var MW_BASE_SANDBOX_URL = 'https://mw-sdk.sandbox.tap.company/v2/checkout';
|
|
3
18
|
var httpClient = axios.create({
|
|
4
|
-
baseURL: MW_BASE_URL,
|
|
5
19
|
headers: {
|
|
6
20
|
'Content-Type': 'application/json',
|
|
7
21
|
Accept: 'application/json'
|
|
@@ -13,4 +27,7 @@ httpClient.interceptors.request.use(function (config) {
|
|
|
13
27
|
httpClient.interceptors.response.use(function (response) {
|
|
14
28
|
return response;
|
|
15
29
|
});
|
|
30
|
+
export var setAxiosGlobalHeaders = function (headers) {
|
|
31
|
+
httpClient.defaults.headers.common = __assign(__assign({}, httpClient.defaults.headers.common), headers);
|
|
32
|
+
};
|
|
16
33
|
export default httpClient;
|
|
@@ -37,3 +37,15 @@ export declare const SupportedNetworks: {
|
|
|
37
37
|
readonly Maestro: "maestro";
|
|
38
38
|
};
|
|
39
39
|
export declare const ApplePayVersion = 5;
|
|
40
|
+
export declare const Environment: {
|
|
41
|
+
readonly Production: "production";
|
|
42
|
+
readonly Sandbox: "sandbox";
|
|
43
|
+
readonly Beta: "beta";
|
|
44
|
+
readonly Development: "development";
|
|
45
|
+
readonly Staging: "staging";
|
|
46
|
+
};
|
|
47
|
+
export declare const RSA_DEV_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----";
|
|
48
|
+
export declare const RSA_SANDBOX_MW_PUBLIC_KEY = "";
|
|
49
|
+
export declare const RSA_PRODUCTION_MW_PUBLIC_KEY = "";
|
|
50
|
+
export declare const RSA_BETA_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
|
|
51
|
+
export declare const RSA_STAGING_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
|
package/build/constants/index.js
CHANGED
|
@@ -37,3 +37,15 @@ export var SupportedNetworks = {
|
|
|
37
37
|
Maestro: 'maestro'
|
|
38
38
|
};
|
|
39
39
|
export var ApplePayVersion = 5;
|
|
40
|
+
export var Environment = {
|
|
41
|
+
Production: 'production',
|
|
42
|
+
Sandbox: 'sandbox',
|
|
43
|
+
Beta: 'beta',
|
|
44
|
+
Development: 'development',
|
|
45
|
+
Staging: 'staging'
|
|
46
|
+
};
|
|
47
|
+
export var RSA_DEV_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----";
|
|
48
|
+
export var RSA_SANDBOX_MW_PUBLIC_KEY = "";
|
|
49
|
+
export var RSA_PRODUCTION_MW_PUBLIC_KEY = "";
|
|
50
|
+
export var RSA_BETA_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
|
|
51
|
+
export var RSA_STAGING_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
|
|
@@ -17,7 +17,7 @@ import { useApplePay } from '../../hooks/useApplePay';
|
|
|
17
17
|
import { ButtonStyle, ButtonType, Locale, 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, onClick = _a.onClick, metaData = _a.metaData, _b = _a.scope, scope = _b === void 0 ? Scope.TapToken : _b, _c = _a.buttonStyle, buttonStyle = _c === void 0 ? ButtonStyle.WhiteOutline : _c, _d = _a.type, type = _d === void 0 ? ButtonType.PLAIN : _d, _e = _a.locale, locale = _e === void 0 ? Locale.EN : _e, debug = _a.debug, merchantIdentifier = _a.merchantIdentifier;
|
|
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, onClick = _a.onClick, metaData = _a.metaData, _b = _a.scope, scope = _b === void 0 ? Scope.TapToken : _b, _c = _a.buttonStyle, buttonStyle = _c === void 0 ? ButtonStyle.WhiteOutline : _c, _d = _a.type, type = _d === void 0 ? ButtonType.PLAIN : _d, _e = _a.locale, locale = _e === void 0 ? Locale.EN : _e, debug = _a.debug, merchantIdentifier = _a.merchantIdentifier, environment = _a.environment, onReady = _a.onReady;
|
|
21
21
|
var _f = useApplePay({
|
|
22
22
|
publicKey: publicKey,
|
|
23
23
|
merchant: merchant,
|
|
@@ -30,7 +30,10 @@ var ApplePay = React.memo(function (_a) {
|
|
|
30
30
|
scope: scope,
|
|
31
31
|
metaData: metaData,
|
|
32
32
|
debug: debug,
|
|
33
|
-
merchantIdentifier: merchantIdentifier
|
|
33
|
+
merchantIdentifier: merchantIdentifier,
|
|
34
|
+
environment: environment,
|
|
35
|
+
locale: locale,
|
|
36
|
+
onReady: onReady
|
|
34
37
|
}), loading = _f.loading, onApplePayButtonClicked = _f.onApplePayButtonClicked, disabled = _f.disabled;
|
|
35
38
|
React.useEffect(function () {
|
|
36
39
|
if (debug) {
|
|
@@ -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, metaData, debug, merchantIdentifier }: UseApplePayProps) => UseApplePayReturnProps;
|
|
8
|
+
export declare const useApplePay: ({ publicKey, merchant, transaction, billingContact, onCancel, onError, onSuccess, scope, supportedNetworks, metaData, debug, merchantIdentifier, environment, locale, onReady }: UseApplePayProps) => UseApplePayReturnProps;
|
|
9
9
|
export {};
|
|
@@ -48,36 +48,55 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
import { useCallback, useEffect, useState } from 'react';
|
|
49
49
|
import appService from '../api/app.service';
|
|
50
50
|
import { ApplePayVersion } from '../constants';
|
|
51
|
+
import { setAxiosGlobalHeaders } from '../api/httpClient';
|
|
51
52
|
import { getApplePayPaymentMethod, getApplePayRequest, validateCurrency, validateSupportedNetworks } from '../utils/config';
|
|
52
53
|
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, metaData = _a.metaData, debug = _a.debug, merchantIdentifier = _a.merchantIdentifier;
|
|
54
|
+
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, metaData = _a.metaData, debug = _a.debug, merchantIdentifier = _a.merchantIdentifier, environment = _a.environment, locale = _a.locale, onReady = _a.onReady;
|
|
54
55
|
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
55
56
|
var _c = useState(null), profileData = _c[0], setProfile = _c[1];
|
|
56
57
|
var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
var initialize = useCallback(function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
+
var merchantProfile, payment_options, headers, data, err_1;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
setLoading(true);
|
|
64
|
+
appService.setEnv(environment);
|
|
65
|
+
appService.setBaseUrl();
|
|
66
|
+
_a.label = 1;
|
|
67
|
+
case 1:
|
|
68
|
+
_a.trys.push([1, 4, 5, 6]);
|
|
69
|
+
if (metaData) {
|
|
70
|
+
merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers = metaData.headers;
|
|
71
|
+
setAxiosGlobalHeaders(__assign({}, headers));
|
|
72
|
+
setProfile({ merchant: merchantProfile, payment_options: payment_options });
|
|
73
|
+
return [2];
|
|
74
|
+
}
|
|
75
|
+
return [4, appService.setBrowserHeaders({ locale: locale, domain: merchant.domain, pk: publicKey })];
|
|
76
|
+
case 2:
|
|
77
|
+
_a.sent();
|
|
78
|
+
return [4, appService.checkoutProfile()];
|
|
79
|
+
case 3:
|
|
80
|
+
data = _a.sent();
|
|
81
|
+
if (debug)
|
|
82
|
+
console.log('merchant configuration: ', data);
|
|
83
|
+
setProfile(data);
|
|
84
|
+
return [3, 6];
|
|
85
|
+
case 4:
|
|
86
|
+
err_1 = _a.sent();
|
|
87
|
+
onError && onError(err_1.errors || err_1);
|
|
88
|
+
return [3, 6];
|
|
89
|
+
case 5:
|
|
90
|
+
setLoading(false);
|
|
91
|
+
onReady && onReady();
|
|
92
|
+
return [7];
|
|
93
|
+
case 6: return [2];
|
|
94
|
+
}
|
|
71
95
|
});
|
|
72
|
-
}, [merchant,
|
|
96
|
+
}); }, [environment, locale, merchant.domain, publicKey, debug, onError]);
|
|
73
97
|
useEffect(function () {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
getMerchantData();
|
|
79
|
-
}
|
|
80
|
-
}, [getMerchantData, metaData]);
|
|
98
|
+
initialize(metaData);
|
|
99
|
+
}, [initialize, metaData]);
|
|
81
100
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
82
101
|
var ApplePaySession, paymentMethod, currency, cardBrands, request, session_1;
|
|
83
102
|
var _a;
|
|
@@ -126,7 +145,7 @@ export var useApplePay = function (_a) {
|
|
|
126
145
|
}
|
|
127
146
|
return [4, appService.appleSession(profileData.merchant, event.validationURL, merchant.domain, merchantIdentifier)];
|
|
128
147
|
case 2:
|
|
129
|
-
merchantSession =
|
|
148
|
+
merchantSession = _a.sent();
|
|
130
149
|
if (debug)
|
|
131
150
|
console.info('merchantSession', merchantSession);
|
|
132
151
|
session_1.completeMerchantValidation(merchantSession);
|
|
@@ -154,7 +173,7 @@ export var useApplePay = function (_a) {
|
|
|
154
173
|
console.info('onpaymentauthorized event', event);
|
|
155
174
|
_b.label = 1;
|
|
156
175
|
case 1:
|
|
157
|
-
_b.trys.push([1, 9, ,
|
|
176
|
+
_b.trys.push([1, 9, 10, 11]);
|
|
158
177
|
_a = scope;
|
|
159
178
|
switch (_a) {
|
|
160
179
|
case 'AppleToken': return [3, 2];
|
|
@@ -166,7 +185,7 @@ export var useApplePay = function (_a) {
|
|
|
166
185
|
_b.sent();
|
|
167
186
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
168
187
|
return [3, 8];
|
|
169
|
-
case 4: return [4, appService.tapTokenization(event.payment.token.paymentData
|
|
188
|
+
case 4: return [4, appService.tapTokenization(event.payment.token.paymentData)];
|
|
170
189
|
case 5:
|
|
171
190
|
data = _b.sent();
|
|
172
191
|
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data))];
|
|
@@ -179,7 +198,7 @@ export var useApplePay = function (_a) {
|
|
|
179
198
|
console.info('Completing payment with status: STATUS_FAILURE');
|
|
180
199
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
181
200
|
_b.label = 8;
|
|
182
|
-
case 8: return [3,
|
|
201
|
+
case 8: return [3, 11];
|
|
183
202
|
case 9:
|
|
184
203
|
error_2 = _b.sent();
|
|
185
204
|
if (debug)
|
|
@@ -188,7 +207,8 @@ export var useApplePay = function (_a) {
|
|
|
188
207
|
throw error_2;
|
|
189
208
|
case 10:
|
|
190
209
|
setLoading(false);
|
|
191
|
-
return [
|
|
210
|
+
return [7];
|
|
211
|
+
case 11: return [2];
|
|
192
212
|
}
|
|
193
213
|
});
|
|
194
214
|
}); };
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ApplePayButtonProps, ApplePayButton } from './features/ApplePayButton';
|
|
2
|
-
import { ButtonStyle, Scope, SupportedNetworks } from './constants';
|
|
2
|
+
import { ButtonStyle, Scope, SupportedNetworks, Environment } from './constants';
|
|
3
3
|
export type { ApplePayButtonProps };
|
|
4
|
-
export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks };
|
|
4
|
+
export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks, Environment };
|
package/build/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
|
|
2
|
-
import { ButtonStyle, Scope, SupportedNetworks } from './constants';
|
|
3
|
-
export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks };
|
|
2
|
+
import { ButtonStyle, Scope, SupportedNetworks, Environment } from './constants';
|
|
3
|
+
export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks, Environment };
|
|
4
4
|
window['TapSDKs'] = {
|
|
5
5
|
renderApplePayButton: renderApplePayButton,
|
|
6
6
|
ButtonStyle: ButtonStyle,
|
|
7
7
|
Scope: Scope,
|
|
8
|
-
SupportedNetworks: SupportedNetworks
|
|
8
|
+
SupportedNetworks: SupportedNetworks,
|
|
9
|
+
Environment: Environment
|
|
9
10
|
};
|
package/build/utils/config.d.ts
CHANGED
|
@@ -7,3 +7,5 @@ export declare const getApplePayRequest: ({ transaction, billingContact, support
|
|
|
7
7
|
name: string;
|
|
8
8
|
}) => ApplePayRequestData;
|
|
9
9
|
export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
|
|
10
|
+
export declare const rsaSetup: (key: string) => (string: string) => string;
|
|
11
|
+
export declare function generateApplicationHeader(obj: Record<string, string | any>): string;
|
package/build/utils/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MerchantCapabilities } from '../constants';
|
|
2
|
+
import { JSEncrypt } from 'jsencrypt';
|
|
2
3
|
export var validateSupportedNetworks = function (supportedNetworksConfig, supportedNetworks) {
|
|
3
4
|
var toLowerCase = function (item) { return item.toLowerCase(); };
|
|
4
5
|
if (!supportedNetworks)
|
|
@@ -52,3 +53,20 @@ export var getApplePayPaymentMethod = function (paymentMethods) {
|
|
|
52
53
|
}
|
|
53
54
|
return paymentMethod;
|
|
54
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/apple-pay-button",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Apple Pay Button React Component",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"module": "build/index.js",
|
|
@@ -72,7 +72,9 @@
|
|
|
72
72
|
"webpack-merge": "^5.8.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
+
"@tap-payments/browser-info": "^1.0.2",
|
|
75
76
|
"axios": "^1.2.2",
|
|
77
|
+
"jsencrypt": "^3.3.2",
|
|
76
78
|
"react": ">=17.0.2",
|
|
77
79
|
"react-dom": ">=17.0.2"
|
|
78
80
|
},
|