@tap-payments/apple-pay-button 0.0.90-development → 0.0.91-development
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/LICENSE +21 -21
- package/README.md +240 -240
- package/build/@types/ApplePayButtonProps.d.ts +56 -56
- package/build/@types/ApplePayButtonProps.js +1 -1
- package/build/@types/charge.d.ts +56 -56
- package/build/@types/charge.js +1 -1
- package/build/@types/checkoutProfile.d.ts +216 -216
- package/build/@types/checkoutProfile.js +1 -1
- package/build/@types/enums.d.ts +44 -45
- package/build/@types/enums.js +51 -52
- package/build/@types/index.d.ts +6 -6
- package/build/@types/index.js +6 -6
- package/build/@types/tapLocalisation.d.ts +193 -193
- package/build/@types/tapLocalisation.js +1 -1
- package/build/@types/tapTheme.d.ts +842 -842
- package/build/@types/tapTheme.js +1 -1
- package/build/api.d.ts +31 -31
- package/build/api.js +236 -236
- package/build/constants/index.d.ts +3 -3
- package/build/constants/index.js +3 -3
- package/build/features/ApplePayButton/ApplePayButton.d.ts +4 -4
- package/build/features/ApplePayButton/ApplePayButton.js +48 -48
- package/build/features/ApplePayButton/index.d.ts +3 -3
- package/build/features/ApplePayButton/index.js +2 -2
- package/build/hooks/index.d.ts +1 -1
- package/build/hooks/index.js +1 -1
- package/build/hooks/useApplePay.d.ts +81 -81
- package/build/hooks/useApplePay.js +424 -425
- package/build/hooks/useMerchantApplePay.d.ts +22 -22
- package/build/hooks/useMerchantApplePay.js +190 -190
- package/build/index.d.ts +5 -5
- package/build/index.js +14 -14
- package/build/utils/config.d.ts +14 -14
- package/build/utils/config.js +59 -57
- package/build/utils/defaultValues.d.ts +2 -2
- package/build/utils/defaultValues.js +27 -27
- package/build/utils/index.d.ts +3 -3
- package/build/utils/index.js +3 -3
- package/build/utils/theme.d.ts +13 -13
- package/build/utils/theme.js +62 -62
- package/package.json +109 -109
|
@@ -1,425 +1,424 @@
|
|
|
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
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
49
|
-
import { ApplePayVersion, MW_BASE_URL } from '../constants';
|
|
50
|
-
import { PAYMENT_METHOD_KEY, prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
|
|
51
|
-
import { IntegrationType } from '../@types';
|
|
52
|
-
import { useMerchantApplePay } from './useMerchantApplePay';
|
|
53
|
-
import { getDefaultThemeMode } from '../utils';
|
|
54
|
-
import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
|
|
55
|
-
import { areAllTheObjectStringValuesValid, ChargeCode, getPaymentMethod, mappingInterface, Scope } from '@tap-payments/acceptance-sdk';
|
|
56
|
-
var FALLBACK_MERCHANT_IDENTIFIER = 'merchant.tap.gosell';
|
|
57
|
-
export var useApplePay = function (_a) {
|
|
58
|
-
var buttonProps = _a.buttonProps;
|
|
59
|
-
var _b = useState(), applePayRequestData = _b[0], setApplePayRequestData = _b[1];
|
|
60
|
-
var _c = useState(), applePayRequestConfiguration = _c[0], setApplePayRequestConfiguration = _c[1];
|
|
61
|
-
var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
|
|
62
|
-
var _e = useState(false), error = _e[0], setError = _e[1];
|
|
63
|
-
var _f = useState(false), success = _f[0], setSuccess = _f[1];
|
|
64
|
-
var _g = useState(false), loading = _g[0], setLoading = _g[1];
|
|
65
|
-
var _h = useState(false), isRounded = _h[0], setIsRounded = _h[1];
|
|
66
|
-
var mappedProps = __assign(__assign({}, buttonProps), { interface: mappingInterface(buttonProps.interface) });
|
|
67
|
-
var interfaceObj = mappedProps.interface, merchant = mappedProps.merchant, customer = mappedProps.customer, acceptance = mappedProps.acceptance, scope = mappedProps.scope, debug = mappedProps.debug, onError = mappedProps.onError, onSuccess = mappedProps.onSuccess, onCancel = mappedProps.onCancel, onReady = mappedProps.onReady, metadata = mappedProps.metadata, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect, integration = mappedProps.integration, features = mappedProps.features;
|
|
68
|
-
var _j = metadata || {}, profileData = _j.profileData, headers = _j.headers;
|
|
69
|
-
var isIframeIntegration = integration === IntegrationType.IFRAME;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
session
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
_e.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
applePayPreparedData
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
err_1
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
var
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
ApplePaySession
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
session_1 =
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
console.info('
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
var
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
_b
|
|
242
|
-
|
|
243
|
-
case Scope.
|
|
244
|
-
case Scope.
|
|
245
|
-
case Scope.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
case
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
case
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
console.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
case
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
};
|
|
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
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
49
|
+
import { ApplePayVersion, MW_BASE_URL } from '../constants';
|
|
50
|
+
import { PAYMENT_METHOD_KEY, prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
|
|
51
|
+
import { IntegrationType } from '../@types';
|
|
52
|
+
import { useMerchantApplePay } from './useMerchantApplePay';
|
|
53
|
+
import { getDefaultThemeMode } from '../utils';
|
|
54
|
+
import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
|
|
55
|
+
import { areAllTheObjectStringValuesValid, ChargeCode, getPaymentMethod, getSelectedCurrency, mappingInterface, Scope } from '@tap-payments/acceptance-sdk';
|
|
56
|
+
var FALLBACK_MERCHANT_IDENTIFIER = 'merchant.tap.gosell';
|
|
57
|
+
export var useApplePay = function (_a) {
|
|
58
|
+
var buttonProps = _a.buttonProps;
|
|
59
|
+
var _b = useState(), applePayRequestData = _b[0], setApplePayRequestData = _b[1];
|
|
60
|
+
var _c = useState(), applePayRequestConfiguration = _c[0], setApplePayRequestConfiguration = _c[1];
|
|
61
|
+
var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
|
|
62
|
+
var _e = useState(false), error = _e[0], setError = _e[1];
|
|
63
|
+
var _f = useState(false), success = _f[0], setSuccess = _f[1];
|
|
64
|
+
var _g = useState(false), loading = _g[0], setLoading = _g[1];
|
|
65
|
+
var _h = useState(false), isRounded = _h[0], setIsRounded = _h[1];
|
|
66
|
+
var mappedProps = __assign(__assign({}, buttonProps), { interface: mappingInterface(buttonProps.interface) });
|
|
67
|
+
var interfaceObj = mappedProps.interface, merchant = mappedProps.merchant, customer = mappedProps.customer, acceptance = mappedProps.acceptance, scope = mappedProps.scope, debug = mappedProps.debug, onError = mappedProps.onError, onSuccess = mappedProps.onSuccess, onCancel = mappedProps.onCancel, onReady = mappedProps.onReady, metadata = mappedProps.metadata, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect, integration = mappedProps.integration, features = mappedProps.features;
|
|
68
|
+
var _j = metadata || {}, profileData = _j.profileData, headers = _j.headers;
|
|
69
|
+
var isIframeIntegration = integration === IntegrationType.IFRAME;
|
|
70
|
+
useMerchantApplePay({
|
|
71
|
+
isIframeIntegration: isIframeIntegration,
|
|
72
|
+
onError: onError,
|
|
73
|
+
onSuccess: onSuccess,
|
|
74
|
+
scope: scope,
|
|
75
|
+
profileData: profileData,
|
|
76
|
+
merchant: merchant,
|
|
77
|
+
order: order,
|
|
78
|
+
customer: customer,
|
|
79
|
+
transaction: transaction,
|
|
80
|
+
operator: operator,
|
|
81
|
+
post: post,
|
|
82
|
+
redirect: redirect,
|
|
83
|
+
setError: setError,
|
|
84
|
+
setSuccess: setSuccess,
|
|
85
|
+
setLoading: setLoading,
|
|
86
|
+
features: features
|
|
87
|
+
});
|
|
88
|
+
var theme = useMemo(function () { return getDefaultThemeMode(interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.theme); }, [interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.theme]);
|
|
89
|
+
var applePayPaymentMethodOptions = useMemo(function () {
|
|
90
|
+
if (!profileData)
|
|
91
|
+
return undefined;
|
|
92
|
+
return getPaymentMethod(profileData.payment_options.payment_methods || [], PAYMENT_METHOD_KEY);
|
|
93
|
+
}, [profileData]);
|
|
94
|
+
var merchantValidationRequestData = useMemo(function () {
|
|
95
|
+
if (!profileData)
|
|
96
|
+
return null;
|
|
97
|
+
return {
|
|
98
|
+
merchantId: merchant.id || (profileData === null || profileData === void 0 ? void 0 : profileData.merchant.id),
|
|
99
|
+
merchantName: profileData.merchant.name,
|
|
100
|
+
validationUrl: '',
|
|
101
|
+
origin: window.location.hostname,
|
|
102
|
+
merchantIdentifier: (applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.identifier) || FALLBACK_MERCHANT_IDENTIFIER
|
|
103
|
+
};
|
|
104
|
+
}, [merchant, profileData === null || profileData === void 0 ? void 0 : profileData.merchant, applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.identifier]);
|
|
105
|
+
var initialize = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
106
|
+
var session, _a, id, api_version, contact, applePayPreparedData, err_1;
|
|
107
|
+
var _b, _c, _d;
|
|
108
|
+
return __generator(this, function (_e) {
|
|
109
|
+
switch (_e.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
_e.trys.push([0, 5, , 6]);
|
|
112
|
+
if (!shallRenderApplePay()) {
|
|
113
|
+
throw new Error('The device/customer is not eligible to use ApplePay');
|
|
114
|
+
}
|
|
115
|
+
if (!applePayPaymentMethodOptions) {
|
|
116
|
+
throw new Error("000::".concat(PAYMENT_METHOD_KEY.toUpperCase(), " is not configured in your payment options"));
|
|
117
|
+
}
|
|
118
|
+
if (!profileData) {
|
|
119
|
+
throw new Error('000::Profile data is not available');
|
|
120
|
+
}
|
|
121
|
+
session = headers === null || headers === void 0 ? void 0 : headers.session;
|
|
122
|
+
setAxiosGlobalHeaders({ session: session });
|
|
123
|
+
if (!(headers && areAllTheObjectStringValuesValid(headers))) return [3, 2];
|
|
124
|
+
return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { authorization: operator.publicKey }))];
|
|
125
|
+
case 1:
|
|
126
|
+
_e.sent();
|
|
127
|
+
return [3, 4];
|
|
128
|
+
case 2: return [4, appService.setBrowserHeaders({
|
|
129
|
+
locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
|
|
130
|
+
domain: window.location.origin,
|
|
131
|
+
pk: operator.publicKey
|
|
132
|
+
})];
|
|
133
|
+
case 3:
|
|
134
|
+
_e.sent();
|
|
135
|
+
_e.label = 4;
|
|
136
|
+
case 4:
|
|
137
|
+
if (debug) {
|
|
138
|
+
_a = profileData.merchant, id = _a.id, api_version = _a.api_version, contact = _a.contact;
|
|
139
|
+
console.log('merchant configuration: ', {
|
|
140
|
+
id: id,
|
|
141
|
+
api_version: api_version,
|
|
142
|
+
contact: contact
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
applePayPreparedData = prepareApplePayRequest(__assign(__assign({}, profileData), { order: order, acceptance: acceptance, customer: customer }));
|
|
146
|
+
setApplePayRequestData(applePayPreparedData.applePaySessionRequest);
|
|
147
|
+
onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((_c = (_b = profileData.payment_options) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.id);
|
|
148
|
+
setApplePayRequestConfiguration({
|
|
149
|
+
BASE_URL: MW_BASE_URL,
|
|
150
|
+
headers: getAxiosGlobalHeaders(),
|
|
151
|
+
merchant: __assign(__assign({}, profileData.merchant), { id: merchant.id || ((_d = profileData.merchant) === null || _d === void 0 ? void 0 : _d.id) })
|
|
152
|
+
});
|
|
153
|
+
onReady === null || onReady === void 0 ? void 0 : onReady();
|
|
154
|
+
return [3, 6];
|
|
155
|
+
case 5:
|
|
156
|
+
err_1 = _e.sent();
|
|
157
|
+
onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
|
|
158
|
+
console.log('error in initialize', err_1);
|
|
159
|
+
return [3, 6];
|
|
160
|
+
case 6: return [2];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}); };
|
|
164
|
+
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
165
|
+
var ApplePaySession, session_1;
|
|
166
|
+
var _a;
|
|
167
|
+
return __generator(this, function (_b) {
|
|
168
|
+
ApplePaySession = window.ApplePaySession;
|
|
169
|
+
if (!ApplePaySession) {
|
|
170
|
+
setDisabled(true);
|
|
171
|
+
console.error('ApplePaySession is not available, please check if you are using Safari browser');
|
|
172
|
+
return [2];
|
|
173
|
+
}
|
|
174
|
+
if (!profileData) {
|
|
175
|
+
setDisabled(true);
|
|
176
|
+
console.error('The profile data is not available, please check the network and try again');
|
|
177
|
+
return [2];
|
|
178
|
+
}
|
|
179
|
+
if (!applePayRequestData) {
|
|
180
|
+
setDisabled(true);
|
|
181
|
+
console.error("We can't find the apple pay request data, please check the network and try again");
|
|
182
|
+
return [2];
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
if (debug) {
|
|
186
|
+
console.info("Creating ApplePaySession with version: ".concat(ApplePayVersion, " and request: ").concat(JSON.stringify(applePayRequestData)));
|
|
187
|
+
}
|
|
188
|
+
session_1 = new ApplePaySession(ApplePayVersion, applePayRequestData);
|
|
189
|
+
session_1.onvalidatemerchant = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
190
|
+
var merchantSession, error_1;
|
|
191
|
+
return __generator(this, function (_a) {
|
|
192
|
+
switch (_a.label) {
|
|
193
|
+
case 0:
|
|
194
|
+
if (debug) {
|
|
195
|
+
console.info('Creating merchant session and validating merchant session');
|
|
196
|
+
console.info('onvalidatemerchant event', event);
|
|
197
|
+
}
|
|
198
|
+
setDisabled(true);
|
|
199
|
+
_a.label = 1;
|
|
200
|
+
case 1:
|
|
201
|
+
_a.trys.push([1, 3, , 4]);
|
|
202
|
+
if (debug) {
|
|
203
|
+
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(window.location.hostname));
|
|
204
|
+
}
|
|
205
|
+
if (!merchantValidationRequestData) {
|
|
206
|
+
throw new Error('Merchant Validation Request Data is not prepared!');
|
|
207
|
+
}
|
|
208
|
+
return [4, appService.appleSession(__assign(__assign({}, merchantValidationRequestData), { validationUrl: event.validationURL }))];
|
|
209
|
+
case 2:
|
|
210
|
+
merchantSession = _a.sent();
|
|
211
|
+
if (debug)
|
|
212
|
+
console.info('merchantSession', merchantSession);
|
|
213
|
+
session_1.completeMerchantValidation(merchantSession);
|
|
214
|
+
console.info('merchantSession completed successfully!');
|
|
215
|
+
return [3, 4];
|
|
216
|
+
case 3:
|
|
217
|
+
error_1 = _a.sent();
|
|
218
|
+
if (debug)
|
|
219
|
+
console.error('error in onvalidatemerchant', error_1);
|
|
220
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
221
|
+
throw error_1;
|
|
222
|
+
case 4:
|
|
223
|
+
setDisabled(false);
|
|
224
|
+
return [2];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}); };
|
|
228
|
+
session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
229
|
+
var _a, paymentData, paymentMethod, transactionIdentifier, _b, data, tokenId, supportedCurrency, transactionRequest, transactionResponse, _c, successState, error_2;
|
|
230
|
+
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
|
|
231
|
+
return __generator(this, function (_2) {
|
|
232
|
+
switch (_2.label) {
|
|
233
|
+
case 0:
|
|
234
|
+
if (debug)
|
|
235
|
+
console.info('onpaymentauthorized event', event);
|
|
236
|
+
_2.label = 1;
|
|
237
|
+
case 1:
|
|
238
|
+
_2.trys.push([1, 16, 17, 18]);
|
|
239
|
+
_a = (_d = event.payment.token) !== null && _d !== void 0 ? _d : {}, paymentData = _a.paymentData, paymentMethod = _a.paymentMethod, transactionIdentifier = _a.transactionIdentifier;
|
|
240
|
+
_b = scope;
|
|
241
|
+
switch (_b) {
|
|
242
|
+
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
243
|
+
case Scope.TOKEN: return [3, 4];
|
|
244
|
+
case Scope.AUTHORIZE: return [3, 7];
|
|
245
|
+
case Scope.CHARGE: return [3, 7];
|
|
246
|
+
}
|
|
247
|
+
return [3, 14];
|
|
248
|
+
case 2: return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token))];
|
|
249
|
+
case 3:
|
|
250
|
+
_2.sent();
|
|
251
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
252
|
+
return [3, 15];
|
|
253
|
+
case 4:
|
|
254
|
+
setLoading(true);
|
|
255
|
+
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
|
|
256
|
+
case 5:
|
|
257
|
+
data = _2.sent();
|
|
258
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
259
|
+
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data))];
|
|
260
|
+
case 6:
|
|
261
|
+
_2.sent();
|
|
262
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
263
|
+
return [3, 15];
|
|
264
|
+
case 7:
|
|
265
|
+
setLoading(true);
|
|
266
|
+
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
|
|
267
|
+
case 8:
|
|
268
|
+
tokenId = (_2.sent()).id;
|
|
269
|
+
supportedCurrency = getSelectedCurrency((profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.supported_currencies) || [], order, applePayPaymentMethodOptions);
|
|
270
|
+
transactionRequest = {
|
|
271
|
+
auto: (_e = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _e === void 0 ? void 0 : _e.auto,
|
|
272
|
+
amount: (_h = (_g = (_f = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _f === void 0 ? void 0 : _f.order) === null || _g === void 0 ? void 0 : _g.amount) !== null && _h !== void 0 ? _h : order.amount,
|
|
273
|
+
currency: (_l = (_k = (_j = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _j === void 0 ? void 0 : _j.order) === null || _k === void 0 ? void 0 : _k.currency) !== null && _l !== void 0 ? _l : order.currency,
|
|
274
|
+
selected_amount: supportedCurrency === null || supportedCurrency === void 0 ? void 0 : supportedCurrency.amount,
|
|
275
|
+
selected_currency: supportedCurrency === null || supportedCurrency === void 0 ? void 0 : supportedCurrency.currency,
|
|
276
|
+
customer: (customer === null || customer === void 0 ? void 0 : customer.id)
|
|
277
|
+
? { id: customer === null || customer === void 0 ? void 0 : customer.id }
|
|
278
|
+
: {
|
|
279
|
+
email: (_m = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _m === void 0 ? void 0 : _m.email,
|
|
280
|
+
first_name: ((_o = customer === null || customer === void 0 ? void 0 : customer.name) === null || _o === void 0 ? void 0 : _o.length) ? customer.name[0].first : '',
|
|
281
|
+
last_name: ((_p = customer === null || customer === void 0 ? void 0 : customer.name) === null || _p === void 0 ? void 0 : _p.length) ? customer.name[0].last : '',
|
|
282
|
+
phone: {
|
|
283
|
+
country_code: (_s = (_r = (_q = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _q === void 0 ? void 0 : _q.phone) === null || _r === void 0 ? void 0 : _r.countryCode) !== null && _s !== void 0 ? _s : '',
|
|
284
|
+
number: (_v = (_u = (_t = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _t === void 0 ? void 0 : _t.phone) === null || _u === void 0 ? void 0 : _u.number) !== null && _v !== void 0 ? _v : ''
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
merchant: {
|
|
288
|
+
id: (_x = (_w = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _w === void 0 ? void 0 : _w.id) !== null && _x !== void 0 ? _x : ''
|
|
289
|
+
},
|
|
290
|
+
order: (_y = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _y === void 0 ? void 0 : _y.order,
|
|
291
|
+
product: 'Apple-Pay-Button',
|
|
292
|
+
save_card: !!((_z = features === null || features === void 0 ? void 0 : features.customerCards) === null || _z === void 0 ? void 0 : _z.saveCard),
|
|
293
|
+
source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
|
|
294
|
+
threeDSecure: (_1 = (_0 = transaction === null || transaction === void 0 ? void 0 : transaction.authenticate) === null || _0 === void 0 ? void 0 : _0.required) !== null && _1 !== void 0 ? _1 : true,
|
|
295
|
+
hashstring: operator.hashstring,
|
|
296
|
+
redirect: redirect,
|
|
297
|
+
metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
|
|
298
|
+
post: post,
|
|
299
|
+
payment_agreement: transaction === null || transaction === void 0 ? void 0 : transaction.paymentAgreement,
|
|
300
|
+
destinations: transaction === null || transaction === void 0 ? void 0 : transaction.destinations,
|
|
301
|
+
reference: {
|
|
302
|
+
order: order === null || order === void 0 ? void 0 : order.reference,
|
|
303
|
+
transaction: transaction === null || transaction === void 0 ? void 0 : transaction.reference
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
if (!(scope === Scope.AUTHORIZE)) return [3, 10];
|
|
307
|
+
return [4, appService.createAuthorize(transactionRequest)];
|
|
308
|
+
case 9:
|
|
309
|
+
_c = _2.sent();
|
|
310
|
+
return [3, 12];
|
|
311
|
+
case 10: return [4, appService.createCharge(transactionRequest)];
|
|
312
|
+
case 11:
|
|
313
|
+
_c = _2.sent();
|
|
314
|
+
_2.label = 12;
|
|
315
|
+
case 12:
|
|
316
|
+
transactionResponse = _c;
|
|
317
|
+
successState = scope === Scope.AUTHORIZE ? ChargeCode.AUTHORIZED : ChargeCode.SUCCESS;
|
|
318
|
+
if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
|
|
319
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
setError === null || setError === void 0 ? void 0 : setError(true);
|
|
323
|
+
}
|
|
324
|
+
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse))];
|
|
325
|
+
case 13:
|
|
326
|
+
_2.sent();
|
|
327
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
328
|
+
return [3, 15];
|
|
329
|
+
case 14:
|
|
330
|
+
console.error('We only support AppleToken and TapToken for now');
|
|
331
|
+
console.info('Completing payment with status: STATUS_FAILURE');
|
|
332
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
333
|
+
_2.label = 15;
|
|
334
|
+
case 15: return [3, 18];
|
|
335
|
+
case 16:
|
|
336
|
+
error_2 = _2.sent();
|
|
337
|
+
if (debug)
|
|
338
|
+
console.error('error in onpaymentauthorized', error_2);
|
|
339
|
+
setError(true);
|
|
340
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
341
|
+
throw error_2;
|
|
342
|
+
case 17:
|
|
343
|
+
setLoading(false);
|
|
344
|
+
return [7];
|
|
345
|
+
case 18: return [2];
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}); };
|
|
349
|
+
session_1.oncancel = function (event) {
|
|
350
|
+
console.info('oncancel event', event);
|
|
351
|
+
if (onCancel)
|
|
352
|
+
onCancel();
|
|
353
|
+
};
|
|
354
|
+
session_1.begin();
|
|
355
|
+
}
|
|
356
|
+
catch (e) {
|
|
357
|
+
if (!onError)
|
|
358
|
+
return [2];
|
|
359
|
+
if (e.errors) {
|
|
360
|
+
onError(e.errors);
|
|
361
|
+
return [2];
|
|
362
|
+
}
|
|
363
|
+
if ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data.errors) {
|
|
364
|
+
onError(e.response.data.errors);
|
|
365
|
+
return [2];
|
|
366
|
+
}
|
|
367
|
+
if (e.message) {
|
|
368
|
+
onError([{ message: e.message, code: '400' }]);
|
|
369
|
+
return [2];
|
|
370
|
+
}
|
|
371
|
+
onError(e);
|
|
372
|
+
}
|
|
373
|
+
return [2];
|
|
374
|
+
});
|
|
375
|
+
}); };
|
|
376
|
+
var handleClick = useCallback(function () {
|
|
377
|
+
var _a, _b;
|
|
378
|
+
if (isIframeIntegration) {
|
|
379
|
+
(_a = buttonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(buttonProps, __assign(__assign({}, applePayRequestConfiguration), { merchantValidationRequestData: merchantValidationRequestData, applePayRequestData: applePayRequestData }));
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
onApplePayButtonClicked();
|
|
383
|
+
(_b = buttonProps.onClick) === null || _b === void 0 ? void 0 : _b.call(buttonProps);
|
|
384
|
+
}, [
|
|
385
|
+
applePayRequestConfiguration,
|
|
386
|
+
applePayRequestData,
|
|
387
|
+
buttonProps,
|
|
388
|
+
isIframeIntegration,
|
|
389
|
+
onApplePayButtonClicked,
|
|
390
|
+
merchantValidationRequestData
|
|
391
|
+
]);
|
|
392
|
+
useEffect(function () {
|
|
393
|
+
initialize();
|
|
394
|
+
}, []);
|
|
395
|
+
useEffect(function () {
|
|
396
|
+
setIsRounded(error || success || loading);
|
|
397
|
+
}, [error, success, loading]);
|
|
398
|
+
useEffect(function () {
|
|
399
|
+
if (!error)
|
|
400
|
+
return;
|
|
401
|
+
var timer = setTimeout(function () {
|
|
402
|
+
setError(false);
|
|
403
|
+
setLoading(false);
|
|
404
|
+
setIsRounded(false);
|
|
405
|
+
}, 2000);
|
|
406
|
+
return function () { return clearTimeout(timer); };
|
|
407
|
+
}, [error, loading]);
|
|
408
|
+
return {
|
|
409
|
+
onClick: handleClick,
|
|
410
|
+
loading: loading,
|
|
411
|
+
isIframeIntegration: isIframeIntegration,
|
|
412
|
+
onApplePayButtonClicked: onApplePayButtonClicked,
|
|
413
|
+
disabled: !profileData || disabled || !applePayRequestData,
|
|
414
|
+
applePayRequestData: applePayRequestData,
|
|
415
|
+
applePayRequestConfiguration: applePayRequestConfiguration,
|
|
416
|
+
mappedProps: mappedProps,
|
|
417
|
+
theme: theme,
|
|
418
|
+
isRounded: isRounded,
|
|
419
|
+
success: success,
|
|
420
|
+
error: error,
|
|
421
|
+
applePayPaymentMethodOptions: applePayPaymentMethodOptions,
|
|
422
|
+
profileData: profileData
|
|
423
|
+
};
|
|
424
|
+
};
|