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