@tap-payments/apple-pay-button 1.2.6 → 1.2.8
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.
|
@@ -34,10 +34,8 @@ var ApplePay = React.memo(function (props) {
|
|
|
34
34
|
}, []);
|
|
35
35
|
React.useEffect(function () {
|
|
36
36
|
var lisnterCallback = function (e) {
|
|
37
|
-
var _a;
|
|
38
37
|
e.preventDefault();
|
|
39
38
|
onApplePayButtonClicked();
|
|
40
|
-
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
41
39
|
};
|
|
42
40
|
var applepayButton = document.getElementById('tap-apple-pay-button');
|
|
43
41
|
applepayButton === null || applepayButton === void 0 ? void 0 : applepayButton.addEventListener('click', lisnterCallback);
|
|
@@ -6,5 +6,5 @@ interface UseApplePayReturnProps {
|
|
|
6
6
|
onApplePayButtonClicked: () => Promise<void>;
|
|
7
7
|
abortApplePaySession: () => void;
|
|
8
8
|
}
|
|
9
|
-
export declare const useApplePay: ({ publicKey, merchant, transaction, interface: interfaceObj, customer, onCancel, onError, onSuccess, integration, scope, acceptance, features, metaData, debug, environment, platform, onReady, onMerchantValidation, onShippingMethodSelected, onShippingContactSelected, onPaymentMethodSelected, onCouponChanged }: UseApplePayProps) => UseApplePayReturnProps;
|
|
9
|
+
export declare const useApplePay: ({ publicKey, merchant, transaction, interface: interfaceObj, customer, onCancel, onError, onSuccess, onClick, integration, scope, acceptance, features, metaData, debug, environment, platform, onReady, onMerchantValidation, onShippingMethodSelected, onShippingContactSelected, onPaymentMethodSelected, onCouponChanged }: UseApplePayProps) => UseApplePayReturnProps;
|
|
10
10
|
export {};
|
|
@@ -65,7 +65,7 @@ import { shapeApplePayError } from '../utils';
|
|
|
65
65
|
import { getMerchantCapaplities } from '../utils/defaultValues';
|
|
66
66
|
import { useApplePayScript } from './useApplePayScript';
|
|
67
67
|
export var useApplePay = function (_a) {
|
|
68
|
-
var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, interfaceObj = _a.interface, customer = _a.customer, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, integration = _a.integration, scope = _a.scope, acceptance = _a.acceptance, features = _a.features, metaData = _a.metaData, debug = _a.debug, environment = _a.environment, platform = _a.platform, onReady = _a.onReady, onMerchantValidation = _a.onMerchantValidation, onShippingMethodSelected = _a.onShippingMethodSelected, onShippingContactSelected = _a.onShippingContactSelected, onPaymentMethodSelected = _a.onPaymentMethodSelected, onCouponChanged = _a.onCouponChanged;
|
|
68
|
+
var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, interfaceObj = _a.interface, customer = _a.customer, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, onClick = _a.onClick, integration = _a.integration, scope = _a.scope, acceptance = _a.acceptance, features = _a.features, metaData = _a.metaData, debug = _a.debug, environment = _a.environment, platform = _a.platform, onReady = _a.onReady, onMerchantValidation = _a.onMerchantValidation, onShippingMethodSelected = _a.onShippingMethodSelected, onShippingContactSelected = _a.onShippingContactSelected, onPaymentMethodSelected = _a.onPaymentMethodSelected, onCouponChanged = _a.onCouponChanged;
|
|
69
69
|
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
70
70
|
var _c = useState(null), profileData = _c[0], setProfile = _c[1];
|
|
71
71
|
var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
|
|
@@ -155,7 +155,7 @@ export var useApplePay = function (_a) {
|
|
|
155
155
|
initialize(metaData);
|
|
156
156
|
}, [isScriptLoaded, initialize, metaData]);
|
|
157
157
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
158
|
-
var ApplePaySession,
|
|
158
|
+
var ApplePaySession, paymentMethod, currency, cardBrands, request, session_1;
|
|
159
159
|
return __generator(this, function (_a) {
|
|
160
160
|
ApplePaySession = window.ApplePaySession;
|
|
161
161
|
if (!ApplePaySession) {
|
|
@@ -169,9 +169,16 @@ export var useApplePay = function (_a) {
|
|
|
169
169
|
return [2];
|
|
170
170
|
}
|
|
171
171
|
try {
|
|
172
|
-
|
|
173
|
-
currency = validateCurrency(transaction.currency,
|
|
174
|
-
cardBrands = validateSupportedNetworks(
|
|
172
|
+
paymentMethod = getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
173
|
+
currency = validateCurrency(transaction.currency, paymentMethod.supported_currencies);
|
|
174
|
+
cardBrands = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedBrands);
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
onError === null || onError === void 0 ? void 0 : onError([{ description: e.message, code: '000' }]);
|
|
178
|
+
return [2];
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
175
182
|
request = getApplePayRequest({
|
|
176
183
|
features: features,
|
|
177
184
|
countryCode: profileData.merchant.country_code,
|
|
@@ -204,7 +211,7 @@ export var useApplePay = function (_a) {
|
|
|
204
211
|
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(merchant.domain));
|
|
205
212
|
}
|
|
206
213
|
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL, merchant.domain, integration === Integration.Webview
|
|
207
|
-
?
|
|
214
|
+
? paymentMethod.identifier || FALLBACK_MERCHANT_IDENTIFIER
|
|
208
215
|
: merchant.identifier || merchant.id)];
|
|
209
216
|
case 2:
|
|
210
217
|
merchantSession = _a.sent();
|
|
@@ -230,7 +237,7 @@ export var useApplePay = function (_a) {
|
|
|
230
237
|
});
|
|
231
238
|
}); };
|
|
232
239
|
session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
233
|
-
var _a, token, rest, newEvent, _b, _c, paymentData,
|
|
240
|
+
var _a, token, rest, newEvent, _b, _c, paymentData, paymentMethod_1, transactionIdentifier, data, error_2;
|
|
234
241
|
var _d, _e;
|
|
235
242
|
return __generator(this, function (_f) {
|
|
236
243
|
switch (_f.label) {
|
|
@@ -255,8 +262,8 @@ export var useApplePay = function (_a) {
|
|
|
255
262
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
256
263
|
return [3, 8];
|
|
257
264
|
case 4:
|
|
258
|
-
_c = (_e = event.payment.token) !== null && _e !== void 0 ? _e : {}, paymentData = _c.paymentData,
|
|
259
|
-
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod:
|
|
265
|
+
_c = (_e = event.payment.token) !== null && _e !== void 0 ? _e : {}, paymentData = _c.paymentData, paymentMethod_1 = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
|
|
266
|
+
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod_1, transactionIdentifier: transactionIdentifier }))];
|
|
260
267
|
case 5:
|
|
261
268
|
data = _f.sent();
|
|
262
269
|
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, newEvent))];
|