@alipay/ams-checkout 0.0.1781004142-dev.0 → 0.0.1781004142-dev.1

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.
@@ -374,7 +374,7 @@ var ElementController = /*#__PURE__*/function () {
374
374
  value: function () {
375
375
  var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
376
376
  var _this3 = this;
377
- var startEventId, res, logParams, isApplePay, shouldContinue, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
377
+ var startEventId, res, logParams, isApplePay, BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, shouldContinue, isTimeout, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
378
378
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
379
379
  while (1) switch (_context4.prev = _context4.next) {
380
380
  case 0:
@@ -402,57 +402,73 @@ var ElementController = /*#__PURE__*/function () {
402
402
 
403
403
  // Non-Apple Pay: execute onBeforeConfirm at SDK layer directly, abort on failure
404
404
  isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
405
+ this.serviceMap.Log.logInfo({
406
+ title: 'sdk_element_submitPayment_beforeConfirm'
407
+ }, {
408
+ msg: safeStringify({
409
+ isApplePay: isApplePay,
410
+ hasOnBeforeConfirm: !!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm),
411
+ currentPaymentMethodType: this.currentPaymentMethodType
412
+ })
413
+ });
405
414
  if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
406
- _context4.next = 23;
415
+ _context4.next = 27;
407
416
  break;
408
417
  }
409
- _context4.prev = 9;
410
- _context4.next = 12;
411
- return submitParams.onBeforeConfirm();
412
- case 12:
418
+ BEFORE_CONFIRM_TIMEOUT_MS = 15000;
419
+ _context4.prev = 11;
420
+ timeoutPromise = new Promise(function (_, reject) {
421
+ return setTimeout(function () {
422
+ return reject(new Error('onBeforeConfirm timed out'));
423
+ }, BEFORE_CONFIRM_TIMEOUT_MS);
424
+ });
425
+ _context4.next = 15;
426
+ return Promise.race([submitParams.onBeforeConfirm(), timeoutPromise]);
427
+ case 15:
413
428
  shouldContinue = _context4.sent;
414
429
  if (!(shouldContinue === false)) {
415
- _context4.next = 16;
430
+ _context4.next = 19;
416
431
  break;
417
432
  }
418
433
  this.changeLoading(false);
419
434
  return _context4.abrupt("return", {
420
435
  status: PaymentStatus.FAIL,
421
436
  error: {
422
- code: 'MERCHANT_ABORT',
437
+ code: 'MERCHANT_CONFIRM_ABORT',
423
438
  message: 'Payment was cancelled by merchant before confirmation.',
424
439
  needChangeSessionForRetry: false
425
440
  }
426
441
  });
427
- case 16:
428
- _context4.next = 23;
442
+ case 19:
443
+ _context4.next = 27;
429
444
  break;
430
- case 18:
431
- _context4.prev = 18;
432
- _context4.t0 = _context4["catch"](9);
445
+ case 21:
446
+ _context4.prev = 21;
447
+ _context4.t0 = _context4["catch"](11);
433
448
  this.changeLoading(false);
449
+ isTimeout = _context4.t0 instanceof Error && _context4.t0.message === 'onBeforeConfirm timed out';
434
450
  this.serviceMap.Log.logError({
435
451
  title: ELEMENT_SPM_MAP.sdk_element_missKeyData
436
452
  }, {
437
453
  msg: safeStringify({
438
- error: 'onBeforeConfirm callback error'
454
+ error: isTimeout ? 'onBeforeConfirm timed out after 15s' : 'onBeforeConfirm callback error'
439
455
  })
440
456
  });
441
457
  return _context4.abrupt("return", {
442
458
  status: PaymentStatus.FAIL,
443
459
  error: {
444
- code: 'BEFORE_CONFIRM_ERROR',
445
- message: 'An error occurred during the before-confirm callback.',
460
+ code: 'MERCHANT_CONFIRM_ABORT',
461
+ message: isTimeout ? 'onBeforeConfirm timed out after 15 seconds.' : 'An error occurred during the before-confirm callback.',
446
462
  needChangeSessionForRetry: false
447
463
  }
448
464
  });
449
- case 23:
465
+ case 27:
450
466
  recordResult = null;
451
- _context4.prev = 24;
452
- _context4.next = 27;
467
+ _context4.prev = 28;
468
+ _context4.next = 31;
453
469
  return new Promise( /*#__PURE__*/function () {
454
470
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
455
- var that, recordResultCallback, params, processStep, _submitParams$handleA, hasBeforeConfirmForApplePay, _yield$_this3$onValid2, _data, errorString, errorResult;
471
+ var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, _yield$_this3$onValid2, _data, errorString, errorResult;
456
472
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
457
473
  while (1) switch (_context3.prev = _context3.next) {
458
474
  case 0:
@@ -528,31 +544,57 @@ var ElementController = /*#__PURE__*/function () {
528
544
  return _context3.abrupt("return");
529
545
  case 14:
530
546
  if (!_this3.elementProcessors[ElementType.payment]) {
531
- _context3.next = 23;
547
+ _context3.next = 24;
532
548
  break;
533
549
  }
534
550
  // Apple Pay: set onBeforeConfirm on paymentProcessor for event bridge callback after iframe authorization
535
551
  hasBeforeConfirmForApplePay = isApplePay && !!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm);
552
+ _this3.serviceMap.Log.logInfo({
553
+ title: 'sdk_element_submitPayment_setBeforeConfirm'
554
+ }, {
555
+ msg: safeStringify({
556
+ hasBeforeConfirmForApplePay: hasBeforeConfirmForApplePay,
557
+ isApplePay: isApplePay
558
+ })
559
+ });
536
560
  _this3.elementProcessors[ElementType.payment].setOnBeforeConfirm(hasBeforeConfirmForApplePay ? submitParams.onBeforeConfirm : null);
537
- _context3.next = 19;
538
- return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, _objectSpread(_objectSpread({}, params), {}, {
539
- handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
540
- shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo,
541
- applePayAmount: submitParams === null || submitParams === void 0 ? void 0 : submitParams.applePayAmount,
542
- hasBeforeConfirm: hasBeforeConfirmForApplePay
543
- }));
544
- case 19:
561
+ _context3.next = 20;
562
+ return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, function (_submitParams$handleA) {
563
+ var hasAmount = !!(submitParams !== null && submitParams !== void 0 && submitParams.amount);
564
+ var hasCurrency = !!(submitParams !== null && submitParams !== void 0 && submitParams.currency);
565
+ if ((hasAmount || hasCurrency) && !(hasAmount && hasCurrency)) {
566
+ _this3.serviceMap.Log.logError({
567
+ title: 'sdk_element_submitPayment_amountCurrencyMismatch'
568
+ }, {
569
+ msg: safeStringify({
570
+ amount: submitParams === null || submitParams === void 0 ? void 0 : submitParams.amount,
571
+ currency: submitParams === null || submitParams === void 0 ? void 0 : submitParams.currency,
572
+ reason: 'amount and currency must be provided together, both ignored'
573
+ })
574
+ });
575
+ }
576
+ return _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
577
+ handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
578
+ shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo
579
+ }, hasAmount && hasCurrency ? {
580
+ amount: submitParams.amount,
581
+ currency: submitParams.currency
582
+ } : {}), {}, {
583
+ hasBeforeConfirm: hasBeforeConfirmForApplePay
584
+ });
585
+ }());
586
+ case 20:
545
587
  _yield$_this3$onValid2 = _context3.sent;
546
588
  _data = _yield$_this3$onValid2.data;
547
589
  // TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
548
590
  // TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
549
591
  recordResult = _data;
550
592
  recordResultCallback(recordResult);
551
- case 23:
552
- _context3.next = 32;
593
+ case 24:
594
+ _context3.next = 33;
553
595
  break;
554
- case 25:
555
- _context3.prev = 25;
596
+ case 26:
597
+ _context3.prev = 26;
556
598
  _context3.t0 = _context3["catch"](2);
557
599
  // 修复error为{}空对象的问题,上报stack&message
558
600
  errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
@@ -569,20 +611,20 @@ var ElementController = /*#__PURE__*/function () {
569
611
  });
570
612
  recordResult = errorResult;
571
613
  recordResultCallback(errorResult);
572
- case 32:
614
+ case 33:
573
615
  case "end":
574
616
  return _context3.stop();
575
617
  }
576
- }, _callee3, null, [[2, 25]]);
618
+ }, _callee3, null, [[2, 26]]);
577
619
  }));
578
620
  return function (_x2) {
579
621
  return _ref3.apply(this, arguments);
580
622
  };
581
623
  }());
582
- case 27:
624
+ case 31:
583
625
  return _context4.abrupt("return", _context4.sent);
584
- case 28:
585
- _context4.prev = 28;
626
+ case 32:
627
+ _context4.prev = 32;
586
628
  _logParams = {
587
629
  eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
588
630
  errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
@@ -593,12 +635,12 @@ var ElementController = /*#__PURE__*/function () {
593
635
  };
594
636
  this.elementEventCenter.endEvent(startEventId, _logParams);
595
637
  this.changeLoading(false);
596
- return _context4.finish(28);
597
- case 33:
638
+ return _context4.finish(32);
639
+ case 37:
598
640
  case "end":
599
641
  return _context4.stop();
600
642
  }
601
- }, _callee4, this, [[9, 18], [24,, 28, 33]]);
643
+ }, _callee4, this, [[11, 21], [28,, 32, 37]]);
602
644
  }));
603
645
  function submitPayment(_x) {
604
646
  return _submitPayment.apply(this, arguments);
@@ -178,12 +178,17 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
178
178
  // requests SDK layer to execute merchant's onBeforeConfirm callback via beforeConfirm event,
179
179
  // and returns the result (continue/abort) to iframe via dispatchToApp.
180
180
  this.eventCenter.listen(EVENT.beforeConfirm.name, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
181
- var shouldContinue;
181
+ var BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, shouldContinue, isTimeout;
182
182
  return _regeneratorRuntime().wrap(function _callee$(_context) {
183
183
  while (1) switch (_context.prev = _context.next) {
184
184
  case 0:
185
+ logger.logInfo({
186
+ title: 'sdk_element_beforeConfirm_event_received'
187
+ }, {
188
+ hasCallback: !!_this2._onBeforeConfirm
189
+ });
185
190
  if (_this2._onBeforeConfirm) {
186
- _context.next = 3;
191
+ _context.next = 4;
187
192
  break;
188
193
  }
189
194
  _this2.eventCenter.dispatchToApp({
@@ -194,12 +199,23 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
194
199
  }
195
200
  });
196
201
  return _context.abrupt("return");
197
- case 3:
198
- _context.prev = 3;
199
- _context.next = 6;
200
- return _this2._onBeforeConfirm();
201
- case 6:
202
+ case 4:
203
+ BEFORE_CONFIRM_TIMEOUT_MS = 15000;
204
+ _context.prev = 5;
205
+ timeoutPromise = new Promise(function (_, reject) {
206
+ return setTimeout(function () {
207
+ return reject(new Error('onBeforeConfirm timed out'));
208
+ }, BEFORE_CONFIRM_TIMEOUT_MS);
209
+ });
210
+ _context.next = 9;
211
+ return Promise.race([_this2._onBeforeConfirm(), timeoutPromise]);
212
+ case 9:
202
213
  shouldContinue = _context.sent;
214
+ logger.logInfo({
215
+ title: 'sdk_element_beforeConfirm_callback_result'
216
+ }, {
217
+ shouldContinue: shouldContinue
218
+ });
203
219
  _this2.eventCenter.dispatchToApp({
204
220
  event: EVENT.beforeConfirm.name,
205
221
  data: {
@@ -207,15 +223,16 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
207
223
  result: shouldContinue !== false
208
224
  }
209
225
  });
210
- _context.next = 14;
226
+ _context.next = 19;
211
227
  break;
212
- case 10:
213
- _context.prev = 10;
214
- _context.t0 = _context["catch"](3);
228
+ case 14:
229
+ _context.prev = 14;
230
+ _context.t0 = _context["catch"](5);
231
+ isTimeout = _context.t0 instanceof Error && _context.t0.message === 'onBeforeConfirm timed out';
215
232
  logger.logError({
216
233
  title: 'sdk_element_onBeforeConfirm_error'
217
234
  }, {
218
- error: safeStringify(_context.t0)
235
+ error: isTimeout ? 'onBeforeConfirm timed out after 15s' : safeStringify(_context.t0)
219
236
  });
220
237
  _this2.eventCenter.dispatchToApp({
221
238
  event: EVENT.beforeConfirm.name,
@@ -224,11 +241,11 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
224
241
  result: false
225
242
  }
226
243
  });
227
- case 14:
244
+ case 19:
228
245
  case "end":
229
246
  return _context.stop();
230
247
  }
231
- }, _callee, null, [[3, 10]]);
248
+ }, _callee, null, [[5, 14]]);
232
249
  })));
233
250
  }
234
251
  }, {
@@ -284,32 +284,27 @@ export interface AddressSubmitData {
284
284
  shippingId: string;
285
285
  actionFlag?: 'I' | 'U' | 'D';
286
286
  }
287
- /**
288
- * Amount info displayed on Apple Pay sheet (display only; actual charge amount is controlled by server)
289
- */
290
- export interface SubmitAmount {
291
- /** Amount value, e.g. '10.99' */
292
- value: string;
293
- /** Currency code, e.g. 'USD' */
294
- currency: string;
295
- }
296
287
  export interface SubmitFuncParams {
297
288
  handleActions?: boolean;
298
289
  shippingInfo?: ShippingInfo;
299
290
  /**
300
- * Amount displayed on Apple Pay sheet. Only effective in Apple Pay scenario,
301
- * used to show amount when launching the sheet first. Actual charge amount
302
- * is determined by server. Ignored in non-Apple Pay scenarios.
291
+ * Amount displayed on the Apple Pay payment sheet, e.g. '10.99'.
292
+ * Display only; actual charge amount is controlled by server.
293
+ * Must be provided together with `currency`. Only effective for Apple Pay.
294
+ */
295
+ amount?: string;
296
+ /**
297
+ * Currency code displayed on the Apple Pay payment sheet, e.g. 'USD'.
298
+ * Follows ISO 4217 standard. Must be provided together with `amount`. Only effective for Apple Pay.
303
299
  */
304
- applePayAmount?: SubmitAmount;
300
+ currency?: string;
305
301
  /**
306
302
  * Pre-confirmation callback. Executed after user authorization but before actual charge,
307
303
  * allowing merchant to create order at this point.
308
- * - Apple Pay: invoked via event bridge after user FaceID/TouchID authorization on the sheet
309
- * - Non-Apple Pay: invoked synchronously at SDK layer
304
+ * - Only effective when payment method is Apple Pay
305
+ * - Invoked via event bridge after user FaceID/TouchID authorization on the payment sheet
310
306
  * - Return true: proceed with charge
311
- * - Return false: abort payment, returns MERCHANT_ABORT error code
312
- * - Throw error: abort payment, returns BEFORE_CONFIRM_ERROR error code
307
+ * - Return false / timeout / throw error: abort payment, returns MERCHANT_CONFIRM_ABORT error code
313
308
  */
314
309
  onBeforeConfirm?: () => Promise<boolean>;
315
310
  }
@@ -119,10 +119,6 @@ export var AddressEventCallbackName = /*#__PURE__*/function (AddressEventCallbac
119
119
  */
120
120
 
121
121
  // export type IMountResult = AddressMountResult | LinkAuthMountResult | PaymentMountResult;
122
-
123
- /**
124
- * Amount info displayed on Apple Pay sheet (display only; actual charge amount is controlled by server)
125
- */
126
122
  var AccountStatusEnum = /*#__PURE__*/function (AccountStatusEnum) {
127
123
  AccountStatusEnum["EFFECTIVE"] = "EFFECTIVE";
128
124
  AccountStatusEnum["UNREGISTERED"] = "UNREGISTERED";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1781004142-dev.0",
3
+ "version": "0.0.1781004142-dev.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "exports": {