@tap-payments/apple-pay-button 0.0.37-development → 0.0.37-test
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/ApplePayButtonProps.d.ts +129 -0
- package/build/@types/ApplePayButtonProps.js +1 -0
- package/build/@types/charge.d.ts +57 -0
- package/build/@types/charge.js +1 -0
- package/build/@types/checkoutProfile.d.ts +195 -0
- package/build/@types/checkoutProfile.js +1 -0
- package/build/@types/enums.d.ts +65 -0
- package/build/@types/enums.js +76 -0
- package/build/@types/index.d.ts +6 -122
- package/build/@types/index.js +6 -1
- package/build/@types/tapLocalisation.d.ts +193 -0
- package/build/@types/tapLocalisation.js +1 -0
- package/build/@types/tapTheme.d.ts +842 -0
- package/build/@types/tapTheme.js +1 -0
- package/build/api.d.ts +29 -0
- package/build/{api/app.service.js → api.js} +87 -95
- package/build/constants/index.d.ts +2 -58
- package/build/constants/index.js +2 -58
- package/build/features/ApplePayButton/ApplePayButton.d.ts +3 -5
- package/build/features/ApplePayButton/ApplePayButton.js +8 -14
- package/build/features/ApplePayButton/index.d.ts +2 -2
- package/build/hooks/index.d.ts +0 -2
- package/build/hooks/index.js +0 -2
- package/build/hooks/useApplePay.d.ts +89 -5
- package/build/hooks/useApplePay.js +289 -117
- package/build/hooks/useMerchantApplePay.d.ts +20 -0
- package/build/hooks/useMerchantApplePay.js +176 -0
- package/build/index.d.ts +4 -6
- package/build/index.js +3 -9
- package/build/utils/config.d.ts +10 -9
- package/build/utils/config.js +40 -47
- package/build/utils/defaultValues.d.ts +2 -30
- package/build/utils/defaultValues.js +10 -31
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.js +3 -0
- package/build/utils/theme.d.ts +12 -0
- package/build/utils/theme.js +61 -0
- package/package.json +16 -11
- package/build/api/app.service.d.ts +0 -23
- package/build/api/base.d.ts +0 -9
- package/build/api/base.js +0 -45
- package/build/api/httpClient.d.ts +0 -8
- package/build/api/httpClient.js +0 -33
- package/build/features/ApplePayButton/ApplePayButton.css +0 -21
- package/build/hooks/useApplePayFromMerchantSide.d.ts +0 -11
- package/build/hooks/useApplePayFromMerchantSide.js +0 -177
- package/build/hooks/useScript.d.ts +0 -1
- package/build/hooks/useScript.js +0 -39
|
@@ -24,7 +24,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
24
24
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
25
|
function step(op) {
|
|
26
26
|
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (_) try {
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
28
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
29
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
30
|
switch (op[0]) {
|
|
@@ -45,92 +45,162 @@ 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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
+
};
|
|
59
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
60
|
+
import { ApplePayVersion, MW_BASE_URL } from '../constants';
|
|
61
|
+
import { prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
|
|
62
|
+
import { Scope } from '../@types';
|
|
63
|
+
import { useMerchantApplePay } from './useMerchantApplePay';
|
|
64
|
+
import { getApplePayPaymentMethod, getDefaultThemeMode } from '../utils';
|
|
65
|
+
import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
|
|
66
|
+
import { ChargeCode, mappingInterface } from '@tap-payments/acceptance-sdk';
|
|
54
67
|
export var useApplePay = function (_a) {
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
var _b, _c;
|
|
69
|
+
var buttonProps = _a.buttonProps;
|
|
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];
|
|
79
|
+
var mappedProps = __assign(__assign({}, buttonProps), { interface: mappingInterface(buttonProps.interface) });
|
|
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
|
+
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
82
|
+
useMerchantApplePay({
|
|
83
|
+
isIframeIntegration: isIframeIntegration,
|
|
84
|
+
onError: onError,
|
|
85
|
+
onSuccess: onSuccess,
|
|
86
|
+
scope: scope,
|
|
87
|
+
profileData: profileData,
|
|
88
|
+
merchant: merchant,
|
|
89
|
+
order: order,
|
|
90
|
+
customer: customer,
|
|
91
|
+
transaction: transaction,
|
|
92
|
+
operator: operator,
|
|
93
|
+
post: post,
|
|
94
|
+
redirect: redirect,
|
|
95
|
+
setError: setError,
|
|
96
|
+
setSuccess: setSuccess,
|
|
97
|
+
setLoading: setLoading
|
|
98
|
+
});
|
|
99
|
+
var theme = getDefaultThemeMode((_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.theme);
|
|
100
|
+
var applePayPaymentMethodOptions = useMemo(function () {
|
|
101
|
+
if (!profileData)
|
|
102
|
+
return null;
|
|
103
|
+
return getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
104
|
+
}, [profileData]);
|
|
105
|
+
var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
106
|
+
var headers_1, rest, applePayPreparedData_1, data, applePayPreparedData, err_1;
|
|
107
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
108
|
+
return __generator(this, function (_o) {
|
|
109
|
+
switch (_o.label) {
|
|
64
110
|
case 0:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
appService.setBaseUrl();
|
|
68
|
-
_h.label = 1;
|
|
111
|
+
setInitialLoading(true);
|
|
112
|
+
_o.label = 1;
|
|
69
113
|
case 1:
|
|
70
|
-
|
|
114
|
+
_o.trys.push([1, 7, , 8]);
|
|
115
|
+
if (!shallRenderApplePay()) {
|
|
116
|
+
throw new Error('The device/customer is not eligible to use ApplePay');
|
|
117
|
+
}
|
|
71
118
|
if (metaData) {
|
|
72
|
-
|
|
73
|
-
setAxiosGlobalHeaders(__assign({},
|
|
74
|
-
setProfile(
|
|
119
|
+
headers_1 = metaData.headers, rest = __rest(metaData, ["headers"]);
|
|
120
|
+
setAxiosGlobalHeaders(__assign({}, headers_1));
|
|
121
|
+
setProfile(rest);
|
|
122
|
+
applePayPreparedData_1 = prepareApplePayRequest(__assign(__assign({}, rest), { order: order, acceptance: acceptance, customer: customer }));
|
|
123
|
+
setApplePayRequestData(applePayPreparedData_1.applePaySessionRequest);
|
|
124
|
+
setInitialLoading(false);
|
|
75
125
|
return [2];
|
|
76
126
|
}
|
|
77
|
-
return [
|
|
78
|
-
|
|
79
|
-
domain: merchant.domain,
|
|
80
|
-
pk: publicKey
|
|
81
|
-
})];
|
|
127
|
+
if (!headers) return [3, 3];
|
|
128
|
+
return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { authorization: operator.publicKey }))];
|
|
82
129
|
case 2:
|
|
83
|
-
|
|
84
|
-
return [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
130
|
+
_o.sent();
|
|
131
|
+
return [3, 5];
|
|
132
|
+
case 3: return [4, appService.setBrowserHeaders({
|
|
133
|
+
locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
|
|
134
|
+
domain: window.location.origin,
|
|
135
|
+
pk: operator.publicKey
|
|
136
|
+
})];
|
|
137
|
+
case 4:
|
|
138
|
+
_o.sent();
|
|
139
|
+
_o.label = 5;
|
|
140
|
+
case 5: return [4, appService.checkoutProfile({
|
|
141
|
+
supported_payment_methods: ['APPLE_PAY'],
|
|
142
|
+
supported_currencies: [order.currency],
|
|
143
|
+
transaction_mode: scope === Scope.AUTHORIZE ? 'AUTHORIZE_CAPTURE' : 'PURCHASE',
|
|
144
|
+
currency: order.currency,
|
|
145
|
+
merchant_id: merchant === null || merchant === void 0 ? void 0 : merchant.id,
|
|
146
|
+
total_amount: Number(order.amount),
|
|
147
|
+
order: __assign(__assign({ id: order === null || order === void 0 ? void 0 : order.id, amount: Number(order.amount), currency: order.currency, description: order === null || order === void 0 ? void 0 : order.description, metadata: order === null || order === void 0 ? void 0 : order.metadata }, (customer && {
|
|
148
|
+
customer: {
|
|
149
|
+
id: customer === null || customer === void 0 ? void 0 : customer.id,
|
|
150
|
+
email: (_a = customer.contact) === null || _a === void 0 ? void 0 : _a.email,
|
|
151
|
+
first_name: ((_b = customer.name) === null || _b === void 0 ? void 0 : _b.length) ? customer.name[0].first : '',
|
|
152
|
+
last_name: ((_c = customer.name) === null || _c === void 0 ? void 0 : _c.length) ? customer.name[0].last : '',
|
|
153
|
+
phone: {
|
|
154
|
+
country_code: (_f = (_e = (_d = customer.contact) === null || _d === void 0 ? void 0 : _d.phone) === null || _e === void 0 ? void 0 : _e.countryCode) !== null && _f !== void 0 ? _f : '',
|
|
155
|
+
number: (_j = (_h = (_g = customer.contact) === null || _g === void 0 ? void 0 : _g.phone) === null || _h === void 0 ? void 0 : _h.number) !== null && _j !== void 0 ? _j : ''
|
|
98
156
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
157
|
+
}
|
|
158
|
+
})), { merchant: {
|
|
159
|
+
id: merchant === null || merchant === void 0 ? void 0 : merchant.id
|
|
160
|
+
}, items: [
|
|
161
|
+
{
|
|
162
|
+
amount: Number(order.amount),
|
|
163
|
+
currency: order.currency,
|
|
164
|
+
name: "apple pay sdk button order item",
|
|
165
|
+
quantity: 1,
|
|
166
|
+
description: "apple pay sdk button order item description"
|
|
167
|
+
}
|
|
168
|
+
] })
|
|
169
|
+
})];
|
|
170
|
+
case 6:
|
|
171
|
+
data = _o.sent();
|
|
113
172
|
if (debug)
|
|
114
173
|
console.log('merchant configuration: ', data);
|
|
115
174
|
setProfile(data);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
175
|
+
applePayPreparedData = prepareApplePayRequest(__assign(__assign({}, data), { order: order, acceptance: acceptance, customer: customer }));
|
|
176
|
+
setApplePayRequestData(applePayPreparedData.applePaySessionRequest);
|
|
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);
|
|
178
|
+
setApplePayRequestConfiguration({
|
|
179
|
+
BASE_URL: MW_BASE_URL,
|
|
180
|
+
headers: getAxiosGlobalHeaders(),
|
|
181
|
+
merchant: __assign(__assign({}, data.merchant), { id: merchant.id || ((_m = data.merchant) === null || _m === void 0 ? void 0 : _m.id) })
|
|
182
|
+
});
|
|
183
|
+
setInitialLoading(false);
|
|
184
|
+
onReady === null || onReady === void 0 ? void 0 : onReady();
|
|
185
|
+
return [3, 8];
|
|
186
|
+
case 7:
|
|
187
|
+
err_1 = _o.sent();
|
|
188
|
+
onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
|
|
189
|
+
console.log('error in initialize', err_1);
|
|
190
|
+
return [3, 8];
|
|
191
|
+
case 8: return [2];
|
|
126
192
|
}
|
|
127
193
|
});
|
|
128
|
-
}); }
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
194
|
+
}); };
|
|
195
|
+
var isTapIdentifier = function (id) { return (id.toLowerCase().includes('knet') ? 'knet' : 'tap'); };
|
|
196
|
+
var identifier = useMemo(function () {
|
|
197
|
+
var _a, _b, _c;
|
|
198
|
+
if (!((_a = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _a === void 0 ? void 0 : _a.payment_methods))
|
|
199
|
+
return '';
|
|
200
|
+
return (_c = (_b = getApplePayPaymentMethod(profileData.payment_options.payment_methods)) === null || _b === void 0 ? void 0 : _b.identifier) !== null && _c !== void 0 ? _c : '';
|
|
201
|
+
}, [(_c = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _c === void 0 ? void 0 : _c.payment_methods]);
|
|
132
202
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
-
var ApplePaySession,
|
|
203
|
+
var ApplePaySession, session_1;
|
|
134
204
|
var _a;
|
|
135
205
|
return __generator(this, function (_b) {
|
|
136
206
|
ApplePaySession = window.ApplePaySession;
|
|
@@ -141,25 +211,19 @@ export var useApplePay = function (_a) {
|
|
|
141
211
|
}
|
|
142
212
|
if (!profileData) {
|
|
143
213
|
setDisabled(true);
|
|
144
|
-
console.error('The profile data is not available, please check
|
|
214
|
+
console.error('The profile data is not available, please check the network and try again');
|
|
215
|
+
return [2];
|
|
216
|
+
}
|
|
217
|
+
if (!applePayRequestData) {
|
|
218
|
+
setDisabled(true);
|
|
219
|
+
console.error("We can't find the apple pay request data, please check the network and try again");
|
|
145
220
|
return [2];
|
|
146
221
|
}
|
|
147
222
|
try {
|
|
148
|
-
paymentMethod = getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
149
|
-
currency = validateCurrency(transaction.currency, paymentMethod.supported_currencies);
|
|
150
|
-
cardBrands = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance.supportedBrands);
|
|
151
|
-
request = getApplePayRequest({
|
|
152
|
-
countryCode: profileData.merchant.country_code,
|
|
153
|
-
transaction: __assign(__assign({}, transaction), { currency: currency }),
|
|
154
|
-
customer: customer,
|
|
155
|
-
supportedNetworks: cardBrands,
|
|
156
|
-
merchantCapabilities: getMerchantCapaplities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedCards),
|
|
157
|
-
name: profileData.merchant.name
|
|
158
|
-
});
|
|
159
223
|
if (debug) {
|
|
160
|
-
console.info("Creating ApplePaySession with version: ".concat(ApplePayVersion, " and request: ").concat(JSON.stringify(
|
|
224
|
+
console.info("Creating ApplePaySession with version: ".concat(ApplePayVersion, " and request: ").concat(JSON.stringify(applePayRequestData)));
|
|
161
225
|
}
|
|
162
|
-
session_1 = new ApplePaySession(ApplePayVersion,
|
|
226
|
+
session_1 = new ApplePaySession(ApplePayVersion, applePayRequestData);
|
|
163
227
|
session_1.onvalidatemerchant = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
164
228
|
var merchantSession, error_1;
|
|
165
229
|
return __generator(this, function (_a) {
|
|
@@ -169,14 +233,14 @@ export var useApplePay = function (_a) {
|
|
|
169
233
|
console.info('Creating merchant session and validating merchant session');
|
|
170
234
|
console.info('onvalidatemerchant event', event);
|
|
171
235
|
}
|
|
172
|
-
|
|
236
|
+
setDisabled(true);
|
|
173
237
|
_a.label = 1;
|
|
174
238
|
case 1:
|
|
175
239
|
_a.trys.push([1, 3, , 4]);
|
|
176
240
|
if (debug) {
|
|
177
|
-
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(
|
|
241
|
+
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(window.location.hostname));
|
|
178
242
|
}
|
|
179
|
-
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL, merchant.
|
|
243
|
+
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, identifier)];
|
|
180
244
|
case 2:
|
|
181
245
|
merchantSession = _a.sent();
|
|
182
246
|
if (debug)
|
|
@@ -191,57 +255,124 @@ export var useApplePay = function (_a) {
|
|
|
191
255
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
192
256
|
throw error_1;
|
|
193
257
|
case 4:
|
|
194
|
-
|
|
258
|
+
setDisabled(false);
|
|
195
259
|
return [2];
|
|
196
260
|
}
|
|
197
261
|
});
|
|
198
262
|
}); };
|
|
199
263
|
session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
200
|
-
var _a, data, error_2;
|
|
201
|
-
|
|
202
|
-
|
|
264
|
+
var _a, data, tokenId, supportCurrency, transactionRequest, transactionResponse, _b, successState, error_2;
|
|
265
|
+
var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
266
|
+
return __generator(this, function (_t) {
|
|
267
|
+
switch (_t.label) {
|
|
203
268
|
case 0:
|
|
204
|
-
setLoading(true);
|
|
205
269
|
if (debug)
|
|
206
270
|
console.info('onpaymentauthorized event', event);
|
|
207
|
-
|
|
271
|
+
_t.label = 1;
|
|
208
272
|
case 1:
|
|
209
|
-
|
|
273
|
+
_t.trys.push([1, 13, 14, 15]);
|
|
210
274
|
_a = scope;
|
|
211
275
|
switch (_a) {
|
|
212
|
-
case
|
|
213
|
-
case
|
|
276
|
+
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
277
|
+
case Scope.TAP_TOKEN: return [3, 3];
|
|
278
|
+
case Scope.AUTHORIZE: return [3, 5];
|
|
279
|
+
case Scope.CHARGE: return [3, 5];
|
|
214
280
|
}
|
|
215
|
-
return [3,
|
|
216
|
-
case 2:
|
|
281
|
+
return [3, 11];
|
|
282
|
+
case 2:
|
|
283
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token);
|
|
284
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
285
|
+
return [3, 12];
|
|
217
286
|
case 3:
|
|
218
|
-
|
|
287
|
+
setLoading(true);
|
|
219
288
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
220
|
-
return [
|
|
221
|
-
case 4:
|
|
289
|
+
return [4, appService.tapTokenization(__assign(__assign(__assign({}, event.payment.token.paymentData), event.payment.token), { paymentData: undefined }))];
|
|
290
|
+
case 4:
|
|
291
|
+
data = _t.sent();
|
|
292
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
293
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
294
|
+
return [3, 12];
|
|
222
295
|
case 5:
|
|
223
|
-
|
|
224
|
-
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data))];
|
|
225
|
-
case 6:
|
|
226
|
-
_b.sent();
|
|
296
|
+
setLoading(true);
|
|
227
297
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
228
|
-
return [
|
|
298
|
+
return [4, appService.tapTokenization(__assign(__assign(__assign({}, event.payment.token.paymentData), event.payment.token), { paymentData: undefined }))];
|
|
299
|
+
case 6:
|
|
300
|
+
tokenId = (_t.sent()).id;
|
|
301
|
+
supportCurrency = ((_d = (_c = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _c === void 0 ? void 0 : _c.supported_currencies) !== null && _d !== void 0 ? _d : [])[0];
|
|
302
|
+
transactionRequest = {
|
|
303
|
+
auto: (_e = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _e === void 0 ? void 0 : _e.auto,
|
|
304
|
+
amount: order.amount,
|
|
305
|
+
currency: order.currency,
|
|
306
|
+
selected_amount: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.amount,
|
|
307
|
+
selected_currency: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.currency,
|
|
308
|
+
customer: (customer === null || customer === void 0 ? void 0 : customer.id)
|
|
309
|
+
? { id: customer === null || customer === void 0 ? void 0 : customer.id }
|
|
310
|
+
: {
|
|
311
|
+
email: (_f = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _f === void 0 ? void 0 : _f.email,
|
|
312
|
+
first_name: ((_g = customer === null || customer === void 0 ? void 0 : customer.name) === null || _g === void 0 ? void 0 : _g.length) ? customer.name[0].first : '',
|
|
313
|
+
last_name: ((_h = customer === null || customer === void 0 ? void 0 : customer.name) === null || _h === void 0 ? void 0 : _h.length) ? customer.name[0].last : '',
|
|
314
|
+
phone: {
|
|
315
|
+
country_code: (_l = (_k = (_j = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _j === void 0 ? void 0 : _j.phone) === null || _k === void 0 ? void 0 : _k.countryCode) !== null && _l !== void 0 ? _l : '',
|
|
316
|
+
number: (_p = (_o = (_m = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _m === void 0 ? void 0 : _m.phone) === null || _o === void 0 ? void 0 : _o.number) !== null && _p !== void 0 ? _p : ''
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
fee: 0,
|
|
320
|
+
merchant: {
|
|
321
|
+
id: (_r = (_q = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _q === void 0 ? void 0 : _q.id) !== null && _r !== void 0 ? _r : ''
|
|
322
|
+
},
|
|
323
|
+
order: (_s = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _s === void 0 ? void 0 : _s.order,
|
|
324
|
+
product: 'Apple-Pay-Button',
|
|
325
|
+
save_card: false,
|
|
326
|
+
source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
|
|
327
|
+
threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.authentication,
|
|
328
|
+
hashstring: operator.hashstring,
|
|
329
|
+
redirect: redirect,
|
|
330
|
+
metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
|
|
331
|
+
post: post,
|
|
332
|
+
payment_agreement: transaction === null || transaction === void 0 ? void 0 : transaction.paymentAgreement,
|
|
333
|
+
destinations: transaction === null || transaction === void 0 ? void 0 : transaction.destinations,
|
|
334
|
+
reference: {
|
|
335
|
+
order: order === null || order === void 0 ? void 0 : order.reference,
|
|
336
|
+
transaction: transaction === null || transaction === void 0 ? void 0 : transaction.reference
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
if (!(scope === Scope.AUTHORIZE)) return [3, 8];
|
|
340
|
+
return [4, appService.createAuthorize(transactionRequest)];
|
|
229
341
|
case 7:
|
|
342
|
+
_b = _t.sent();
|
|
343
|
+
return [3, 10];
|
|
344
|
+
case 8: return [4, appService.createCharge(transactionRequest)];
|
|
345
|
+
case 9:
|
|
346
|
+
_b = _t.sent();
|
|
347
|
+
_t.label = 10;
|
|
348
|
+
case 10:
|
|
349
|
+
transactionResponse = _b;
|
|
350
|
+
successState = scope === Scope.AUTHORIZE ? ChargeCode.AUTHORIZED : ChargeCode.SUCCESS;
|
|
351
|
+
if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
|
|
352
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
setError === null || setError === void 0 ? void 0 : setError(true);
|
|
356
|
+
}
|
|
357
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
|
|
358
|
+
return [3, 12];
|
|
359
|
+
case 11:
|
|
230
360
|
console.error('We only support AppleToken and TapToken for now');
|
|
231
361
|
console.info('Completing payment with status: STATUS_FAILURE');
|
|
232
362
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
233
|
-
|
|
234
|
-
case
|
|
235
|
-
case
|
|
236
|
-
error_2 =
|
|
363
|
+
_t.label = 12;
|
|
364
|
+
case 12: return [3, 15];
|
|
365
|
+
case 13:
|
|
366
|
+
error_2 = _t.sent();
|
|
237
367
|
if (debug)
|
|
238
368
|
console.error('error in onpaymentauthorized', error_2);
|
|
369
|
+
setError(true);
|
|
239
370
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
240
371
|
throw error_2;
|
|
241
|
-
case
|
|
372
|
+
case 14:
|
|
242
373
|
setLoading(false);
|
|
243
374
|
return [7];
|
|
244
|
-
case
|
|
375
|
+
case 15: return [2];
|
|
245
376
|
}
|
|
246
377
|
});
|
|
247
378
|
}); };
|
|
@@ -264,7 +395,7 @@ export var useApplePay = function (_a) {
|
|
|
264
395
|
return [2];
|
|
265
396
|
}
|
|
266
397
|
if (e.message) {
|
|
267
|
-
onError([{
|
|
398
|
+
onError([{ message: e.message, code: '400' }]);
|
|
268
399
|
return [2];
|
|
269
400
|
}
|
|
270
401
|
onError(e);
|
|
@@ -272,5 +403,46 @@ export var useApplePay = function (_a) {
|
|
|
272
403
|
return [2];
|
|
273
404
|
});
|
|
274
405
|
}); };
|
|
275
|
-
|
|
406
|
+
var handleClick = useCallback(function () {
|
|
407
|
+
var _a, _b;
|
|
408
|
+
if (isIframeIntegration) {
|
|
409
|
+
(_a = buttonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(buttonProps, __assign(__assign({}, applePayRequestConfiguration), { applePayRequestData: applePayRequestData }));
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
onApplePayButtonClicked();
|
|
413
|
+
(_b = buttonProps.onClick) === null || _b === void 0 ? void 0 : _b.call(buttonProps);
|
|
414
|
+
}, [applePayRequestConfiguration, applePayRequestData, buttonProps, isIframeIntegration, onApplePayButtonClicked]);
|
|
415
|
+
useEffect(function () {
|
|
416
|
+
initialize(metaData);
|
|
417
|
+
}, []);
|
|
418
|
+
useEffect(function () {
|
|
419
|
+
setIsRounded(error || success || loading);
|
|
420
|
+
}, [error, success, loading]);
|
|
421
|
+
useEffect(function () {
|
|
422
|
+
if (!error)
|
|
423
|
+
return;
|
|
424
|
+
var timer = setTimeout(function () {
|
|
425
|
+
setError(false);
|
|
426
|
+
setLoading(false);
|
|
427
|
+
setIsRounded(false);
|
|
428
|
+
}, 2000);
|
|
429
|
+
return function () { return clearTimeout(timer); };
|
|
430
|
+
}, [error, loading]);
|
|
431
|
+
return {
|
|
432
|
+
onClick: handleClick,
|
|
433
|
+
loading: loading,
|
|
434
|
+
isIframeIntegration: isIframeIntegration,
|
|
435
|
+
onApplePayButtonClicked: onApplePayButtonClicked,
|
|
436
|
+
disabled: !profileData || disabled || !applePayRequestData,
|
|
437
|
+
applePayRequestData: applePayRequestData,
|
|
438
|
+
applePayRequestConfiguration: applePayRequestConfiguration,
|
|
439
|
+
mappedProps: mappedProps,
|
|
440
|
+
theme: theme,
|
|
441
|
+
initialLoading: initialLoading,
|
|
442
|
+
isRounded: isRounded,
|
|
443
|
+
success: success,
|
|
444
|
+
error: error,
|
|
445
|
+
applePayPaymentMethodOptions: applePayPaymentMethodOptions,
|
|
446
|
+
profileData: profileData
|
|
447
|
+
};
|
|
276
448
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MetaData, ApplePayButtonProps, Scope } from '../@types';
|
|
2
|
+
interface ApplePayRequestData {
|
|
3
|
+
isIframeIntegration: boolean;
|
|
4
|
+
onError?: (error: any) => void;
|
|
5
|
+
onSuccess?: (data: Record<string, any>) => void;
|
|
6
|
+
setLoading?: (loading: boolean) => void;
|
|
7
|
+
setSuccess?: (success: boolean) => void;
|
|
8
|
+
setError?: (error: boolean) => void;
|
|
9
|
+
scope: typeof Scope[keyof typeof Scope];
|
|
10
|
+
profileData?: Pick<MetaData, 'merchant' | 'payment_options'>;
|
|
11
|
+
merchant: Pick<MetaData['merchant'], 'id'>;
|
|
12
|
+
order: ApplePayButtonProps['order'];
|
|
13
|
+
customer: ApplePayButtonProps['customer'];
|
|
14
|
+
transaction: ApplePayButtonProps['transaction'];
|
|
15
|
+
operator: ApplePayButtonProps['operator'];
|
|
16
|
+
redirect?: ApplePayButtonProps['redirect'];
|
|
17
|
+
post?: ApplePayButtonProps['post'];
|
|
18
|
+
}
|
|
19
|
+
export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
|
|
20
|
+
export {};
|