@tap-payments/apple-pay-button 1.2.4 → 1.2.5

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.
@@ -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.errors || 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
- var _a;
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);
@@ -367,21 +367,7 @@ export var useApplePay = function (_a) {
367
367
  session_1.begin();
368
368
  }
369
369
  catch (e) {
370
- if (!onError)
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);
370
+ onError && onError(shapeApplePayError(e));
385
371
  }
386
372
  return [2];
387
373
  });
@@ -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
+ };
@@ -1 +1,2 @@
1
1
  export * from './html';
2
+ export * from './error';
@@ -1 +1,2 @@
1
1
  export * from './html';
2
+ export * from './error';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",