@tap-payments/apple-pay-button 0.0.73-development → 0.0.75-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.
@@ -54,11 +54,10 @@ import { getApplePayPaymentMethod, getDefaultThemeMode } from '../utils';
54
54
  import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
55
55
  import { ChargeCode, mapingInterface } from '@tap-payments/acceptance-sdk';
56
56
  export var useApplePay = function (_a) {
57
- var _b;
57
+ var _b, _c;
58
58
  var buttonProps = _a.buttonProps;
59
- var _c = useState(), applePayRequestData = _c[0], setApplePayRequestData = _c[1];
60
- var _d = useState(), applePayRequestConfiguration = _d[0], setApplePayRequestConfiguration = _d[1];
61
- var _e = useState(), paymentMethodIdentifier = _e[0], setPaymentMethodIdentifier = _e[1];
59
+ var _d = useState(), applePayRequestData = _d[0], setApplePayRequestData = _d[1];
60
+ var _e = useState(), applePayRequestConfiguration = _e[0], setApplePayRequestConfiguration = _e[1];
62
61
  var _f = useState(), profileData = _f[0], setProfile = _f[1];
63
62
  var _g = useState(false), disabled = _g[0], setDisabled = _g[1];
64
63
  var _h = useState(false), initialLoading = _h[0], setInitialLoading = _h[1];
@@ -66,9 +65,6 @@ export var useApplePay = function (_a) {
66
65
  var _k = useState(false), success = _k[0], setSuccess = _k[1];
67
66
  var _l = useState(false), loading = _l[0], setLoading = _l[1];
68
67
  var _m = useState(false), isRounded = _m[0], setIsRounded = _m[1];
69
- var domainValidator = useMemo(function () {
70
- return (paymentMethodIdentifier !== null && paymentMethodIdentifier !== void 0 ? paymentMethodIdentifier : '').toLowerCase().includes('knet') ? 'knet' : 'tap';
71
- }, [paymentMethodIdentifier]);
72
68
  var mappedProps = __assign(__assign({}, buttonProps), { interface: mapingInterface(buttonProps.interface) });
73
69
  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, headers = mappedProps.headers, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect;
74
70
  var isIframeIntegration = buttonProps.integration === 'iframe';
@@ -97,14 +93,14 @@ export var useApplePay = function (_a) {
97
93
  }, [profileData]);
98
94
  var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
99
95
  var merchantProfile, payment_options, headers_1, data, applePayPreparedData, err_1;
100
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
101
- return __generator(this, function (_p) {
102
- switch (_p.label) {
96
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
97
+ return __generator(this, function (_o) {
98
+ switch (_o.label) {
103
99
  case 0:
104
100
  setInitialLoading(true);
105
- _p.label = 1;
101
+ _o.label = 1;
106
102
  case 1:
107
- _p.trys.push([1, 7, , 8]);
103
+ _o.trys.push([1, 7, , 8]);
108
104
  if (!shallRenderApplePay()) {
109
105
  throw new Error('The device/customer is not eligible to use ApplePay');
110
106
  }
@@ -117,7 +113,7 @@ export var useApplePay = function (_a) {
117
113
  if (!headers) return [3, 3];
118
114
  return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { authorization: operator.publicKey }))];
119
115
  case 2:
120
- _p.sent();
116
+ _o.sent();
121
117
  return [3, 5];
122
118
  case 3: return [4, appService.setBrowserHeaders({
123
119
  locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
@@ -125,8 +121,8 @@ export var useApplePay = function (_a) {
125
121
  pk: operator.publicKey
126
122
  })];
127
123
  case 4:
128
- _p.sent();
129
- _p.label = 5;
124
+ _o.sent();
125
+ _o.label = 5;
130
126
  case 5: return [4, appService.checkoutProfile({
131
127
  supported_payment_methods: ['APPLE_PAY'],
132
128
  supported_currencies: [order.currency],
@@ -158,24 +154,23 @@ export var useApplePay = function (_a) {
158
154
  ] })
159
155
  })];
160
156
  case 6:
161
- data = _p.sent();
157
+ data = _o.sent();
162
158
  if (debug)
163
159
  console.log('merchant configuration: ', data);
164
160
  setProfile(data);
165
161
  applePayPreparedData = prepareApplePayRequest(__assign(__assign({}, data), { order: order, acceptance: acceptance, customer: customer }));
166
162
  setApplePayRequestData(applePayPreparedData.applePaySessionRequest);
167
- setPaymentMethodIdentifier((_k = merchant.identifier) !== null && _k !== void 0 ? _k : applePayPreparedData.paymentMethod.identifier);
168
- onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((_m = (_l = data.payment_options) === null || _l === void 0 ? void 0 : _l.order) === null || _m === void 0 ? void 0 : _m.id);
163
+ onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((_l = (_k = data.payment_options) === null || _k === void 0 ? void 0 : _k.order) === null || _l === void 0 ? void 0 : _l.id);
169
164
  setApplePayRequestConfiguration({
170
165
  BASE_URL: MW_BASE_URL,
171
166
  headers: getAxiosGlobalHeaders(),
172
- merchant: __assign(__assign({}, data.merchant), { id: merchant.id || ((_o = data.merchant) === null || _o === void 0 ? void 0 : _o.id) })
167
+ merchant: __assign(__assign({}, data.merchant), { id: merchant.id || ((_m = data.merchant) === null || _m === void 0 ? void 0 : _m.id) })
173
168
  });
174
169
  setInitialLoading(false);
175
170
  onReady === null || onReady === void 0 ? void 0 : onReady();
176
171
  return [3, 8];
177
172
  case 7:
178
- err_1 = _p.sent();
173
+ err_1 = _o.sent();
179
174
  onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
180
175
  console.log('error in initialize', err_1);
181
176
  return [3, 8];
@@ -183,6 +178,16 @@ export var useApplePay = function (_a) {
183
178
  }
184
179
  });
185
180
  }); };
181
+ var isTapIdentifier = function (id) { return (id.toLowerCase().includes('knet') ? 'knet' : 'tap'); };
182
+ var domainValidator = useMemo(function () {
183
+ var _a, _b, _c;
184
+ if (merchant.identifier)
185
+ return isTapIdentifier(merchant.identifier);
186
+ if (!((_a = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _a === void 0 ? void 0 : _a.payment_methods))
187
+ return '';
188
+ var identifier = (_c = (_b = getApplePayPaymentMethod(profileData.payment_options.payment_methods)) === null || _b === void 0 ? void 0 : _b.identifier) !== null && _c !== void 0 ? _c : '';
189
+ return isTapIdentifier(identifier);
190
+ }, [(_c = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _c === void 0 ? void 0 : _c.payment_methods, merchant === null || merchant === void 0 ? void 0 : merchant.identifier]);
186
191
  var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
187
192
  var ApplePaySession, session_1;
188
193
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.73-development",
3
+ "version": "0.0.75-development",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",