@tap-payments/apple-pay-button 0.0.59-development → 0.0.61-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/hooks/useApplePay.js +28 -28
- package/package.json +1 -1
|
@@ -52,20 +52,20 @@ import { ApplePayVersion } from '../constants';
|
|
|
52
52
|
import { Scope } from '../@types/enums';
|
|
53
53
|
import { prepareApplePayRequest } from '../utils/config';
|
|
54
54
|
import { useMerchantApplePay } from './useMerchantApplePay';
|
|
55
|
-
import { getApplePayPaymentMethod, getDefaultThemeMode, getDefaultValues, getFullThemeMode } from '../utils';
|
|
55
|
+
import { getApplePayPaymentMethod, getDefaultLocale, getDefaultThemeMode, getDefaultValues, getFullThemeMode } from '../utils';
|
|
56
56
|
export var useApplePay = function (_a) {
|
|
57
|
-
var _b, _c, _d, _e
|
|
57
|
+
var _b, _c, _d, _e;
|
|
58
58
|
var buttonProps = _a.buttonProps;
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var
|
|
59
|
+
var _f = useState(), applePayRequestData = _f[0], setApplePayRequestData = _f[1];
|
|
60
|
+
var _g = useState(), applePayRequestConfiguration = _g[0], setApplePayRequestConfiguration = _g[1];
|
|
61
|
+
var _h = useState(), profileData = _h[0], setProfile = _h[1];
|
|
62
|
+
var _j = useState(false), disabled = _j[0], setDisabled = _j[1];
|
|
63
|
+
var _k = useState(null), tapTheme = _k[0], setTapTheme = _k[1];
|
|
64
|
+
var _l = useState(), tapLocalization = _l[0], setTapLocalization = _l[1];
|
|
65
|
+
var _m = useState(false), error = _m[0], setError = _m[1];
|
|
66
|
+
var _o = useState(false), success = _o[0], setSuccess = _o[1];
|
|
67
|
+
var _p = useState(false), loading = _p[0], setLoading = _p[1];
|
|
68
|
+
var _q = useState(false), isRounded = _q[0], setIsRounded = _q[1];
|
|
69
69
|
var mappedProps = getDefaultValues(buttonProps);
|
|
70
70
|
var environment = mappedProps.environment, 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, integration = mappedProps.integration, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect;
|
|
71
71
|
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
@@ -86,8 +86,8 @@ export var useApplePay = function (_a) {
|
|
|
86
86
|
setSuccess: setSuccess,
|
|
87
87
|
setIsRounded: setIsRounded
|
|
88
88
|
});
|
|
89
|
-
var lang = (
|
|
90
|
-
var theme = getDefaultThemeMode((
|
|
89
|
+
var lang = getDefaultLocale((_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.locale);
|
|
90
|
+
var theme = getDefaultThemeMode((_c = mappedProps.interface) === null || _c === void 0 ? void 0 : _c.theme);
|
|
91
91
|
var applePayPaymentMethodOptions = useMemo(function () {
|
|
92
92
|
if (!profileData)
|
|
93
93
|
return null;
|
|
@@ -120,8 +120,8 @@ export var useApplePay = function (_a) {
|
|
|
120
120
|
applePayPaymentMethodOptions,
|
|
121
121
|
lang,
|
|
122
122
|
profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods,
|
|
123
|
-
(
|
|
124
|
-
(
|
|
123
|
+
(_d = buttonProps.interface) === null || _d === void 0 ? void 0 : _d.colorStyle,
|
|
124
|
+
(_e = buttonProps.interface) === null || _e === void 0 ? void 0 : _e.theme
|
|
125
125
|
]);
|
|
126
126
|
var showLoader = useMemo(function () {
|
|
127
127
|
var _a;
|
|
@@ -129,16 +129,16 @@ export var useApplePay = function (_a) {
|
|
|
129
129
|
}, [mappedProps]);
|
|
130
130
|
var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
131
131
|
var merchantProfile, payment_options, headers_1, data, err_1;
|
|
132
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
133
|
-
return __generator(this, function (
|
|
134
|
-
switch (
|
|
132
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
133
|
+
return __generator(this, function (_o) {
|
|
134
|
+
switch (_o.label) {
|
|
135
135
|
case 0:
|
|
136
136
|
setLoading(true);
|
|
137
137
|
appService.setEnv(environment);
|
|
138
138
|
appService.setBaseUrl();
|
|
139
|
-
|
|
139
|
+
_o.label = 1;
|
|
140
140
|
case 1:
|
|
141
|
-
|
|
141
|
+
_o.trys.push([1, 7, 8, 9]);
|
|
142
142
|
if (metaData) {
|
|
143
143
|
merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers_1 = metaData.headers;
|
|
144
144
|
setAxiosGlobalHeaders(__assign({}, headers_1));
|
|
@@ -148,7 +148,7 @@ export var useApplePay = function (_a) {
|
|
|
148
148
|
if (!headers) return [3, 3];
|
|
149
149
|
return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { authorization: operator.publicKey }))];
|
|
150
150
|
case 2:
|
|
151
|
-
|
|
151
|
+
_o.sent();
|
|
152
152
|
return [3, 5];
|
|
153
153
|
case 3: return [4, appService.setBrowserHeaders({
|
|
154
154
|
locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
|
|
@@ -156,8 +156,8 @@ export var useApplePay = function (_a) {
|
|
|
156
156
|
pk: operator.publicKey
|
|
157
157
|
})];
|
|
158
158
|
case 4:
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
_o.sent();
|
|
160
|
+
_o.label = 5;
|
|
161
161
|
case 5: return [4, appService.checkoutProfile({
|
|
162
162
|
supported_payment_methods: ['APPLE_PAY'],
|
|
163
163
|
supported_currencies: [order.currency],
|
|
@@ -189,7 +189,7 @@ export var useApplePay = function (_a) {
|
|
|
189
189
|
] })
|
|
190
190
|
})];
|
|
191
191
|
case 6:
|
|
192
|
-
data =
|
|
192
|
+
data = _o.sent();
|
|
193
193
|
if (debug)
|
|
194
194
|
console.log('merchant configuration: ', data);
|
|
195
195
|
setProfile(data);
|
|
@@ -198,11 +198,11 @@ export var useApplePay = function (_a) {
|
|
|
198
198
|
setApplePayRequestConfiguration({
|
|
199
199
|
BASE_URL: appService.getBaseUrl(),
|
|
200
200
|
headers: getAxiosGlobalHeaders(),
|
|
201
|
-
merchant: data.merchant
|
|
201
|
+
merchant: __assign(__assign({}, data.merchant), { id: merchant.id || ((_m = data.merchant) === null || _m === void 0 ? void 0 : _m.id) })
|
|
202
202
|
});
|
|
203
203
|
return [3, 9];
|
|
204
204
|
case 7:
|
|
205
|
-
err_1 =
|
|
205
|
+
err_1 = _o.sent();
|
|
206
206
|
onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
|
|
207
207
|
console.log('error in initialize', err_1);
|
|
208
208
|
return [3, 9];
|
|
@@ -255,7 +255,7 @@ export var useApplePay = function (_a) {
|
|
|
255
255
|
if (debug) {
|
|
256
256
|
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(window.location.origin));
|
|
257
257
|
}
|
|
258
|
-
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL, window.location.origin)];
|
|
258
|
+
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id || profileData.merchant.id }), event.validationURL, window.location.origin)];
|
|
259
259
|
case 2:
|
|
260
260
|
merchantSession = _a.sent();
|
|
261
261
|
if (debug)
|