@alipay/ams-checkout 0.0.1781004142-dev.13 → 0.0.1781004142-dev.15

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.
@@ -37,6 +37,7 @@ import { ServiceProvider } from "../../../../foundation/service";
37
37
  import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
38
38
  import { ProductSceneEnum } from "../../../../types";
39
39
  import { ELEMENT_SPM_MAP } from "../../../../util/spm-map";
40
+ import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../../../util/beforeConfirm";
40
41
  import { ElementContainerService } from "../elementContainerService"; // 引入 ElementContainerService
41
42
  import { IContainerStatus } from "../elementContainerService/containerService";
42
43
  import { EventCenter as ElementEventCenter } from "../EventCenter/index";
@@ -374,7 +375,7 @@ var ElementController = /*#__PURE__*/function () {
374
375
  value: function () {
375
376
  var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
376
377
  var _this3 = this;
377
- var startEventId, res, logParams, isApplePay, paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS, timerId, timeoutPromise, shouldContinue, isTimeout, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
378
+ var startEventId, res, logParams, isApplePay, paymentMethodType, startTime, _yield$executeWithTim, shouldContinue, timedOut, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
378
379
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
379
380
  while (1) switch (_context4.prev = _context4.next) {
380
381
  case 0:
@@ -404,42 +405,44 @@ var ElementController = /*#__PURE__*/function () {
404
405
  isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
405
406
  paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
406
407
  if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
407
- _context4.next = 38;
408
+ _context4.next = 34;
408
409
  break;
409
410
  }
410
- BEFORE_CONFIRM_TIMEOUT_MS = 15000;
411
411
  this.serviceMap.Log.logInfo({
412
412
  title: 'sdk_before_confirm_start'
413
413
  }, {
414
414
  paymentMethodType: paymentMethodType,
415
415
  path: 'nonApplePay_sync'
416
416
  });
417
- _context4.prev = 12;
418
- timeoutPromise = new Promise(function (_, reject) {
419
- timerId = setTimeout(function () {
420
- return reject(new Error('onBeforeConfirm timed out'));
421
- }, BEFORE_CONFIRM_TIMEOUT_MS);
417
+ _context4.prev = 11;
418
+ startTime = Date.now();
419
+ _context4.next = 15;
420
+ return executeWithTimeout(function () {
421
+ return submitParams.onBeforeConfirm();
422
422
  });
423
- _context4.prev = 14;
424
- _context4.next = 17;
425
- return Promise.race([submitParams.onBeforeConfirm(), timeoutPromise]);
426
- case 17:
427
- shouldContinue = _context4.sent;
428
- case 18:
429
- _context4.prev = 18;
430
- clearTimeout(timerId);
431
- return _context4.finish(18);
432
- case 21:
433
- if (!(shouldContinue === false)) {
434
- _context4.next = 26;
423
+ case 15:
424
+ _yield$executeWithTim = _context4.sent;
425
+ shouldContinue = _yield$executeWithTim.result;
426
+ timedOut = _yield$executeWithTim.timedOut;
427
+ if (!(timedOut || !shouldContinue || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS)) {
428
+ _context4.next = 23;
435
429
  break;
436
430
  }
437
- this.serviceMap.Log.logInfo({
438
- title: 'sdk_before_confirm_abort'
439
- }, {
440
- paymentMethodType: paymentMethodType,
441
- path: 'nonApplePay_sync'
442
- });
431
+ if (timedOut) {
432
+ this.serviceMap.Log.logError({
433
+ title: 'sdk_before_confirm_timeout'
434
+ }, {
435
+ paymentMethodType: paymentMethodType,
436
+ path: 'nonApplePay_sync'
437
+ });
438
+ } else {
439
+ this.serviceMap.Log.logInfo({
440
+ title: 'sdk_before_confirm_abort'
441
+ }, {
442
+ paymentMethodType: paymentMethodType,
443
+ path: 'nonApplePay_sync'
444
+ });
445
+ }
443
446
  this.changeLoading(false);
444
447
  this.elementEventCenter.endEvent(startEventId, {
445
448
  eventCode: PaymentStatus.FAIL,
@@ -453,35 +456,25 @@ var ElementController = /*#__PURE__*/function () {
453
456
  needChangeSessionForRetry: false
454
457
  }
455
458
  });
456
- case 26:
459
+ case 23:
457
460
  this.serviceMap.Log.logInfo({
458
461
  title: 'sdk_before_confirm_success'
459
462
  }, {
460
463
  paymentMethodType: paymentMethodType,
461
464
  path: 'nonApplePay_sync'
462
465
  });
463
- _context4.next = 36;
466
+ _context4.next = 32;
464
467
  break;
465
- case 29:
466
- _context4.prev = 29;
467
- _context4.t0 = _context4["catch"](12);
468
- isTimeout = _context4.t0 instanceof Error && _context4.t0.message === 'onBeforeConfirm timed out';
469
- if (isTimeout) {
470
- this.serviceMap.Log.logError({
471
- title: 'sdk_before_confirm_timeout'
472
- }, {
473
- paymentMethodType: paymentMethodType,
474
- path: 'nonApplePay_sync'
475
- });
476
- } else {
477
- this.serviceMap.Log.logError({
478
- title: 'sdk_before_confirm_error'
479
- }, {
480
- paymentMethodType: paymentMethodType,
481
- errorMessage: String((_context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message) || _context4.t0).slice(0, 200),
482
- path: 'nonApplePay_sync'
483
- });
484
- }
468
+ case 26:
469
+ _context4.prev = 26;
470
+ _context4.t0 = _context4["catch"](11);
471
+ this.serviceMap.Log.logError({
472
+ title: 'sdk_before_confirm_error'
473
+ }, {
474
+ paymentMethodType: paymentMethodType,
475
+ errorMessage: String((_context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message) || _context4.t0).slice(0, 200),
476
+ path: 'nonApplePay_sync'
477
+ });
485
478
  this.changeLoading(false);
486
479
  this.elementEventCenter.endEvent(startEventId, {
487
480
  eventCode: PaymentStatus.FAIL,
@@ -495,10 +488,10 @@ var ElementController = /*#__PURE__*/function () {
495
488
  needChangeSessionForRetry: false
496
489
  }
497
490
  });
498
- case 36:
499
- _context4.next = 39;
491
+ case 32:
492
+ _context4.next = 35;
500
493
  break;
501
- case 38:
494
+ case 34:
502
495
  if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
503
496
  this.serviceMap.Log.logInfo({
504
497
  title: 'sdk_before_confirm_skip'
@@ -507,10 +500,10 @@ var ElementController = /*#__PURE__*/function () {
507
500
  path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
508
501
  });
509
502
  }
510
- case 39:
503
+ case 35:
511
504
  recordResult = null;
512
- _context4.prev = 40;
513
- _context4.next = 43;
505
+ _context4.prev = 36;
506
+ _context4.next = 39;
514
507
  return new Promise( /*#__PURE__*/function () {
515
508
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
516
509
  var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, _yield$_this3$onValid2, _data, errorString, errorResult;
@@ -667,10 +660,10 @@ var ElementController = /*#__PURE__*/function () {
667
660
  return _ref3.apply(this, arguments);
668
661
  };
669
662
  }());
670
- case 43:
663
+ case 39:
671
664
  return _context4.abrupt("return", _context4.sent);
672
- case 44:
673
- _context4.prev = 44;
665
+ case 40:
666
+ _context4.prev = 40;
674
667
  _logParams = {
675
668
  eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
676
669
  errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
@@ -681,12 +674,12 @@ var ElementController = /*#__PURE__*/function () {
681
674
  };
682
675
  this.elementEventCenter.endEvent(startEventId, _logParams);
683
676
  this.changeLoading(false);
684
- return _context4.finish(44);
685
- case 49:
677
+ return _context4.finish(40);
678
+ case 45:
686
679
  case "end":
687
680
  return _context4.stop();
688
681
  }
689
- }, _callee4, this, [[12, 29], [14,, 18, 21], [40,, 44, 49]]);
682
+ }, _callee4, this, [[11, 26], [36,, 40, 45]]);
690
683
  }));
691
684
  function submitPayment(_x) {
692
685
  return _submitPayment.apply(this, arguments);
@@ -33,6 +33,7 @@ import { parseSessionData } from "../../index";
33
33
  import { oneAccount, sdkAction } from "../mock";
34
34
  import { generateIframeSrc as _generateIframeSrc, isElementPad, isElementPC, safeStringify } from "../util";
35
35
  import BaseElementProcessor from "./baseElementProcessor";
36
+ import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../../../util/beforeConfirm";
36
37
  var logger = new Logger(LogConfig, true);
37
38
  var isExpressCheckout = function isExpressCheckout(extendInfo) {
38
39
  try {
@@ -194,7 +195,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
194
195
  // requests SDK layer to execute merchant's onBeforeConfirm callback via beforeConfirm event,
195
196
  // and returns the result (continue/abort) to iframe via dispatchToApp.
196
197
  this.eventCenter.listen(EVENT.beforeConfirm.name, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
197
- var paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, startTime, shouldContinue, isTimeout;
198
+ var paymentMethodType, startTime, _yield$executeWithTim, rawResult, timedOut, shouldContinue;
198
199
  return _regeneratorRuntime().wrap(function _callee$(_context) {
199
200
  while (1) switch (_context.prev = _context.next) {
200
201
  case 0:
@@ -218,25 +219,24 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
218
219
  });
219
220
  return _context.abrupt("return");
220
221
  case 5:
221
- BEFORE_CONFIRM_TIMEOUT_MS = 15000;
222
222
  logger.logInfo({
223
223
  title: 'sdk_before_confirm_start'
224
224
  }, {
225
225
  paymentMethodType: paymentMethodType,
226
226
  path: 'applePay_eventBridge'
227
227
  });
228
- _context.prev = 7;
229
- timeoutPromise = new Promise(function (_, reject) {
230
- return setTimeout(function () {
231
- return reject(new Error('onBeforeConfirm timed out'));
232
- }, BEFORE_CONFIRM_TIMEOUT_MS);
233
- });
228
+ _context.prev = 6;
234
229
  startTime = Date.now();
235
- _context.next = 12;
236
- return Promise.race([_this2._onBeforeConfirm(), timeoutPromise]);
237
- case 12:
238
- shouldContinue = _context.sent;
239
- if (Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
230
+ _context.next = 10;
231
+ return executeWithTimeout(function () {
232
+ return _this2._onBeforeConfirm();
233
+ });
234
+ case 10:
235
+ _yield$executeWithTim = _context.sent;
236
+ rawResult = _yield$executeWithTim.result;
237
+ timedOut = _yield$executeWithTim.timedOut;
238
+ shouldContinue = rawResult; // 双重校验:timedOut(Promise race) + startTime(实际时间差),防止竞态误判
239
+ if (timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
240
240
  logger.logError({
241
241
  title: 'sdk_before_confirm_timeout'
242
242
  });
@@ -251,31 +251,21 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
251
251
  event: EVENT.beforeConfirm.name,
252
252
  data: {
253
253
  success: true,
254
- result: shouldContinue !== false
254
+ result: !!shouldContinue
255
255
  }
256
256
  });
257
257
  _context.next = 23;
258
258
  break;
259
- case 18:
260
- _context.prev = 18;
261
- _context.t0 = _context["catch"](7);
262
- isTimeout = _context.t0 instanceof Error && _context.t0.message === 'onBeforeConfirm timed out';
263
- if (isTimeout) {
264
- logger.logError({
265
- title: 'sdk_before_confirm_timeout'
266
- }, {
267
- paymentMethodType: paymentMethodType,
268
- path: 'applePay_eventBridge'
269
- });
270
- } else {
271
- logger.logError({
272
- title: 'sdk_before_confirm_error'
273
- }, {
274
- paymentMethodType: paymentMethodType,
275
- errorMessage: String((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0).slice(0, 200),
276
- path: 'applePay_eventBridge'
277
- });
278
- }
259
+ case 19:
260
+ _context.prev = 19;
261
+ _context.t0 = _context["catch"](6);
262
+ logger.logError({
263
+ title: 'sdk_before_confirm_error'
264
+ }, {
265
+ paymentMethodType: paymentMethodType,
266
+ errorMessage: String((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0).slice(0, 200),
267
+ path: 'applePay_eventBridge'
268
+ });
279
269
  _this2.eventCenter.dispatchToApp({
280
270
  event: EVENT.beforeConfirm.name,
281
271
  data: {
@@ -287,7 +277,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
287
277
  case "end":
288
278
  return _context.stop();
289
279
  }
290
- }, _callee, null, [[7, 18]]);
280
+ }, _callee, null, [[6, 19]]);
291
281
  })));
292
282
  }
293
283
  }, {
@@ -17,6 +17,7 @@ import { getDoubleFaUrlFromSession } from "../../foundation/utils/web_app_url_ut
17
17
  import { getApplePayPaymentSession, submitPayInfo } from "../../service";
18
18
  import { EnvironmentEnum } from "../../types";
19
19
  import { device, isEmpty } from "../../util";
20
+ import { executeWithTimeout, BEFORE_CONFIRM_TIMEOUT_MS } from "../../util/beforeConfirm";
20
21
  import { APPLE_PAY_RECURRING_VERSION, APPLE_PAY_VERSION } from "../applepay/interface";
21
22
  var APPLEPAYERRORENUM = /*#__PURE__*/function (APPLEPAYERRORENUM) {
22
23
  APPLEPAYERRORENUM["APPLE_PAY_MISSING_DATA"] = "APPLE_PAY_MISSING_DATA";
@@ -212,7 +213,6 @@ export var ApplePaySdk = /*#__PURE__*/function () {
212
213
  try {
213
214
  if (!_this.session) return;
214
215
  _this.paymentStatus = PAYMENT_STATUS.PENDING;
215
- _this.session.begin();
216
216
  _this.session.onvalidatemerchant = /*#__PURE__*/function () {
217
217
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(event) {
218
218
  var requestParams, res, merchantSession, _this$logger, _this$logger2;
@@ -282,7 +282,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
282
282
  }();
283
283
  _this.session.onpaymentauthorized = /*#__PURE__*/function () {
284
284
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(event) {
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;
285
+ var exception, _event$payment, token, billingContact, shippingContact, _this$parseData, obj, _this$parseData$payme, requiredBillingContactFields, requiredShippingContactFields, _this$logger3, _this$logger4, _this$logger6, startTime, _yield$executeWithTim, rawResult, timedOut, shouldContinue, _this$logger5, _this$session2, _this$session2$comple, _this$logger7, _this$session3, _this$session3$comple, res, _this$logger8;
286
286
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
287
287
  while (1) switch (_context3.prev = _context3.next) {
288
288
  case 0:
@@ -296,7 +296,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
296
296
  };
297
297
  _event$payment = event === null || event === void 0 ? void 0 : event.payment, token = _event$payment.token, billingContact = _event$payment.billingContact, shippingContact = _event$payment.shippingContact;
298
298
  if (!token) {
299
- _context3.next = 48;
299
+ _context3.next = 46;
300
300
  break;
301
301
  }
302
302
  obj = {
@@ -320,33 +320,29 @@ export var ApplePaySdk = /*#__PURE__*/function () {
320
320
  paymentMethodType: 'APPLEPAY',
321
321
  path: 'applePay_chrome_sdk'
322
322
  });
323
- _context3.next = 41;
323
+ _context3.next = 39;
324
324
  break;
325
325
  case 11:
326
326
  // 清空回原始状态
327
327
  _this.cancelReason = 'USER_CANCEL';
328
- BEFORE_CONFIRM_TIMEOUT_MS = 15000;
329
328
  (_this$logger4 = _this.logger) === null || _this$logger4 === void 0 || _this$logger4.logInfo({
330
329
  title: 'sdk_before_confirm_start'
331
330
  }, {
332
331
  paymentMethodType: 'APPLEPAY',
333
332
  path: 'applePay_chrome_sdk'
334
333
  });
335
- _context3.prev = 14;
336
- timerId = null;
337
- timeoutPromise = new Promise(function (_, reject) {
338
- timerId = setTimeout(function () {
339
- return reject(new Error('onBeforeConfirm timed out'));
340
- }, BEFORE_CONFIRM_TIMEOUT_MS);
341
- });
334
+ _context3.prev = 13;
342
335
  startTime = Date.now();
343
- _context3.next = 20;
344
- return Promise.race([_this.onBeforeConfirm(), timeoutPromise]);
345
- case 20:
346
- shouldContinue = _context3.sent;
347
- // 正常返回时清除超时定时器,避免 unhandled promise rejection
348
- if (timerId !== null) clearTimeout(timerId);
349
- if (Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
336
+ _context3.next = 17;
337
+ return executeWithTimeout(function () {
338
+ return _this.onBeforeConfirm();
339
+ });
340
+ case 17:
341
+ _yield$executeWithTim = _context3.sent;
342
+ rawResult = _yield$executeWithTim.result;
343
+ timedOut = _yield$executeWithTim.timedOut;
344
+ shouldContinue = rawResult;
345
+ if (timedOut || Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
350
346
  (_this$logger5 = _this.logger) === null || _this$logger5 === void 0 || _this$logger5.logError({
351
347
  title: 'sdk_before_confirm_timeout'
352
348
  });
@@ -358,7 +354,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
358
354
  shouldContinue: shouldContinue
359
355
  });
360
356
  if (shouldContinue) {
361
- _context3.next = 30;
357
+ _context3.next = 29;
362
358
  break;
363
359
  }
364
360
  _this.cancelReason = 'MERCHANT_ABORT';
@@ -368,29 +364,19 @@ export var ApplePaySdk = /*#__PURE__*/function () {
368
364
  errorCode: 'MERCHANT_CONFIRM_ABORT'
369
365
  });
370
366
  return _context3.abrupt("return");
371
- case 30:
372
- _context3.next = 41;
367
+ case 29:
368
+ _context3.next = 39;
373
369
  break;
374
- case 32:
375
- _context3.prev = 32;
376
- _context3.t0 = _context3["catch"](14);
377
- isTimeout = _context3.t0 instanceof Error && _context3.t0.message === 'onBeforeConfirm timed out';
378
- if (isTimeout) {
379
- (_this$logger7 = _this.logger) === null || _this$logger7 === void 0 || _this$logger7.logError({
380
- title: 'sdk_before_confirm_timeout'
381
- }, {
382
- paymentMethodType: 'APPLEPAY',
383
- path: 'applePay_chrome_sdk'
384
- });
385
- } else {
386
- (_this$logger8 = _this.logger) === null || _this$logger8 === void 0 || _this$logger8.logError({
387
- title: 'sdk_before_confirm_error'
388
- }, {
389
- paymentMethodType: 'APPLEPAY',
390
- path: 'applePay_chrome_sdk',
391
- errorMessage: String((_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message) || _context3.t0).slice(0, 200)
392
- });
393
- }
370
+ case 31:
371
+ _context3.prev = 31;
372
+ _context3.t0 = _context3["catch"](13);
373
+ (_this$logger7 = _this.logger) === null || _this$logger7 === void 0 || _this$logger7.logError({
374
+ title: 'sdk_before_confirm_error'
375
+ }, {
376
+ paymentMethodType: 'APPLEPAY',
377
+ path: 'applePay_chrome_sdk',
378
+ errorMessage: String((_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message) || _context3.t0).slice(0, 200)
379
+ });
394
380
  _this.cancelReason = 'MERCHANT_ABORT';
395
381
  (_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);
396
382
  _this.abortSession();
@@ -398,25 +384,25 @@ export var ApplePaySdk = /*#__PURE__*/function () {
398
384
  errorCode: 'MERCHANT_CONFIRM_ABORT'
399
385
  });
400
386
  return _context3.abrupt("return");
401
- case 41:
402
- _context3.next = 43;
387
+ case 39:
388
+ _context3.next = 41;
403
389
  return _this.submitPay(obj);
404
- case 43:
390
+ case 41:
405
391
  res = _context3.sent;
406
392
  _this.setPayStatus(res);
407
393
  resolve(res);
408
- _context3.next = 50;
394
+ _context3.next = 48;
409
395
  break;
410
- case 48:
411
- (_this$logger9 = _this.logger) === null || _this$logger9 === void 0 || _this$logger9.logError({
396
+ case 46:
397
+ (_this$logger8 = _this.logger) === null || _this$logger8 === void 0 || _this$logger8.logError({
412
398
  title: 'a3753.b103030.c386485.d507486'
413
399
  });
414
400
  exception();
415
- case 50:
401
+ case 48:
416
402
  case "end":
417
403
  return _context3.stop();
418
404
  }
419
- }, _callee3, null, [[14, 32]]);
405
+ }, _callee3, null, [[13, 31]]);
420
406
  }));
421
407
  return function (_x2) {
422
408
  return _ref3.apply(this, arguments);
@@ -424,13 +410,13 @@ export var ApplePaySdk = /*#__PURE__*/function () {
424
410
  }();
425
411
  _this.session.oncancel = function () {
426
412
  if (_this.paymentStatus === PAYMENT_STATUS.PENDING) {
427
- var _this$logger10;
428
- (_this$logger10 = _this.logger) === null || _this$logger10 === void 0 || _this$logger10.logError({
413
+ var _this$logger9;
414
+ (_this$logger9 = _this.logger) === null || _this$logger9 === void 0 || _this$logger9.logError({
429
415
  title: 'a3753.b103030.c386485.d507497'
430
416
  });
431
417
  } else {
432
- var _this$logger11;
433
- (_this$logger11 = _this.logger) === null || _this$logger11 === void 0 || _this$logger11.logInfo({
418
+ var _this$logger10;
419
+ (_this$logger10 = _this.logger) === null || _this$logger10 === void 0 || _this$logger10.logInfo({
434
420
  title: 'a3753.b103030.c386485.d507498'
435
421
  });
436
422
  }
@@ -524,7 +510,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
524
510
  key: "initApplePaySession",
525
511
  value: function () {
526
512
  var _initApplePaySession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
527
- var _this$logger13, _this$parseData3, _this$logger12, _ref4, recurringInfo, version, _this$logger14;
513
+ var _this$logger12, _this$parseData3, _this$logger11, _ref4, recurringInfo, version, _this$logger13;
528
514
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
529
515
  while (1) switch (_context5.prev = _context5.next) {
530
516
  case 0:
@@ -539,7 +525,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
539
525
  _context5.next = 7;
540
526
  break;
541
527
  }
542
- (_this$logger12 = this.logger) === null || _this$logger12 === void 0 || _this$logger12.logError({
528
+ (_this$logger11 = this.logger) === null || _this$logger11 === void 0 || _this$logger11.logError({
543
529
  title: 'a3753.b103030.c386485.d507448'
544
530
  });
545
531
  this.paymentStatus = PAYMENT_STATUS.NORMAL;
@@ -547,7 +533,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
547
533
  errorCode: APPLEPAYERRORENUM.APPLE_PAY_MISSING_DATA
548
534
  }));
549
535
  case 7:
550
- (_this$logger13 = this.logger) === null || _this$logger13 === void 0 || _this$logger13.logInfo({
536
+ (_this$logger12 = this.logger) === null || _this$logger12 === void 0 || _this$logger12.logInfo({
551
537
  title: 'a3753.b103030.c386485.d507459'
552
538
  });
553
539
  _context5.next = 10;
@@ -573,7 +559,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
573
559
  case 19:
574
560
  _context5.prev = 19;
575
561
  _context5.t0 = _context5["catch"](0);
576
- (_this$logger14 = this.logger) === null || _this$logger14 === void 0 || _this$logger14.logError({
562
+ (_this$logger13 = this.logger) === null || _this$logger13 === void 0 || _this$logger13.logError({
577
563
  title: 'a3753.b103030.c386485.d507471'
578
564
  });
579
565
  return _context5.abrupt("return", Promise.reject({
@@ -0,0 +1,12 @@
1
+ export declare const BEFORE_CONFIRM_TIMEOUT_MS = 15000;
2
+ /**
3
+ * 带超时的异步执行,始终清理定时器避免 unhandled promise rejection。
4
+ *
5
+ * @param fn - 要执行的异步函数
6
+ * @param timeoutMs - 超时时间(毫秒),默认 15000
7
+ * @returns result 为 fn 的返回值(超时时为 undefined),timedOut 表示是否因超时返回
8
+ */
9
+ export declare function executeWithTimeout<T>(fn: () => Promise<T>, timeoutMs?: number): Promise<{
10
+ result: T | undefined;
11
+ timedOut: boolean;
12
+ }>;
@@ -0,0 +1,68 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ export var BEFORE_CONFIRM_TIMEOUT_MS = 15000;
6
+
7
+ /**
8
+ * 带超时的异步执行,始终清理定时器避免 unhandled promise rejection。
9
+ *
10
+ * @param fn - 要执行的异步函数
11
+ * @param timeoutMs - 超时时间(毫秒),默认 15000
12
+ * @returns result 为 fn 的返回值(超时时为 undefined),timedOut 表示是否因超时返回
13
+ */
14
+ export function executeWithTimeout(_x) {
15
+ return _executeWithTimeout.apply(this, arguments);
16
+ }
17
+ function _executeWithTimeout() {
18
+ _executeWithTimeout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(fn) {
19
+ var timeoutMs,
20
+ timerId,
21
+ timeoutPromise,
22
+ result,
23
+ isTimeout,
24
+ _args = arguments;
25
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
26
+ while (1) switch (_context.prev = _context.next) {
27
+ case 0:
28
+ timeoutMs = _args.length > 1 && _args[1] !== undefined ? _args[1] : BEFORE_CONFIRM_TIMEOUT_MS;
29
+ timeoutPromise = new Promise(function (_, reject) {
30
+ timerId = setTimeout(function () {
31
+ return reject(new Error('timed out'));
32
+ }, timeoutMs);
33
+ });
34
+ _context.prev = 2;
35
+ _context.next = 5;
36
+ return Promise.race([fn(), timeoutPromise]);
37
+ case 5:
38
+ result = _context.sent;
39
+ return _context.abrupt("return", {
40
+ result: result,
41
+ timedOut: false
42
+ });
43
+ case 9:
44
+ _context.prev = 9;
45
+ _context.t0 = _context["catch"](2);
46
+ isTimeout = _context.t0 instanceof Error && _context.t0.message === 'timed out';
47
+ if (!isTimeout) {
48
+ _context.next = 14;
49
+ break;
50
+ }
51
+ return _context.abrupt("return", {
52
+ result: undefined,
53
+ timedOut: true
54
+ });
55
+ case 14:
56
+ throw _context.t0;
57
+ case 15:
58
+ _context.prev = 15;
59
+ clearTimeout(timerId);
60
+ return _context.finish(15);
61
+ case 18:
62
+ case "end":
63
+ return _context.stop();
64
+ }
65
+ }, _callee, null, [[2, 9, 15, 18]]);
66
+ }));
67
+ return _executeWithTimeout.apply(this, arguments);
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1781004142-dev.13",
3
+ "version": "0.0.1781004142-dev.15",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "exports": {