@tap-payments/apple-pay-button 0.0.76-development → 0.0.78-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/@types/checkoutProfile.d.ts +1 -0
- package/build/api.d.ts +8 -13
- package/build/api.js +3 -2
- package/build/hooks/useApplePay.js +39 -15
- package/build/utils/config.d.ts +4 -1
- package/build/utils/config.js +1 -1
- package/package.json +1 -1
package/build/api.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { MerchantResponse, CheckoutProfileRequest, ChargeRequestBody, AuthorizeRequestBody } from './@types';
|
|
2
2
|
export declare const setAxiosGlobalHeaders: (headers: Record<string, string>) => void;
|
|
3
3
|
export declare const getAxiosGlobalHeaders: () => {
|
|
4
|
-
[x: string]:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
put?: import("axios").AxiosHeaders | undefined;
|
|
12
|
-
patch?: import("axios").AxiosHeaders | undefined;
|
|
13
|
-
purge?: import("axios").AxiosHeaders | undefined;
|
|
14
|
-
unlink?: import("axios").AxiosHeaders | undefined;
|
|
15
|
-
common?: import("axios").AxiosHeaders | undefined;
|
|
4
|
+
[x: string]: import("axios").AxiosHeaderValue | undefined;
|
|
5
|
+
Accept?: import("axios").AxiosHeaderValue | undefined;
|
|
6
|
+
"Content-Length"?: import("axios").AxiosHeaderValue | undefined;
|
|
7
|
+
"User-Agent"?: import("axios").AxiosHeaderValue | undefined;
|
|
8
|
+
"Content-Encoding"?: import("axios").AxiosHeaderValue | undefined;
|
|
9
|
+
Authorization?: import("axios").AxiosHeaderValue | undefined;
|
|
10
|
+
'Content-Type'?: import("axios").AxiosHeaderValue | undefined;
|
|
16
11
|
};
|
|
17
12
|
declare class APPService {
|
|
18
13
|
setHttpHeaders(headers: Record<string, string>): Promise<void>;
|
|
@@ -25,7 +20,7 @@ declare class APPService {
|
|
|
25
20
|
merchant: any;
|
|
26
21
|
payment_options: any;
|
|
27
22
|
}>;
|
|
28
|
-
appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string): Promise<any>;
|
|
23
|
+
appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string, domainValidator: string): Promise<any>;
|
|
29
24
|
tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
|
|
30
25
|
createCharge(request: ChargeRequestBody): Promise<any>;
|
|
31
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, domainValidator) {
|
|
153
153
|
return __awaiter(this, void 0, void 0, function () {
|
|
154
154
|
var body, data;
|
|
155
155
|
return __generator(this, function (_a) {
|
|
@@ -160,7 +160,8 @@ var APPService = (function () {
|
|
|
160
160
|
origin: merchantRegisteredDomain,
|
|
161
161
|
merchantIdentifier: merchantIdentifier,
|
|
162
162
|
merchantId: merchant.id,
|
|
163
|
-
merchantName: merchant.name
|
|
163
|
+
merchantName: merchant.name,
|
|
164
|
+
domainValidator: domainValidator
|
|
164
165
|
};
|
|
165
166
|
return [4, axiosInstance.post('/validatemerchant', body)];
|
|
166
167
|
case 1:
|
|
@@ -45,6 +45,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
45
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
|
+
var t = {};
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
+
t[p] = s[p];
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
+
t[p[i]] = s[p[i]];
|
|
56
|
+
}
|
|
57
|
+
return t;
|
|
58
|
+
};
|
|
48
59
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
49
60
|
import { ApplePayVersion, MW_BASE_URL } from '../constants';
|
|
50
61
|
import { prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
|
|
@@ -54,17 +65,17 @@ import { getApplePayPaymentMethod, getDefaultThemeMode } from '../utils';
|
|
|
54
65
|
import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
|
|
55
66
|
import { ChargeCode, mappingInterface } from '@tap-payments/acceptance-sdk';
|
|
56
67
|
export var useApplePay = function (_a) {
|
|
57
|
-
var _b;
|
|
68
|
+
var _b, _c;
|
|
58
69
|
var buttonProps = _a.buttonProps;
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var
|
|
70
|
+
var _d = useState(), applePayRequestData = _d[0], setApplePayRequestData = _d[1];
|
|
71
|
+
var _e = useState(), applePayRequestConfiguration = _e[0], setApplePayRequestConfiguration = _e[1];
|
|
72
|
+
var _f = useState(), profileData = _f[0], setProfile = _f[1];
|
|
73
|
+
var _g = useState(false), disabled = _g[0], setDisabled = _g[1];
|
|
74
|
+
var _h = useState(false), initialLoading = _h[0], setInitialLoading = _h[1];
|
|
75
|
+
var _j = useState(false), error = _j[0], setError = _j[1];
|
|
76
|
+
var _k = useState(false), success = _k[0], setSuccess = _k[1];
|
|
77
|
+
var _l = useState(false), loading = _l[0], setLoading = _l[1];
|
|
78
|
+
var _m = useState(false), isRounded = _m[0], setIsRounded = _m[1];
|
|
68
79
|
var mappedProps = __assign(__assign({}, buttonProps), { interface: mappingInterface(buttonProps.interface) });
|
|
69
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;
|
|
70
81
|
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
@@ -92,7 +103,7 @@ export var useApplePay = function (_a) {
|
|
|
92
103
|
return getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
93
104
|
}, [profileData]);
|
|
94
105
|
var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
95
|
-
var
|
|
106
|
+
var headers_1, rest, applePayPreparedData_1, data, applePayPreparedData, err_1;
|
|
96
107
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
97
108
|
return __generator(this, function (_o) {
|
|
98
109
|
switch (_o.label) {
|
|
@@ -105,9 +116,11 @@ export var useApplePay = function (_a) {
|
|
|
105
116
|
throw new Error('The device/customer is not eligible to use ApplePay');
|
|
106
117
|
}
|
|
107
118
|
if (metaData) {
|
|
108
|
-
|
|
119
|
+
headers_1 = metaData.headers, rest = __rest(metaData, ["headers"]);
|
|
109
120
|
setAxiosGlobalHeaders(__assign({}, headers_1));
|
|
110
|
-
setProfile(
|
|
121
|
+
setProfile(rest);
|
|
122
|
+
applePayPreparedData_1 = prepareApplePayRequest(__assign(__assign({}, rest), { order: order, acceptance: acceptance, customer: customer }));
|
|
123
|
+
setApplePayRequestData(applePayPreparedData_1.applePaySessionRequest);
|
|
111
124
|
setInitialLoading(false);
|
|
112
125
|
return [2];
|
|
113
126
|
}
|
|
@@ -159,7 +172,8 @@ export var useApplePay = function (_a) {
|
|
|
159
172
|
if (debug)
|
|
160
173
|
console.log('merchant configuration: ', data);
|
|
161
174
|
setProfile(data);
|
|
162
|
-
|
|
175
|
+
applePayPreparedData = prepareApplePayRequest(__assign(__assign({}, data), { order: order, acceptance: acceptance, customer: customer }));
|
|
176
|
+
setApplePayRequestData(applePayPreparedData.applePaySessionRequest);
|
|
163
177
|
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);
|
|
164
178
|
setApplePayRequestConfiguration({
|
|
165
179
|
BASE_URL: MW_BASE_URL,
|
|
@@ -178,6 +192,16 @@ export var useApplePay = function (_a) {
|
|
|
178
192
|
}
|
|
179
193
|
});
|
|
180
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]);
|
|
181
205
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
182
206
|
var ApplePaySession, session_1;
|
|
183
207
|
var _a;
|
|
@@ -219,7 +243,7 @@ export var useApplePay = function (_a) {
|
|
|
219
243
|
if (debug) {
|
|
220
244
|
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(window.location.hostname));
|
|
221
245
|
}
|
|
222
|
-
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)];
|
|
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, domainValidator)];
|
|
223
247
|
case 2:
|
|
224
248
|
merchantSession = _a.sent();
|
|
225
249
|
if (debug)
|
package/build/utils/config.d.ts
CHANGED
|
@@ -7,5 +7,8 @@ export declare const getApplePayRequest: ({ order, customer, supportedNetworks,
|
|
|
7
7
|
countryCode: string;
|
|
8
8
|
name: string;
|
|
9
9
|
}) => ApplePayRequestData;
|
|
10
|
-
export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: Pick<MetaData, 'merchant' | 'payment_options'> & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) =>
|
|
10
|
+
export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: Pick<MetaData, 'merchant' | 'payment_options'> & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => {
|
|
11
|
+
applePaySessionRequest: ApplePayRequestData;
|
|
12
|
+
paymentMethod: PaymentMethod;
|
|
13
|
+
};
|
|
11
14
|
export declare const shallRenderApplePay: () => boolean;
|
package/build/utils/config.js
CHANGED
|
@@ -57,7 +57,7 @@ export var prepareApplePayRequest = function (_a) {
|
|
|
57
57
|
merchantCapabilities: getMerchantCapabilities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedFundSource),
|
|
58
58
|
name: merchant.name
|
|
59
59
|
});
|
|
60
|
-
return request;
|
|
60
|
+
return { applePaySessionRequest: request, paymentMethod: paymentMethod };
|
|
61
61
|
};
|
|
62
62
|
export var shallRenderApplePay = function () {
|
|
63
63
|
var https = window.location.protocol === 'https:';
|