@alipay/ams-checkout 0.0.1781004142-dev.12 → 0.0.1781004142-dev.13
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.
|
@@ -31,6 +31,10 @@ export declare class ApplePaySdk {
|
|
|
31
31
|
* @description 支付状态,pending:支付中,normal:正常
|
|
32
32
|
*/
|
|
33
33
|
private paymentStatus;
|
|
34
|
+
/**
|
|
35
|
+
* @description oncancel 原因标记,用于区分用户主动取消 vs 商户通过 onBeforeConfirm 中止
|
|
36
|
+
*/
|
|
37
|
+
private cancelReason;
|
|
34
38
|
private logger;
|
|
35
39
|
private env;
|
|
36
40
|
private shipping?;
|
|
@@ -153,6 +153,10 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
153
153
|
* @description 支付状态,pending:支付中,normal:正常
|
|
154
154
|
*/
|
|
155
155
|
_defineProperty(this, "paymentStatus", void 0);
|
|
156
|
+
/**
|
|
157
|
+
* @description oncancel 原因标记,用于区分用户主动取消 vs 商户通过 onBeforeConfirm 中止
|
|
158
|
+
*/
|
|
159
|
+
_defineProperty(this, "cancelReason", null);
|
|
156
160
|
_defineProperty(this, "logger", void 0);
|
|
157
161
|
_defineProperty(this, "env", void 0);
|
|
158
162
|
_defineProperty(this, "shipping", void 0);
|
|
@@ -208,6 +212,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
208
212
|
try {
|
|
209
213
|
if (!_this.session) return;
|
|
210
214
|
_this.paymentStatus = PAYMENT_STATUS.PENDING;
|
|
215
|
+
_this.session.begin();
|
|
211
216
|
_this.session.onvalidatemerchant = /*#__PURE__*/function () {
|
|
212
217
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(event) {
|
|
213
218
|
var requestParams, res, merchantSession, _this$logger, _this$logger2;
|
|
@@ -277,7 +282,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
277
282
|
}();
|
|
278
283
|
_this.session.onpaymentauthorized = /*#__PURE__*/function () {
|
|
279
284
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(event) {
|
|
280
|
-
var exception, _event$payment, token, billingContact, shippingContact, _this$parseData, obj, _this$parseData$payme, requiredBillingContactFields, requiredShippingContactFields, _this$logger3, _this$logger4, BEFORE_CONFIRM_TIMEOUT_MS, _this$logger6, timeoutPromise, startTime, shouldContinue, _this$logger5, _this$session2, _this$session2$comple, _this$session3, _this$session3$comple, isTimeout, _this$logger7, _this$logger8, res, _this$logger9;
|
|
285
|
+
var exception, _event$payment, token, billingContact, shippingContact, _this$parseData, obj, _this$parseData$payme, requiredBillingContactFields, requiredShippingContactFields, _this$logger3, _this$logger4, BEFORE_CONFIRM_TIMEOUT_MS, _this$logger6, timerId, timeoutPromise, startTime, shouldContinue, _this$logger5, _this$session2, _this$session2$comple, _this$session3, _this$session3$comple, isTimeout, _this$logger7, _this$logger8, res, _this$logger9;
|
|
281
286
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
282
287
|
while (1) switch (_context3.prev = _context3.next) {
|
|
283
288
|
case 0:
|
|
@@ -291,7 +296,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
291
296
|
};
|
|
292
297
|
_event$payment = event === null || event === void 0 ? void 0 : event.payment, token = _event$payment.token, billingContact = _event$payment.billingContact, shippingContact = _event$payment.shippingContact;
|
|
293
298
|
if (!token) {
|
|
294
|
-
_context3.next =
|
|
299
|
+
_context3.next = 48;
|
|
295
300
|
break;
|
|
296
301
|
}
|
|
297
302
|
obj = {
|
|
@@ -315,9 +320,11 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
315
320
|
paymentMethodType: 'APPLEPAY',
|
|
316
321
|
path: 'applePay_chrome_sdk'
|
|
317
322
|
});
|
|
318
|
-
_context3.next =
|
|
323
|
+
_context3.next = 41;
|
|
319
324
|
break;
|
|
320
325
|
case 11:
|
|
326
|
+
// 清空回原始状态
|
|
327
|
+
_this.cancelReason = 'USER_CANCEL';
|
|
321
328
|
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
322
329
|
(_this$logger4 = _this.logger) === null || _this$logger4 === void 0 || _this$logger4.logInfo({
|
|
323
330
|
title: 'sdk_before_confirm_start'
|
|
@@ -325,17 +332,20 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
325
332
|
paymentMethodType: 'APPLEPAY',
|
|
326
333
|
path: 'applePay_chrome_sdk'
|
|
327
334
|
});
|
|
328
|
-
_context3.prev =
|
|
335
|
+
_context3.prev = 14;
|
|
336
|
+
timerId = null;
|
|
329
337
|
timeoutPromise = new Promise(function (_, reject) {
|
|
330
|
-
|
|
338
|
+
timerId = setTimeout(function () {
|
|
331
339
|
return reject(new Error('onBeforeConfirm timed out'));
|
|
332
340
|
}, BEFORE_CONFIRM_TIMEOUT_MS);
|
|
333
341
|
});
|
|
334
342
|
startTime = Date.now();
|
|
335
|
-
_context3.next =
|
|
343
|
+
_context3.next = 20;
|
|
336
344
|
return Promise.race([_this.onBeforeConfirm(), timeoutPromise]);
|
|
337
|
-
case
|
|
345
|
+
case 20:
|
|
338
346
|
shouldContinue = _context3.sent;
|
|
347
|
+
// 正常返回时清除超时定时器,避免 unhandled promise rejection
|
|
348
|
+
if (timerId !== null) clearTimeout(timerId);
|
|
339
349
|
if (Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
|
|
340
350
|
(_this$logger5 = _this.logger) === null || _this$logger5 === void 0 || _this$logger5.logError({
|
|
341
351
|
title: 'sdk_before_confirm_timeout'
|
|
@@ -348,21 +358,22 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
348
358
|
shouldContinue: shouldContinue
|
|
349
359
|
});
|
|
350
360
|
if (shouldContinue) {
|
|
351
|
-
_context3.next =
|
|
361
|
+
_context3.next = 30;
|
|
352
362
|
break;
|
|
353
363
|
}
|
|
364
|
+
_this.cancelReason = 'MERCHANT_ABORT';
|
|
354
365
|
(_this$session2 = _this.session) === null || _this$session2 === void 0 || (_this$session2$comple = _this$session2.completePayment) === null || _this$session2$comple === void 0 || _this$session2$comple.call(_this$session2, window.ApplePaySession.STATUS_FAILURE);
|
|
355
366
|
_this.abortSession();
|
|
356
367
|
reject({
|
|
357
368
|
errorCode: 'MERCHANT_CONFIRM_ABORT'
|
|
358
369
|
});
|
|
359
370
|
return _context3.abrupt("return");
|
|
360
|
-
case
|
|
361
|
-
_context3.next =
|
|
371
|
+
case 30:
|
|
372
|
+
_context3.next = 41;
|
|
362
373
|
break;
|
|
363
|
-
case
|
|
364
|
-
_context3.prev =
|
|
365
|
-
_context3.t0 = _context3["catch"](
|
|
374
|
+
case 32:
|
|
375
|
+
_context3.prev = 32;
|
|
376
|
+
_context3.t0 = _context3["catch"](14);
|
|
366
377
|
isTimeout = _context3.t0 instanceof Error && _context3.t0.message === 'onBeforeConfirm timed out';
|
|
367
378
|
if (isTimeout) {
|
|
368
379
|
(_this$logger7 = _this.logger) === null || _this$logger7 === void 0 || _this$logger7.logError({
|
|
@@ -380,31 +391,32 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
380
391
|
errorMessage: String((_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message) || _context3.t0).slice(0, 200)
|
|
381
392
|
});
|
|
382
393
|
}
|
|
394
|
+
_this.cancelReason = 'MERCHANT_ABORT';
|
|
383
395
|
(_this$session3 = _this.session) === null || _this$session3 === void 0 || (_this$session3$comple = _this$session3.completePayment) === null || _this$session3$comple === void 0 || _this$session3$comple.call(_this$session3, window.ApplePaySession.STATUS_FAILURE);
|
|
384
396
|
_this.abortSession();
|
|
385
397
|
reject({
|
|
386
398
|
errorCode: 'MERCHANT_CONFIRM_ABORT'
|
|
387
399
|
});
|
|
388
400
|
return _context3.abrupt("return");
|
|
389
|
-
case
|
|
390
|
-
_context3.next =
|
|
401
|
+
case 41:
|
|
402
|
+
_context3.next = 43;
|
|
391
403
|
return _this.submitPay(obj);
|
|
392
|
-
case
|
|
404
|
+
case 43:
|
|
393
405
|
res = _context3.sent;
|
|
394
406
|
_this.setPayStatus(res);
|
|
395
407
|
resolve(res);
|
|
396
|
-
_context3.next =
|
|
408
|
+
_context3.next = 50;
|
|
397
409
|
break;
|
|
398
|
-
case
|
|
410
|
+
case 48:
|
|
399
411
|
(_this$logger9 = _this.logger) === null || _this$logger9 === void 0 || _this$logger9.logError({
|
|
400
412
|
title: 'a3753.b103030.c386485.d507486'
|
|
401
413
|
});
|
|
402
414
|
exception();
|
|
403
|
-
case
|
|
415
|
+
case 50:
|
|
404
416
|
case "end":
|
|
405
417
|
return _context3.stop();
|
|
406
418
|
}
|
|
407
|
-
}, _callee3, null, [[
|
|
419
|
+
}, _callee3, null, [[14, 32]]);
|
|
408
420
|
}));
|
|
409
421
|
return function (_x2) {
|
|
410
422
|
return _ref3.apply(this, arguments);
|
|
@@ -422,8 +434,10 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
422
434
|
title: 'a3753.b103030.c386485.d507498'
|
|
423
435
|
});
|
|
424
436
|
}
|
|
437
|
+
// cancelReason === 'MERCHANT_ABORT': onBeforeConfirm 返回 false 或异常,由商户主动中止
|
|
438
|
+
// 其他:用户主动取消付款界面
|
|
425
439
|
reject({
|
|
426
|
-
errorCode: APPLEPAYERRORENUM.APPLE_PAY_CANCEL
|
|
440
|
+
errorCode: _this.cancelReason === 'MERCHANT_ABORT' ? 'MERCHANT_CONFIRM_ABORT' : APPLEPAYERRORENUM.APPLE_PAY_CANCEL
|
|
427
441
|
});
|
|
428
442
|
};
|
|
429
443
|
_this.session.begin();
|