@tap-payments/apple-pay-button 1.2.4 → 1.2.6
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/hooks/useApplePay.js +6 -21
- package/build/utils/error.d.ts +1 -0
- package/build/utils/error.js +13 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +1 -0
- package/package.json +1 -1
|
@@ -61,6 +61,7 @@ import appService from '../api/app.service';
|
|
|
61
61
|
import { ApplePayVersion, FALLBACK_MERCHANT_IDENTIFIER, Integration } from '../constants';
|
|
62
62
|
import { setAxiosGlobalHeaders } from '../api/httpClient';
|
|
63
63
|
import { getApplePayPaymentMethod, getApplePayRequest, validateCurrency, validateSupportedNetworks } from '../utils/config';
|
|
64
|
+
import { shapeApplePayError } from '../utils';
|
|
64
65
|
import { getMerchantCapaplities } from '../utils/defaultValues';
|
|
65
66
|
import { useApplePayScript } from './useApplePayScript';
|
|
66
67
|
export var useApplePay = function (_a) {
|
|
@@ -139,7 +140,7 @@ export var useApplePay = function (_a) {
|
|
|
139
140
|
return [3, 6];
|
|
140
141
|
case 4:
|
|
141
142
|
err_1 = _h.sent();
|
|
142
|
-
onError && onError(err_1
|
|
143
|
+
onError && onError(shapeApplePayError(err_1));
|
|
143
144
|
return [3, 6];
|
|
144
145
|
case 5:
|
|
145
146
|
setLoading(false);
|
|
@@ -155,8 +156,7 @@ export var useApplePay = function (_a) {
|
|
|
155
156
|
}, [isScriptLoaded, initialize, metaData]);
|
|
156
157
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
157
158
|
var ApplePaySession, paymentMethod_1, currency, cardBrands, request, session_1;
|
|
158
|
-
|
|
159
|
-
return __generator(this, function (_b) {
|
|
159
|
+
return __generator(this, function (_a) {
|
|
160
160
|
ApplePaySession = window.ApplePaySession;
|
|
161
161
|
if (!ApplePaySession) {
|
|
162
162
|
setDisabled(true);
|
|
@@ -266,8 +266,6 @@ export var useApplePay = function (_a) {
|
|
|
266
266
|
return [3, 8];
|
|
267
267
|
case 7:
|
|
268
268
|
console.error('We only support AppleToken and TapToken for now');
|
|
269
|
-
console.info('Completing payment with status: STATUS_FAILURE');
|
|
270
|
-
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
271
269
|
throw new Error('We only support AppleToken and TapToken for now');
|
|
272
270
|
case 8: return [3, 11];
|
|
273
271
|
case 9:
|
|
@@ -275,7 +273,8 @@ export var useApplePay = function (_a) {
|
|
|
275
273
|
if (debug)
|
|
276
274
|
console.error('error in onpaymentauthorized', error_2);
|
|
277
275
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
278
|
-
|
|
276
|
+
onError && onError(shapeApplePayError(error_2));
|
|
277
|
+
return [3, 11];
|
|
279
278
|
case 10:
|
|
280
279
|
setLoading(false);
|
|
281
280
|
return [7];
|
|
@@ -367,21 +366,7 @@ export var useApplePay = function (_a) {
|
|
|
367
366
|
session_1.begin();
|
|
368
367
|
}
|
|
369
368
|
catch (e) {
|
|
370
|
-
|
|
371
|
-
return [2];
|
|
372
|
-
if (e.errors) {
|
|
373
|
-
onError(e.errors);
|
|
374
|
-
return [2];
|
|
375
|
-
}
|
|
376
|
-
if ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data.errors) {
|
|
377
|
-
onError(e.response.data.errors);
|
|
378
|
-
return [2];
|
|
379
|
-
}
|
|
380
|
-
if (e.message) {
|
|
381
|
-
onError([{ description: e.message, code: '400' }]);
|
|
382
|
-
return [2];
|
|
383
|
-
}
|
|
384
|
-
onError(e);
|
|
369
|
+
onError && onError(shapeApplePayError(e));
|
|
385
370
|
}
|
|
386
371
|
return [2];
|
|
387
372
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const shapeApplePayError: (error: any) => any;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export var shapeApplePayError = function (error) {
|
|
2
|
+
var _a, _b;
|
|
3
|
+
if (error === null || error === void 0 ? void 0 : error.errors) {
|
|
4
|
+
return error.errors;
|
|
5
|
+
}
|
|
6
|
+
if ((_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errors) {
|
|
7
|
+
return error.response.data.errors;
|
|
8
|
+
}
|
|
9
|
+
if (error === null || error === void 0 ? void 0 : error.message) {
|
|
10
|
+
return [{ description: error.message, code: '400' }];
|
|
11
|
+
}
|
|
12
|
+
return error;
|
|
13
|
+
};
|
package/build/utils/index.d.ts
CHANGED
package/build/utils/index.js
CHANGED