@tap-payments/apple-pay-button 1.2.5 → 1.2.7
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 +16 -11
- package/package.json +1 -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,15 @@ 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: '400' }]);
|
|
178
|
+
return [2];
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
175
181
|
request = getApplePayRequest({
|
|
176
182
|
features: features,
|
|
177
183
|
countryCode: profileData.merchant.country_code,
|
|
@@ -204,7 +210,7 @@ export var useApplePay = function (_a) {
|
|
|
204
210
|
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(merchant.domain));
|
|
205
211
|
}
|
|
206
212
|
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL, merchant.domain, integration === Integration.Webview
|
|
207
|
-
?
|
|
213
|
+
? paymentMethod.identifier || FALLBACK_MERCHANT_IDENTIFIER
|
|
208
214
|
: merchant.identifier || merchant.id)];
|
|
209
215
|
case 2:
|
|
210
216
|
merchantSession = _a.sent();
|
|
@@ -230,7 +236,7 @@ export var useApplePay = function (_a) {
|
|
|
230
236
|
});
|
|
231
237
|
}); };
|
|
232
238
|
session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
233
|
-
var _a, token, rest, newEvent, _b, _c, paymentData,
|
|
239
|
+
var _a, token, rest, newEvent, _b, _c, paymentData, paymentMethod_1, transactionIdentifier, data, error_2;
|
|
234
240
|
var _d, _e;
|
|
235
241
|
return __generator(this, function (_f) {
|
|
236
242
|
switch (_f.label) {
|
|
@@ -255,8 +261,8 @@ export var useApplePay = function (_a) {
|
|
|
255
261
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
256
262
|
return [3, 8];
|
|
257
263
|
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:
|
|
264
|
+
_c = (_e = event.payment.token) !== null && _e !== void 0 ? _e : {}, paymentData = _c.paymentData, paymentMethod_1 = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
|
|
265
|
+
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod_1, transactionIdentifier: transactionIdentifier }))];
|
|
260
266
|
case 5:
|
|
261
267
|
data = _f.sent();
|
|
262
268
|
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data, newEvent))];
|
|
@@ -266,8 +272,6 @@ export var useApplePay = function (_a) {
|
|
|
266
272
|
return [3, 8];
|
|
267
273
|
case 7:
|
|
268
274
|
console.error('We only support AppleToken and TapToken for now');
|
|
269
|
-
console.info('Completing payment with status: STATUS_FAILURE');
|
|
270
|
-
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
271
275
|
throw new Error('We only support AppleToken and TapToken for now');
|
|
272
276
|
case 8: return [3, 11];
|
|
273
277
|
case 9:
|
|
@@ -275,7 +279,8 @@ export var useApplePay = function (_a) {
|
|
|
275
279
|
if (debug)
|
|
276
280
|
console.error('error in onpaymentauthorized', error_2);
|
|
277
281
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
278
|
-
|
|
282
|
+
onError && onError(shapeApplePayError(error_2));
|
|
283
|
+
return [3, 11];
|
|
279
284
|
case 10:
|
|
280
285
|
setLoading(false);
|
|
281
286
|
return [7];
|