@tap-payments/apple-pay-button 0.0.79-development → 0.0.81-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/api.d.ts +1 -1
- package/build/api.js +2 -3
- package/build/hooks/useApplePay.js +36 -46
- package/build/hooks/useMerchantApplePay.d.ts +1 -1
- package/package.json +1 -1
package/build/api.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare class APPService {
|
|
|
20
20
|
merchant: any;
|
|
21
21
|
payment_options: any;
|
|
22
22
|
}>;
|
|
23
|
-
appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string
|
|
23
|
+
appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string): Promise<any>;
|
|
24
24
|
tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
|
|
25
25
|
createCharge(request: ChargeRequestBody): Promise<any>;
|
|
26
26
|
createAuthorize(request: AuthorizeRequestBody): Promise<any>;
|
package/build/api.js
CHANGED
|
@@ -149,7 +149,7 @@ var APPService = (function () {
|
|
|
149
149
|
enumerable: false,
|
|
150
150
|
configurable: true,
|
|
151
151
|
writable: true,
|
|
152
|
-
value: function (merchant, validationURL, merchantRegisteredDomain, merchantIdentifier
|
|
152
|
+
value: function (merchant, validationURL, merchantRegisteredDomain, merchantIdentifier) {
|
|
153
153
|
return __awaiter(this, void 0, void 0, function () {
|
|
154
154
|
var body, data;
|
|
155
155
|
return __generator(this, function (_a) {
|
|
@@ -160,8 +160,7 @@ var APPService = (function () {
|
|
|
160
160
|
origin: merchantRegisteredDomain,
|
|
161
161
|
merchantIdentifier: merchantIdentifier,
|
|
162
162
|
merchantId: merchant.id,
|
|
163
|
-
merchantName: merchant.name
|
|
164
|
-
domainValidator: domainValidator
|
|
163
|
+
merchantName: merchant.name
|
|
165
164
|
};
|
|
166
165
|
return [4, axiosInstance.post('/validatemerchant', body)];
|
|
167
166
|
case 1:
|
|
@@ -65,17 +65,17 @@ import { getApplePayPaymentMethod, getDefaultThemeMode } from '../utils';
|
|
|
65
65
|
import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
|
|
66
66
|
import { ChargeCode, mappingInterface } from '@tap-payments/acceptance-sdk';
|
|
67
67
|
export var useApplePay = function (_a) {
|
|
68
|
-
var _b
|
|
68
|
+
var _b;
|
|
69
69
|
var buttonProps = _a.buttonProps;
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
var
|
|
76
|
-
var
|
|
77
|
-
var
|
|
78
|
-
var
|
|
70
|
+
var _c = useState(), applePayRequestData = _c[0], setApplePayRequestData = _c[1];
|
|
71
|
+
var _d = useState(), applePayRequestConfiguration = _d[0], setApplePayRequestConfiguration = _d[1];
|
|
72
|
+
var _e = useState(), profileData = _e[0], setProfile = _e[1];
|
|
73
|
+
var _f = useState(false), disabled = _f[0], setDisabled = _f[1];
|
|
74
|
+
var _g = useState(false), initialLoading = _g[0], setInitialLoading = _g[1];
|
|
75
|
+
var _h = useState(false), error = _h[0], setError = _h[1];
|
|
76
|
+
var _j = useState(false), success = _j[0], setSuccess = _j[1];
|
|
77
|
+
var _k = useState(false), loading = _k[0], setLoading = _k[1];
|
|
78
|
+
var _l = useState(false), isRounded = _l[0], setIsRounded = _l[1];
|
|
79
79
|
var mappedProps = __assign(__assign({}, buttonProps), { interface: mappingInterface(buttonProps.interface) });
|
|
80
80
|
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;
|
|
81
81
|
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
@@ -192,16 +192,6 @@ export var useApplePay = function (_a) {
|
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
194
|
}); };
|
|
195
|
-
var isTapIdentifier = function (id) { return (id.toLowerCase().includes('knet') ? 'knet' : 'tap'); };
|
|
196
|
-
var domainValidator = useMemo(function () {
|
|
197
|
-
var _a, _b, _c;
|
|
198
|
-
if (merchant.identifier)
|
|
199
|
-
return isTapIdentifier(merchant.identifier);
|
|
200
|
-
if (!((_a = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _a === void 0 ? void 0 : _a.payment_methods))
|
|
201
|
-
return '';
|
|
202
|
-
var identifier = (_c = (_b = getApplePayPaymentMethod(profileData.payment_options.payment_methods)) === null || _b === void 0 ? void 0 : _b.identifier) !== null && _c !== void 0 ? _c : '';
|
|
203
|
-
return isTapIdentifier(identifier);
|
|
204
|
-
}, [(_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]);
|
|
205
195
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
206
196
|
var ApplePaySession, session_1;
|
|
207
197
|
var _a;
|
|
@@ -243,7 +233,7 @@ export var useApplePay = function (_a) {
|
|
|
243
233
|
if (debug) {
|
|
244
234
|
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(window.location.hostname));
|
|
245
235
|
}
|
|
246
|
-
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id || profileData.merchant.id }), event.validationURL, window.location.hostname, merchant.identifier || merchant.id || profileData.merchant.id
|
|
236
|
+
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id || profileData.merchant.id }), event.validationURL, window.location.hostname, merchant.identifier || merchant.id || profileData.merchant.id)];
|
|
247
237
|
case 2:
|
|
248
238
|
merchantSession = _a.sent();
|
|
249
239
|
if (debug)
|
|
@@ -264,16 +254,16 @@ export var useApplePay = function (_a) {
|
|
|
264
254
|
});
|
|
265
255
|
}); };
|
|
266
256
|
session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
267
|
-
var _a, data, tokenId, supportCurrency, transactionRequest, transactionResponse,
|
|
268
|
-
var
|
|
269
|
-
return __generator(this, function (
|
|
270
|
-
switch (
|
|
257
|
+
var _a, _b, paymentData, paymentMethod, transactionIdentifier, data, tokenId, supportCurrency, transactionRequest, transactionResponse, _c, successState, error_2;
|
|
258
|
+
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
259
|
+
return __generator(this, function (_v) {
|
|
260
|
+
switch (_v.label) {
|
|
271
261
|
case 0:
|
|
272
262
|
if (debug)
|
|
273
263
|
console.info('onpaymentauthorized event', event);
|
|
274
|
-
|
|
264
|
+
_v.label = 1;
|
|
275
265
|
case 1:
|
|
276
|
-
|
|
266
|
+
_v.trys.push([1, 13, 14, 15]);
|
|
277
267
|
_a = scope;
|
|
278
268
|
switch (_a) {
|
|
279
269
|
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
@@ -288,10 +278,10 @@ export var useApplePay = function (_a) {
|
|
|
288
278
|
return [3, 12];
|
|
289
279
|
case 3:
|
|
290
280
|
setLoading(true);
|
|
291
|
-
|
|
292
|
-
return [4, appService.tapTokenization(__assign(__assign(
|
|
281
|
+
_b = (_d = event.payment.token) !== null && _d !== void 0 ? _d : {}, paymentData = _b.paymentData, paymentMethod = _b.paymentMethod, transactionIdentifier = _b.transactionIdentifier;
|
|
282
|
+
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
|
|
293
283
|
case 4:
|
|
294
|
-
data =
|
|
284
|
+
data = _v.sent();
|
|
295
285
|
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
296
286
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
297
287
|
return [3, 12];
|
|
@@ -300,10 +290,10 @@ export var useApplePay = function (_a) {
|
|
|
300
290
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
301
291
|
return [4, appService.tapTokenization(__assign(__assign(__assign({}, event.payment.token.paymentData), event.payment.token), { paymentData: undefined }))];
|
|
302
292
|
case 6:
|
|
303
|
-
tokenId = (
|
|
304
|
-
supportCurrency = ((
|
|
293
|
+
tokenId = (_v.sent()).id;
|
|
294
|
+
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];
|
|
305
295
|
transactionRequest = {
|
|
306
|
-
auto: (
|
|
296
|
+
auto: (_g = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _g === void 0 ? void 0 : _g.auto,
|
|
307
297
|
amount: order.amount,
|
|
308
298
|
currency: order.currency,
|
|
309
299
|
selected_amount: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.amount,
|
|
@@ -311,19 +301,19 @@ export var useApplePay = function (_a) {
|
|
|
311
301
|
customer: (customer === null || customer === void 0 ? void 0 : customer.id)
|
|
312
302
|
? { id: customer === null || customer === void 0 ? void 0 : customer.id }
|
|
313
303
|
: {
|
|
314
|
-
email: (
|
|
315
|
-
first_name: ((
|
|
316
|
-
last_name: ((
|
|
304
|
+
email: (_h = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _h === void 0 ? void 0 : _h.email,
|
|
305
|
+
first_name: ((_j = customer === null || customer === void 0 ? void 0 : customer.name) === null || _j === void 0 ? void 0 : _j.length) ? customer.name[0].first : '',
|
|
306
|
+
last_name: ((_k = customer === null || customer === void 0 ? void 0 : customer.name) === null || _k === void 0 ? void 0 : _k.length) ? customer.name[0].last : '',
|
|
317
307
|
phone: {
|
|
318
|
-
country_code: (
|
|
319
|
-
number: (
|
|
308
|
+
country_code: (_o = (_m = (_l = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _l === void 0 ? void 0 : _l.phone) === null || _m === void 0 ? void 0 : _m.countryCode) !== null && _o !== void 0 ? _o : '',
|
|
309
|
+
number: (_r = (_q = (_p = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _p === void 0 ? void 0 : _p.phone) === null || _q === void 0 ? void 0 : _q.number) !== null && _r !== void 0 ? _r : ''
|
|
320
310
|
}
|
|
321
311
|
},
|
|
322
312
|
fee: 0,
|
|
323
313
|
merchant: {
|
|
324
|
-
id: (
|
|
314
|
+
id: (_t = (_s = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _s === void 0 ? void 0 : _s.id) !== null && _t !== void 0 ? _t : ''
|
|
325
315
|
},
|
|
326
|
-
order: (
|
|
316
|
+
order: (_u = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _u === void 0 ? void 0 : _u.order,
|
|
327
317
|
product: 'Apple-Pay-Button',
|
|
328
318
|
save_card: false,
|
|
329
319
|
source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
|
|
@@ -342,14 +332,14 @@ export var useApplePay = function (_a) {
|
|
|
342
332
|
if (!(scope === Scope.AUTHORIZE)) return [3, 8];
|
|
343
333
|
return [4, appService.createAuthorize(transactionRequest)];
|
|
344
334
|
case 7:
|
|
345
|
-
|
|
335
|
+
_c = _v.sent();
|
|
346
336
|
return [3, 10];
|
|
347
337
|
case 8: return [4, appService.createCharge(transactionRequest)];
|
|
348
338
|
case 9:
|
|
349
|
-
|
|
350
|
-
|
|
339
|
+
_c = _v.sent();
|
|
340
|
+
_v.label = 10;
|
|
351
341
|
case 10:
|
|
352
|
-
transactionResponse =
|
|
342
|
+
transactionResponse = _c;
|
|
353
343
|
successState = scope === Scope.AUTHORIZE ? ChargeCode.AUTHORIZED : ChargeCode.SUCCESS;
|
|
354
344
|
if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
|
|
355
345
|
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
@@ -363,10 +353,10 @@ export var useApplePay = function (_a) {
|
|
|
363
353
|
console.error('We only support AppleToken and TapToken for now');
|
|
364
354
|
console.info('Completing payment with status: STATUS_FAILURE');
|
|
365
355
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
366
|
-
|
|
356
|
+
_v.label = 12;
|
|
367
357
|
case 12: return [3, 15];
|
|
368
358
|
case 13:
|
|
369
|
-
error_2 =
|
|
359
|
+
error_2 = _v.sent();
|
|
370
360
|
if (debug)
|
|
371
361
|
console.error('error in onpaymentauthorized', error_2);
|
|
372
362
|
setError(true);
|
|
@@ -6,7 +6,7 @@ interface ApplePayRequestData {
|
|
|
6
6
|
setLoading?: (loading: boolean) => void;
|
|
7
7
|
setSuccess?: (success: boolean) => void;
|
|
8
8
|
setError?: (error: boolean) => void;
|
|
9
|
-
scope: typeof Scope[keyof typeof Scope];
|
|
9
|
+
scope: (typeof Scope)[keyof typeof Scope];
|
|
10
10
|
profileData?: Pick<MetaData, 'merchant' | 'payment_options'>;
|
|
11
11
|
merchant: Pick<MetaData['merchant'], 'id'>;
|
|
12
12
|
order: ApplePayButtonProps['order'];
|