@tap-payments/apple-pay-button 0.0.62-development → 0.0.64-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/build/features/ApplePayButton/ApplePayButton.js +2 -2
- package/build/hooks/useApplePay.d.ts +3 -2
- package/build/hooks/useApplePay.js +109 -44
- package/build/hooks/useMerchantApplePay.d.ts +2 -2
- package/build/hooks/useMerchantApplePay.js +10 -7
- package/build/utils/config.d.ts +1 -0
- package/build/utils/config.js +4 -0
- package/package.json +1 -1
|
@@ -20,13 +20,13 @@ import { StyledContainer } from './style';
|
|
|
20
20
|
import PayButton from '../../components/PayButton';
|
|
21
21
|
var ApplePay = React.memo(function (props) {
|
|
22
22
|
var _a, _b, _c, _d;
|
|
23
|
-
var _e = useApplePay({ buttonProps: props }), onClick = _e.onClick,
|
|
23
|
+
var _e = useApplePay({ buttonProps: props }), onClick = _e.onClick, initialLoading = _e.initialLoading, disabled = _e.disabled, mappedProps = _e.mappedProps, theme = _e.theme, isRounded = _e.isRounded, success = _e.success, error = _e.error, backgroundColor = _e.backgroundColor, gradientColor = _e.gradientColor, titleAsset = _e.titleAsset;
|
|
24
24
|
React.useEffect(function () {
|
|
25
25
|
if (props.debug) {
|
|
26
26
|
console.log('ApplePayButtonProps', props);
|
|
27
27
|
}
|
|
28
28
|
}, []);
|
|
29
|
-
return (_jsx(StyledContainer, __assign({ "data-src": 'apple-pay-button-element', "data-testid": 'ApplePayButton-section', edges: (_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.edges }, { children:
|
|
29
|
+
return (_jsx(StyledContainer, __assign({ "data-src": 'apple-pay-button-element', "data-testid": 'ApplePayButton-section', edges: (_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.edges }, { children: initialLoading ? (_jsx(InitialLoader, { open: true, themeMode: (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.theme, edges: (_c = mappedProps.interface) === null || _c === void 0 ? void 0 : _c.edges })) : (_jsx(_Fragment, { children: _jsx(PayButton, { "data-src": 'apple-pay-button-element', "data-testid": 'ApplePayButton', theme: theme, isRounded: isRounded, isSuccess: success, isFailed: error, bgColor: backgroundColor, gradientColor: gradientColor, titleAsset: titleAsset, edges: (_d = mappedProps.interface) === null || _d === void 0 ? void 0 : _d.edges, disabled: disabled, onClick: onClick }) })) })));
|
|
30
30
|
});
|
|
31
31
|
export function ApplePayButton(props) {
|
|
32
32
|
return _jsx(ApplePay, __assign({}, props));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Scope } from '../@types/enums';
|
|
2
2
|
import { ApplePayButtonProps, ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData, MetaData } from '../@types';
|
|
3
3
|
interface UsaApplePayProps {
|
|
4
4
|
buttonProps: ApplePayButtonProps;
|
|
@@ -13,7 +13,7 @@ export declare const useApplePay: ({ buttonProps }: UsaApplePayProps) => {
|
|
|
13
13
|
applePayRequestConfiguration: Omit<ApplePayDataToLunchSDKFromMerchantSide, "applePayRequestData"> | undefined;
|
|
14
14
|
mappedProps: {
|
|
15
15
|
interface: {
|
|
16
|
-
locale?: Locale | undefined;
|
|
16
|
+
locale?: import("../@types").Locale | undefined;
|
|
17
17
|
theme?: import("../@types").ThemeMode | undefined;
|
|
18
18
|
edges?: import("../@types").Edges | undefined;
|
|
19
19
|
type?: import("../@types").ButtonType | undefined;
|
|
@@ -81,6 +81,7 @@ export declare const useApplePay: ({ buttonProps }: UsaApplePayProps) => {
|
|
|
81
81
|
} | undefined;
|
|
82
82
|
};
|
|
83
83
|
theme: import("../@types").ThemeMode;
|
|
84
|
+
initialLoading: boolean;
|
|
84
85
|
isRounded: boolean;
|
|
85
86
|
success: boolean;
|
|
86
87
|
error: boolean;
|
|
@@ -49,8 +49,8 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
49
49
|
import appService from '../api/app.service';
|
|
50
50
|
import { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api/httpClient';
|
|
51
51
|
import { ApplePayVersion } from '../constants';
|
|
52
|
-
import { Scope } from '../@types/enums';
|
|
53
|
-
import { prepareApplePayRequest } from '../utils/config';
|
|
52
|
+
import { CHARGE_CODE, Scope } from '../@types/enums';
|
|
53
|
+
import { prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
|
|
54
54
|
import { useMerchantApplePay } from './useMerchantApplePay';
|
|
55
55
|
import { getApplePayPaymentMethod, getDefaultLocale, getDefaultThemeMode, getDefaultValues, getFullThemeMode } from '../utils';
|
|
56
56
|
export var useApplePay = function (_a) {
|
|
@@ -60,14 +60,13 @@ export var useApplePay = function (_a) {
|
|
|
60
60
|
var _g = useState(), applePayRequestConfiguration = _g[0], setApplePayRequestConfiguration = _g[1];
|
|
61
61
|
var _h = useState(), profileData = _h[0], setProfile = _h[1];
|
|
62
62
|
var _j = useState(false), disabled = _j[0], setDisabled = _j[1];
|
|
63
|
-
var _k = useState(
|
|
64
|
-
var _l = useState(),
|
|
65
|
-
var _m = useState(false),
|
|
66
|
-
var _o = useState(false),
|
|
67
|
-
var _p = useState(false),
|
|
68
|
-
var _q = useState(false), isRounded = _q[0], setIsRounded = _q[1];
|
|
63
|
+
var _k = useState(false), initialLoading = _k[0], setInitialLoading = _k[1];
|
|
64
|
+
var _l = useState(false), error = _l[0], setError = _l[1];
|
|
65
|
+
var _m = useState(false), success = _m[0], setSuccess = _m[1];
|
|
66
|
+
var _o = useState(false), loading = _o[0], setLoading = _o[1];
|
|
67
|
+
var _p = useState(false), isRounded = _p[0], setIsRounded = _p[1];
|
|
69
68
|
var mappedProps = getDefaultValues(buttonProps);
|
|
70
|
-
var environment = mappedProps.environment, 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, headers = mappedProps.headers, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated,
|
|
69
|
+
var environment = mappedProps.environment, 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, headers = mappedProps.headers, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect;
|
|
71
70
|
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
72
71
|
useMerchantApplePay({
|
|
73
72
|
isIframeIntegration: isIframeIntegration,
|
|
@@ -84,7 +83,7 @@ export var useApplePay = function (_a) {
|
|
|
84
83
|
redirect: redirect,
|
|
85
84
|
setError: setError,
|
|
86
85
|
setSuccess: setSuccess,
|
|
87
|
-
|
|
86
|
+
setLoading: setLoading
|
|
88
87
|
});
|
|
89
88
|
var lang = getDefaultLocale((_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.locale);
|
|
90
89
|
var theme = getDefaultThemeMode((_c = mappedProps.interface) === null || _c === void 0 ? void 0 : _c.theme);
|
|
@@ -123,22 +122,21 @@ export var useApplePay = function (_a) {
|
|
|
123
122
|
(_d = buttonProps.interface) === null || _d === void 0 ? void 0 : _d.colorStyle,
|
|
124
123
|
(_e = buttonProps.interface) === null || _e === void 0 ? void 0 : _e.theme
|
|
125
124
|
]);
|
|
126
|
-
var showLoader = useMemo(function () {
|
|
127
|
-
var _a;
|
|
128
|
-
return ((_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.loader) !== false;
|
|
129
|
-
}, [mappedProps]);
|
|
130
125
|
var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
131
126
|
var merchantProfile, payment_options, headers_1, data, err_1;
|
|
132
127
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
133
128
|
return __generator(this, function (_o) {
|
|
134
129
|
switch (_o.label) {
|
|
135
130
|
case 0:
|
|
136
|
-
|
|
131
|
+
setInitialLoading(true);
|
|
137
132
|
appService.setEnv(environment);
|
|
138
133
|
appService.setBaseUrl();
|
|
139
134
|
_o.label = 1;
|
|
140
135
|
case 1:
|
|
141
|
-
_o.trys.push([1, 7,
|
|
136
|
+
_o.trys.push([1, 7, , 8]);
|
|
137
|
+
if (!shallRenderApplePay()) {
|
|
138
|
+
throw new Error('The device/customer is not eligible to use ApplePay');
|
|
139
|
+
}
|
|
142
140
|
if (metaData) {
|
|
143
141
|
merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers_1 = metaData.headers;
|
|
144
142
|
setAxiosGlobalHeaders(__assign({}, headers_1));
|
|
@@ -200,17 +198,15 @@ export var useApplePay = function (_a) {
|
|
|
200
198
|
headers: getAxiosGlobalHeaders(),
|
|
201
199
|
merchant: __assign(__assign({}, data.merchant), { id: merchant.id || ((_m = data.merchant) === null || _m === void 0 ? void 0 : _m.id) })
|
|
202
200
|
});
|
|
203
|
-
|
|
201
|
+
setInitialLoading(false);
|
|
202
|
+
onReady === null || onReady === void 0 ? void 0 : onReady();
|
|
203
|
+
return [3, 8];
|
|
204
204
|
case 7:
|
|
205
205
|
err_1 = _o.sent();
|
|
206
206
|
onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
|
|
207
207
|
console.log('error in initialize', err_1);
|
|
208
|
-
return [3,
|
|
209
|
-
case 8:
|
|
210
|
-
setLoading(false);
|
|
211
|
-
onReady === null || onReady === void 0 ? void 0 : onReady();
|
|
212
|
-
return [7];
|
|
213
|
-
case 9: return [2];
|
|
208
|
+
return [3, 8];
|
|
209
|
+
case 8: return [2];
|
|
214
210
|
}
|
|
215
211
|
});
|
|
216
212
|
}); };
|
|
@@ -231,7 +227,7 @@ export var useApplePay = function (_a) {
|
|
|
231
227
|
}
|
|
232
228
|
if (!applePayRequestData) {
|
|
233
229
|
setDisabled(true);
|
|
234
|
-
console.error("We can't find the apple pay request data, please the network and try again");
|
|
230
|
+
console.error("We can't find the apple pay request data, please check the network and try again");
|
|
235
231
|
return [2];
|
|
236
232
|
}
|
|
237
233
|
try {
|
|
@@ -276,52 +272,117 @@ export var useApplePay = function (_a) {
|
|
|
276
272
|
});
|
|
277
273
|
}); };
|
|
278
274
|
session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
279
|
-
var _a, data, error_2;
|
|
280
|
-
|
|
281
|
-
|
|
275
|
+
var _a, data, tokenId, supportCurrency, transactionRequest, transactionResponse, _b, successState, error_2;
|
|
276
|
+
var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
277
|
+
return __generator(this, function (_t) {
|
|
278
|
+
switch (_t.label) {
|
|
282
279
|
case 0:
|
|
283
|
-
setLoading(true);
|
|
284
280
|
if (debug)
|
|
285
281
|
console.info('onpaymentauthorized event', event);
|
|
286
|
-
|
|
282
|
+
_t.label = 1;
|
|
287
283
|
case 1:
|
|
288
|
-
|
|
289
|
-
setIsRounded === null || setIsRounded === void 0 ? void 0 : setIsRounded(true);
|
|
284
|
+
_t.trys.push([1, 13, 14, 15]);
|
|
290
285
|
_a = scope;
|
|
291
286
|
switch (_a) {
|
|
292
287
|
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
293
288
|
case Scope.TAP_TOKEN: return [3, 3];
|
|
289
|
+
case Scope.AUTHORIZE: return [3, 5];
|
|
290
|
+
case Scope.CHARGE: return [3, 5];
|
|
294
291
|
}
|
|
295
|
-
return [3,
|
|
292
|
+
return [3, 11];
|
|
296
293
|
case 2:
|
|
297
294
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token.paymentData);
|
|
298
295
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
299
|
-
return [3,
|
|
300
|
-
case 3:
|
|
296
|
+
return [3, 12];
|
|
297
|
+
case 3:
|
|
298
|
+
setLoading(true);
|
|
299
|
+
return [4, appService.tapTokenization(event.payment.token.paymentData)];
|
|
301
300
|
case 4:
|
|
302
|
-
data =
|
|
301
|
+
data = _t.sent();
|
|
303
302
|
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
304
303
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
305
304
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
306
|
-
return [3,
|
|
305
|
+
return [3, 12];
|
|
307
306
|
case 5:
|
|
307
|
+
setLoading(true);
|
|
308
|
+
return [4, appService.tapTokenization(event.payment.token.paymentData)];
|
|
309
|
+
case 6:
|
|
310
|
+
tokenId = (_t.sent()).id;
|
|
311
|
+
supportCurrency = ((_d = (_c = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _c === void 0 ? void 0 : _c.supported_currencies) !== null && _d !== void 0 ? _d : [])[0];
|
|
312
|
+
transactionRequest = {
|
|
313
|
+
auto: (_e = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _e === void 0 ? void 0 : _e.auto,
|
|
314
|
+
amount: order.amount,
|
|
315
|
+
currency: order.currency,
|
|
316
|
+
selected_amount: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.amount,
|
|
317
|
+
selected_currency: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.currency,
|
|
318
|
+
customer: (customer === null || customer === void 0 ? void 0 : customer.id)
|
|
319
|
+
? { id: customer === null || customer === void 0 ? void 0 : customer.id }
|
|
320
|
+
: {
|
|
321
|
+
email: (_f = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _f === void 0 ? void 0 : _f.email,
|
|
322
|
+
first_name: ((_g = customer === null || customer === void 0 ? void 0 : customer.name) === null || _g === void 0 ? void 0 : _g.length) ? customer.name[0].first : '',
|
|
323
|
+
last_name: ((_h = customer === null || customer === void 0 ? void 0 : customer.name) === null || _h === void 0 ? void 0 : _h.length) ? customer.name[0].last : '',
|
|
324
|
+
phone: {
|
|
325
|
+
country_code: (_l = (_k = (_j = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _j === void 0 ? void 0 : _j.phone) === null || _k === void 0 ? void 0 : _k.countryCode) !== null && _l !== void 0 ? _l : '',
|
|
326
|
+
number: (_p = (_o = (_m = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _m === void 0 ? void 0 : _m.phone) === null || _o === void 0 ? void 0 : _o.number) !== null && _p !== void 0 ? _p : ''
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
fee: 0,
|
|
330
|
+
merchant: {
|
|
331
|
+
id: (_r = (_q = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _q === void 0 ? void 0 : _q.id) !== null && _r !== void 0 ? _r : ''
|
|
332
|
+
},
|
|
333
|
+
order: (_s = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _s === void 0 ? void 0 : _s.order,
|
|
334
|
+
product: 'Apple-Pay-Button',
|
|
335
|
+
save_card: false,
|
|
336
|
+
source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
|
|
337
|
+
threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.authentication,
|
|
338
|
+
hashstring: operator.hashstring,
|
|
339
|
+
redirect: redirect,
|
|
340
|
+
metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
|
|
341
|
+
post: post,
|
|
342
|
+
payment_agreement: transaction === null || transaction === void 0 ? void 0 : transaction.paymentAgreement,
|
|
343
|
+
destinations: transaction === null || transaction === void 0 ? void 0 : transaction.destinations,
|
|
344
|
+
reference: {
|
|
345
|
+
order: order === null || order === void 0 ? void 0 : order.reference,
|
|
346
|
+
transaction: transaction === null || transaction === void 0 ? void 0 : transaction.reference
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
if (!(scope === Scope.AUTHORIZE)) return [3, 8];
|
|
350
|
+
return [4, appService.createAuthorize(transactionRequest)];
|
|
351
|
+
case 7:
|
|
352
|
+
_b = _t.sent();
|
|
353
|
+
return [3, 10];
|
|
354
|
+
case 8: return [4, appService.createCharge(transactionRequest)];
|
|
355
|
+
case 9:
|
|
356
|
+
_b = _t.sent();
|
|
357
|
+
_t.label = 10;
|
|
358
|
+
case 10:
|
|
359
|
+
transactionResponse = _b;
|
|
360
|
+
successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
|
|
361
|
+
if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
|
|
362
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
setError === null || setError === void 0 ? void 0 : setError(true);
|
|
366
|
+
}
|
|
367
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
|
|
368
|
+
return [3, 12];
|
|
369
|
+
case 11:
|
|
308
370
|
console.error('We only support AppleToken and TapToken for now');
|
|
309
371
|
console.info('Completing payment with status: STATUS_FAILURE');
|
|
310
372
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
311
|
-
|
|
312
|
-
case
|
|
313
|
-
case
|
|
314
|
-
error_2 =
|
|
373
|
+
_t.label = 12;
|
|
374
|
+
case 12: return [3, 15];
|
|
375
|
+
case 13:
|
|
376
|
+
error_2 = _t.sent();
|
|
315
377
|
if (debug)
|
|
316
378
|
console.error('error in onpaymentauthorized', error_2);
|
|
317
379
|
setError(true);
|
|
318
380
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
319
381
|
throw error_2;
|
|
320
|
-
case
|
|
382
|
+
case 14:
|
|
321
383
|
setLoading(false);
|
|
322
|
-
setIsRounded === null || setIsRounded === void 0 ? void 0 : setIsRounded(false);
|
|
323
384
|
return [7];
|
|
324
|
-
case
|
|
385
|
+
case 15: return [2];
|
|
325
386
|
}
|
|
326
387
|
});
|
|
327
388
|
}); };
|
|
@@ -364,6 +425,9 @@ export var useApplePay = function (_a) {
|
|
|
364
425
|
useEffect(function () {
|
|
365
426
|
initialize(metaData);
|
|
366
427
|
}, []);
|
|
428
|
+
useEffect(function () {
|
|
429
|
+
setIsRounded(error || success || loading);
|
|
430
|
+
}, [error, success, loading]);
|
|
367
431
|
useEffect(function () {
|
|
368
432
|
if (!error)
|
|
369
433
|
return;
|
|
@@ -373,7 +437,7 @@ export var useApplePay = function (_a) {
|
|
|
373
437
|
setIsRounded(false);
|
|
374
438
|
}, 2000);
|
|
375
439
|
return function () { return clearTimeout(timer); };
|
|
376
|
-
}, [error]);
|
|
440
|
+
}, [error, loading]);
|
|
377
441
|
return {
|
|
378
442
|
onClick: handleClick,
|
|
379
443
|
loading: loading,
|
|
@@ -384,6 +448,7 @@ export var useApplePay = function (_a) {
|
|
|
384
448
|
applePayRequestConfiguration: applePayRequestConfiguration,
|
|
385
449
|
mappedProps: mappedProps,
|
|
386
450
|
theme: theme,
|
|
451
|
+
initialLoading: initialLoading,
|
|
387
452
|
isRounded: isRounded,
|
|
388
453
|
success: success,
|
|
389
454
|
error: error,
|
|
@@ -3,7 +3,7 @@ interface ApplePayRequestData {
|
|
|
3
3
|
isIframeIntegration: boolean;
|
|
4
4
|
onError?: (error: any) => void;
|
|
5
5
|
onSuccess?: (data: Record<string, any>) => void;
|
|
6
|
-
|
|
6
|
+
setLoading?: (loading: boolean) => void;
|
|
7
7
|
setSuccess?: (success: boolean) => void;
|
|
8
8
|
setError?: (error: boolean) => void;
|
|
9
9
|
scope: typeof Scope[keyof typeof Scope];
|
|
@@ -16,5 +16,5 @@ interface ApplePayRequestData {
|
|
|
16
16
|
redirect?: ApplePayButtonProps['redirect'];
|
|
17
17
|
post?: ApplePayButtonProps['post'];
|
|
18
18
|
}
|
|
19
|
-
export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess,
|
|
19
|
+
export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
|
|
20
20
|
export {};
|
|
@@ -39,7 +39,7 @@ import appService from '../api/app.service';
|
|
|
39
39
|
import { Scope, CHARGE_CODE } from '../@types';
|
|
40
40
|
var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
|
|
41
41
|
export var useMerchantApplePay = function (_a) {
|
|
42
|
-
var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess,
|
|
42
|
+
var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, setLoading = _a.setLoading, setError = _a.setError, setSuccess = _a.setSuccess, scope = _a.scope, profileData = _a.profileData, order = _a.order, customer = _a.customer, transaction = _a.transaction, operator = _a.operator, redirect = _a.redirect, post = _a.post;
|
|
43
43
|
var onMessageReceived = React.useCallback(function (_a) {
|
|
44
44
|
var message = _a.data;
|
|
45
45
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -53,7 +53,7 @@ export var useMerchantApplePay = function (_a) {
|
|
|
53
53
|
return [2];
|
|
54
54
|
_w.label = 1;
|
|
55
55
|
case 1:
|
|
56
|
-
_w.trys.push([1, 13, ,
|
|
56
|
+
_w.trys.push([1, 13, 14, 15]);
|
|
57
57
|
_c = scope;
|
|
58
58
|
switch (_c) {
|
|
59
59
|
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
@@ -66,7 +66,7 @@ export var useMerchantApplePay = function (_a) {
|
|
|
66
66
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
67
67
|
return [3, 12];
|
|
68
68
|
case 3:
|
|
69
|
-
|
|
69
|
+
setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
|
|
70
70
|
return [4, appService.tapTokenization(data)];
|
|
71
71
|
case 4:
|
|
72
72
|
response = _w.sent();
|
|
@@ -74,7 +74,7 @@ export var useMerchantApplePay = function (_a) {
|
|
|
74
74
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
|
|
75
75
|
return [3, 12];
|
|
76
76
|
case 5:
|
|
77
|
-
|
|
77
|
+
setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
|
|
78
78
|
return [4, appService.tapTokenization(data)];
|
|
79
79
|
case 6:
|
|
80
80
|
tokenId = (_w.sent()).id;
|
|
@@ -140,7 +140,7 @@ export var useMerchantApplePay = function (_a) {
|
|
|
140
140
|
console.error("We only support: ".concat(Object.values(Scope).join(', '), " for now"));
|
|
141
141
|
onError === null || onError === void 0 ? void 0 : onError({ message: "We only support: ".concat(Object.values(Scope).join(', '), " for now"), code: '400' });
|
|
142
142
|
return [3, 12];
|
|
143
|
-
case 12: return [3,
|
|
143
|
+
case 12: return [3, 15];
|
|
144
144
|
case 13:
|
|
145
145
|
e_1 = _w.sent();
|
|
146
146
|
if (!onError)
|
|
@@ -158,8 +158,11 @@ export var useMerchantApplePay = function (_a) {
|
|
|
158
158
|
return [2];
|
|
159
159
|
}
|
|
160
160
|
onError(e_1);
|
|
161
|
-
return [3,
|
|
162
|
-
case 14:
|
|
161
|
+
return [3, 15];
|
|
162
|
+
case 14:
|
|
163
|
+
setLoading === null || setLoading === void 0 ? void 0 : setLoading(false);
|
|
164
|
+
return [7];
|
|
165
|
+
case 15: return [2];
|
|
163
166
|
}
|
|
164
167
|
});
|
|
165
168
|
});
|
package/build/utils/config.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export declare const getApplePayRequest: ({ order, customer, supportedNetworks,
|
|
|
10
10
|
export declare const rsaSetup: (key: string) => (string: string) => string;
|
|
11
11
|
export declare function generateApplicationHeader(obj: Record<string, string | any>): string;
|
|
12
12
|
export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: Pick<MetaData, 'merchant' | 'payment_options'> & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => ApplePayRequestData;
|
|
13
|
+
export declare const shallRenderApplePay: () => boolean;
|
package/build/utils/config.js
CHANGED