@alipay/ams-checkout 0.0.1781004142-dev.12 → 0.0.1781004142-dev.14

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);
@@ -277,7 +281,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
277
281
  }();
278
282
  _this.session.onpaymentauthorized = /*#__PURE__*/function () {
279
283
  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;
284
+ 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
285
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
282
286
  while (1) switch (_context3.prev = _context3.next) {
283
287
  case 0:
@@ -291,7 +295,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
291
295
  };
292
296
  _event$payment = event === null || event === void 0 ? void 0 : event.payment, token = _event$payment.token, billingContact = _event$payment.billingContact, shippingContact = _event$payment.shippingContact;
293
297
  if (!token) {
294
- _context3.next = 43;
298
+ _context3.next = 48;
295
299
  break;
296
300
  }
297
301
  obj = {
@@ -315,9 +319,11 @@ export var ApplePaySdk = /*#__PURE__*/function () {
315
319
  paymentMethodType: 'APPLEPAY',
316
320
  path: 'applePay_chrome_sdk'
317
321
  });
318
- _context3.next = 36;
322
+ _context3.next = 41;
319
323
  break;
320
324
  case 11:
325
+ // 清空回原始状态
326
+ _this.cancelReason = 'USER_CANCEL';
321
327
  BEFORE_CONFIRM_TIMEOUT_MS = 15000;
322
328
  (_this$logger4 = _this.logger) === null || _this$logger4 === void 0 || _this$logger4.logInfo({
323
329
  title: 'sdk_before_confirm_start'
@@ -325,17 +331,20 @@ export var ApplePaySdk = /*#__PURE__*/function () {
325
331
  paymentMethodType: 'APPLEPAY',
326
332
  path: 'applePay_chrome_sdk'
327
333
  });
328
- _context3.prev = 13;
334
+ _context3.prev = 14;
335
+ timerId = null;
329
336
  timeoutPromise = new Promise(function (_, reject) {
330
- return setTimeout(function () {
337
+ timerId = setTimeout(function () {
331
338
  return reject(new Error('onBeforeConfirm timed out'));
332
339
  }, BEFORE_CONFIRM_TIMEOUT_MS);
333
340
  });
334
341
  startTime = Date.now();
335
- _context3.next = 18;
342
+ _context3.next = 20;
336
343
  return Promise.race([_this.onBeforeConfirm(), timeoutPromise]);
337
- case 18:
344
+ case 20:
338
345
  shouldContinue = _context3.sent;
346
+ // 正常返回时清除超时定时器,避免 unhandled promise rejection
347
+ if (timerId !== null) clearTimeout(timerId);
339
348
  if (Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
340
349
  (_this$logger5 = _this.logger) === null || _this$logger5 === void 0 || _this$logger5.logError({
341
350
  title: 'sdk_before_confirm_timeout'
@@ -348,21 +357,22 @@ export var ApplePaySdk = /*#__PURE__*/function () {
348
357
  shouldContinue: shouldContinue
349
358
  });
350
359
  if (shouldContinue) {
351
- _context3.next = 26;
360
+ _context3.next = 30;
352
361
  break;
353
362
  }
363
+ _this.cancelReason = 'MERCHANT_ABORT';
354
364
  (_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
365
  _this.abortSession();
356
366
  reject({
357
367
  errorCode: 'MERCHANT_CONFIRM_ABORT'
358
368
  });
359
369
  return _context3.abrupt("return");
360
- case 26:
361
- _context3.next = 36;
370
+ case 30:
371
+ _context3.next = 41;
362
372
  break;
363
- case 28:
364
- _context3.prev = 28;
365
- _context3.t0 = _context3["catch"](13);
373
+ case 32:
374
+ _context3.prev = 32;
375
+ _context3.t0 = _context3["catch"](14);
366
376
  isTimeout = _context3.t0 instanceof Error && _context3.t0.message === 'onBeforeConfirm timed out';
367
377
  if (isTimeout) {
368
378
  (_this$logger7 = _this.logger) === null || _this$logger7 === void 0 || _this$logger7.logError({
@@ -380,31 +390,32 @@ export var ApplePaySdk = /*#__PURE__*/function () {
380
390
  errorMessage: String((_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message) || _context3.t0).slice(0, 200)
381
391
  });
382
392
  }
393
+ _this.cancelReason = 'MERCHANT_ABORT';
383
394
  (_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
395
  _this.abortSession();
385
396
  reject({
386
397
  errorCode: 'MERCHANT_CONFIRM_ABORT'
387
398
  });
388
399
  return _context3.abrupt("return");
389
- case 36:
390
- _context3.next = 38;
400
+ case 41:
401
+ _context3.next = 43;
391
402
  return _this.submitPay(obj);
392
- case 38:
403
+ case 43:
393
404
  res = _context3.sent;
394
405
  _this.setPayStatus(res);
395
406
  resolve(res);
396
- _context3.next = 45;
407
+ _context3.next = 50;
397
408
  break;
398
- case 43:
409
+ case 48:
399
410
  (_this$logger9 = _this.logger) === null || _this$logger9 === void 0 || _this$logger9.logError({
400
411
  title: 'a3753.b103030.c386485.d507486'
401
412
  });
402
413
  exception();
403
- case 45:
414
+ case 50:
404
415
  case "end":
405
416
  return _context3.stop();
406
417
  }
407
- }, _callee3, null, [[13, 28]]);
418
+ }, _callee3, null, [[14, 32]]);
408
419
  }));
409
420
  return function (_x2) {
410
421
  return _ref3.apply(this, arguments);
@@ -422,8 +433,10 @@ export var ApplePaySdk = /*#__PURE__*/function () {
422
433
  title: 'a3753.b103030.c386485.d507498'
423
434
  });
424
435
  }
436
+ // cancelReason === 'MERCHANT_ABORT': onBeforeConfirm 返回 false 或异常,由商户主动中止
437
+ // 其他:用户主动取消付款界面
425
438
  reject({
426
- errorCode: APPLEPAYERRORENUM.APPLE_PAY_CANCEL
439
+ errorCode: _this.cancelReason === 'MERCHANT_ABORT' ? 'MERCHANT_CONFIRM_ABORT' : APPLEPAYERRORENUM.APPLE_PAY_CANCEL
427
440
  });
428
441
  };
429
442
  _this.session.begin();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1781004142-dev.12",
3
+ "version": "0.0.1781004142-dev.14",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "exports": {