@alipay/ams-checkout 2.0.17 → 2.0.18

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.
@@ -283,6 +283,9 @@ export declare const EVENT: {
283
283
  submitPromiseCallback: {
284
284
  name: string;
285
285
  };
286
+ beforeConfirm: {
287
+ name: string;
288
+ };
286
289
  validateFieldsResult: {
287
290
  name: string;
288
291
  forwardName: string;
@@ -289,6 +289,10 @@ export var EVENT = {
289
289
  submitPromiseCallback: {
290
290
  name: 'onSubmitPayCallback'
291
291
  },
292
+ // After Apple Pay authorization, before charge: notify SDK layer to execute merchant's onBeforeConfirm callback
293
+ beforeConfirm: {
294
+ name: 'onBeforeConfirm'
295
+ },
292
296
  validateFieldsResult: {
293
297
  name: 'validateFieldsResult',
294
298
  forwardName: 'validateFieldsResultForward',
@@ -10,6 +10,8 @@ declare class ElementController {
10
10
  private onStatusChangeCallback;
11
11
  private submitPayPromise;
12
12
  private elementEventCenter;
13
+ /** Current selected payment method type (e.g. 'APPLEPAY', 'CARD'), updated via paymentMethodChanged event */
14
+ private currentPaymentMethodType;
13
15
  constructor(options: IElementOptions);
14
16
  private initService;
15
17
  private initElementProcessors;
@@ -37,11 +37,12 @@ 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";
43
44
  import { oneAccountUpdate, sdkActionUpdate } from "../mock";
44
- import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
45
+ import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EVENTNAME, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
45
46
  import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeParse, safeStringify, showToast } from "../util";
46
47
  var TIMEOUT_DURATION = 16000;
47
48
  var ElementController = /*#__PURE__*/function () {
@@ -59,6 +60,8 @@ var ElementController = /*#__PURE__*/function () {
59
60
  // 新增变量
60
61
  _defineProperty(this, "submitPayPromise", void 0);
61
62
  _defineProperty(this, "elementEventCenter", void 0);
63
+ /** Current selected payment method type (e.g. 'APPLEPAY', 'CARD'), updated via paymentMethodChanged event */
64
+ _defineProperty(this, "currentPaymentMethodType", '');
62
65
  _defineProperty(this, "onValidateFunc", function (event, target) {
63
66
  return new Promise(function (resolve) {
64
67
  event.emitAndListen({
@@ -372,7 +375,7 @@ var ElementController = /*#__PURE__*/function () {
372
375
  value: function () {
373
376
  var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
374
377
  var _this3 = this;
375
- var startEventId, res, logParams, 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;
376
379
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
377
380
  while (1) switch (_context4.prev = _context4.next) {
378
381
  case 0:
@@ -397,12 +400,113 @@ var ElementController = /*#__PURE__*/function () {
397
400
  return _context4.abrupt("return", Promise.resolve(res));
398
401
  case 6:
399
402
  this.changeLoading(true);
403
+
404
+ // Non-Apple Pay: execute onBeforeConfirm at SDK layer directly, abort on failure
405
+ isApplePay = this.currentPaymentMethodType === 'APPLEPAY';
406
+ paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
407
+ if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
408
+ _context4.next = 34;
409
+ break;
410
+ }
411
+ this.serviceMap.Log.logInfo({
412
+ title: 'sdk_before_confirm_start'
413
+ }, {
414
+ paymentMethodType: paymentMethodType,
415
+ path: 'nonApplePay_sync'
416
+ });
417
+ _context4.prev = 11;
418
+ startTime = Date.now();
419
+ _context4.next = 15;
420
+ return executeWithTimeout(function () {
421
+ return submitParams.onBeforeConfirm();
422
+ });
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;
429
+ break;
430
+ }
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
+ }
446
+ this.changeLoading(false);
447
+ this.elementEventCenter.endEvent(startEventId, {
448
+ eventCode: PaymentStatus.FAIL,
449
+ errorName: 'MERCHANT_CONFIRM_ABORT'
450
+ });
451
+ return _context4.abrupt("return", {
452
+ status: PaymentStatus.FAIL,
453
+ error: {
454
+ code: 'MERCHANT_CONFIRM_ABORT',
455
+ message: 'Merchant canceled payment.',
456
+ needChangeSessionForRetry: false
457
+ }
458
+ });
459
+ case 23:
460
+ this.serviceMap.Log.logInfo({
461
+ title: 'sdk_before_confirm_success'
462
+ }, {
463
+ paymentMethodType: paymentMethodType,
464
+ path: 'nonApplePay_sync'
465
+ });
466
+ _context4.next = 32;
467
+ break;
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
+ });
478
+ this.changeLoading(false);
479
+ this.elementEventCenter.endEvent(startEventId, {
480
+ eventCode: PaymentStatus.FAIL,
481
+ errorName: 'MERCHANT_CONFIRM_ABORT'
482
+ });
483
+ return _context4.abrupt("return", {
484
+ status: PaymentStatus.FAIL,
485
+ error: {
486
+ code: 'MERCHANT_CONFIRM_ABORT',
487
+ message: 'Merchant canceled payment.',
488
+ needChangeSessionForRetry: false
489
+ }
490
+ });
491
+ case 32:
492
+ _context4.next = 35;
493
+ break;
494
+ case 34:
495
+ if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
496
+ this.serviceMap.Log.logInfo({
497
+ title: 'sdk_before_confirm_skip'
498
+ }, {
499
+ paymentMethodType: paymentMethodType,
500
+ path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
501
+ });
502
+ }
503
+ case 35:
400
504
  recordResult = null;
401
- _context4.prev = 8;
402
- _context4.next = 11;
505
+ _context4.prev = 36;
506
+ _context4.next = 39;
403
507
  return new Promise( /*#__PURE__*/function () {
404
508
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
405
- var that, recordResultCallback, params, processStep, _submitParams$handleA, _yield$_this3$onValid2, _data, errorString, errorResult;
509
+ var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, _yield$_this3$onValid2, _data, errorString, errorResult;
406
510
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
407
511
  while (1) switch (_context3.prev = _context3.next) {
408
512
  case 0:
@@ -478,26 +582,58 @@ var ElementController = /*#__PURE__*/function () {
478
582
  return _context3.abrupt("return");
479
583
  case 14:
480
584
  if (!_this3.elementProcessors[ElementType.payment]) {
481
- _context3.next = 21;
585
+ _context3.next = 28;
482
586
  break;
483
587
  }
484
- _context3.next = 17;
485
- return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, _objectSpread(_objectSpread({}, params), {}, {
486
- handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
487
- shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo
488
- }));
489
- case 17:
588
+ // Apple Pay: set onBeforeConfirm on paymentProcessor for event bridge callback after iframe authorization
589
+ hasBeforeConfirmForApplePay = isApplePay && !!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm);
590
+ _this3.serviceMap.Log.logInfo({
591
+ title: 'sdk_element_submitPayment_setBeforeConfirm'
592
+ }, {
593
+ msg: safeStringify({
594
+ hasBeforeConfirmForApplePay: hasBeforeConfirmForApplePay,
595
+ isApplePay: isApplePay
596
+ })
597
+ });
598
+ _this3.elementProcessors[ElementType.payment].setOnBeforeConfirm(hasBeforeConfirmForApplePay ? submitParams.onBeforeConfirm : null);
599
+ hasAmount = !!(submitParams !== null && submitParams !== void 0 && submitParams.amount);
600
+ hasCurrency = !!(submitParams !== null && submitParams !== void 0 && submitParams.currency);
601
+ if ((hasAmount || hasCurrency) && !(hasAmount && hasCurrency)) {
602
+ _this3.serviceMap.Log.logError({
603
+ title: 'sdk_element_submitPayment_amountCurrencyMismatch'
604
+ }, {
605
+ msg: safeStringify({
606
+ amount: submitParams === null || submitParams === void 0 ? void 0 : submitParams.amount,
607
+ currency: submitParams === null || submitParams === void 0 ? void 0 : submitParams.currency,
608
+ reason: 'amount and currency must be provided together, both ignored'
609
+ })
610
+ });
611
+ }
612
+ _this3.elementProcessors[ElementType.payment].setMerchantAmountOverride(hasAmount && hasCurrency ? submitParams.amount : null, hasAmount && hasCurrency ? submitParams.currency : null);
613
+ _context3.next = 24;
614
+ return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, function (_submitParams$handleA) {
615
+ return _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
616
+ handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
617
+ shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo
618
+ }, hasAmount && hasCurrency ? {
619
+ amount: submitParams.amount,
620
+ currency: submitParams.currency
621
+ } : {}), {}, {
622
+ hasBeforeConfirm: hasBeforeConfirmForApplePay
623
+ });
624
+ }());
625
+ case 24:
490
626
  _yield$_this3$onValid2 = _context3.sent;
491
627
  _data = _yield$_this3$onValid2.data;
492
628
  // TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
493
629
  // TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
494
630
  recordResult = _data;
495
631
  recordResultCallback(recordResult);
496
- case 21:
497
- _context3.next = 30;
632
+ case 28:
633
+ _context3.next = 37;
498
634
  break;
499
- case 23:
500
- _context3.prev = 23;
635
+ case 30:
636
+ _context3.prev = 30;
501
637
  _context3.t0 = _context3["catch"](2);
502
638
  // 修复error为{}空对象的问题,上报stack&message
503
639
  errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
@@ -514,20 +650,20 @@ var ElementController = /*#__PURE__*/function () {
514
650
  });
515
651
  recordResult = errorResult;
516
652
  recordResultCallback(errorResult);
517
- case 30:
653
+ case 37:
518
654
  case "end":
519
655
  return _context3.stop();
520
656
  }
521
- }, _callee3, null, [[2, 23]]);
657
+ }, _callee3, null, [[2, 30]]);
522
658
  }));
523
659
  return function (_x2) {
524
660
  return _ref3.apply(this, arguments);
525
661
  };
526
662
  }());
527
- case 11:
663
+ case 39:
528
664
  return _context4.abrupt("return", _context4.sent);
529
- case 12:
530
- _context4.prev = 12;
665
+ case 40:
666
+ _context4.prev = 40;
531
667
  _logParams = {
532
668
  eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
533
669
  errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
@@ -538,12 +674,12 @@ var ElementController = /*#__PURE__*/function () {
538
674
  };
539
675
  this.elementEventCenter.endEvent(startEventId, _logParams);
540
676
  this.changeLoading(false);
541
- return _context4.finish(12);
542
- case 17:
677
+ return _context4.finish(40);
678
+ case 45:
543
679
  case "end":
544
680
  return _context4.stop();
545
681
  }
546
- }, _callee4, this, [[8,, 12, 17]]);
682
+ }, _callee4, this, [[11, 26], [36,, 40, 45]]);
547
683
  }));
548
684
  function submitPayment(_x) {
549
685
  return _submitPayment.apply(this, arguments);
@@ -628,6 +764,9 @@ var ElementController = /*#__PURE__*/function () {
628
764
  var _this4$submitPayPromi;
629
765
  (_this4$submitPayPromi = _this4.submitPayPromise) === null || _this4$submitPayPromi === void 0 || _this4$submitPayPromi.call(_this4, data);
630
766
  });
767
+ this.serviceMap.EventCenter.listen(EVENTNAME.PAYMENTMETHODCHANGED, function (data) {
768
+ _this4.currentPaymentMethodType = (data === null || data === void 0 ? void 0 : data.type) || '';
769
+ });
631
770
  }
632
771
  }, {
633
772
  key: "sendRequestAndWaitWebLaunch",
@@ -2,6 +2,16 @@ import { LogService } from '../../../../foundation/service/log';
2
2
  import BaseElementProcessor from './baseElementProcessor';
3
3
  declare class PaymentProcessor extends BaseElementProcessor {
4
4
  private ApplePayService;
5
+ /**
6
+ * Merchant's onBeforeConfirm callback reference, used in Apple Pay scenario only.
7
+ * Set by elementController.submitPayment before payment,
8
+ * triggered via beforeConfirm event after Apple Pay authorization in iframe.
9
+ */
10
+ private _onBeforeConfirm;
11
+ private _merchantAmount;
12
+ private _merchantCurrency;
13
+ setOnBeforeConfirm(callback: (() => Promise<boolean>) | null): void;
14
+ setMerchantAmountOverride(amount: string | null, currency: string | null): void;
5
15
  onReady(extraParam: any): void;
6
16
  getLogger(): LogService;
7
17
  private addEventListener;
@@ -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 {
@@ -56,9 +57,32 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
56
57
  // parameterInitAndCheck(): void {}
57
58
  // apple pay
58
59
  _defineProperty(_assertThisInitialized(_this), "ApplePayService", void 0);
60
+ /**
61
+ * Merchant's onBeforeConfirm callback reference, used in Apple Pay scenario only.
62
+ * Set by elementController.submitPayment before payment,
63
+ * triggered via beforeConfirm event after Apple Pay authorization in iframe.
64
+ */
65
+ _defineProperty(_assertThisInitialized(_this), "_onBeforeConfirm", null);
66
+ _defineProperty(_assertThisInitialized(_this), "_merchantAmount", null);
67
+ _defineProperty(_assertThisInitialized(_this), "_merchantCurrency", null);
59
68
  return _this;
60
69
  }
61
70
  _createClass(PaymentProcessor, [{
71
+ key: "setOnBeforeConfirm",
72
+ value: function setOnBeforeConfirm(callback) {
73
+ this._onBeforeConfirm = callback;
74
+ // 展码链路:同步设置 onBeforeConfirm 到 ApplePaySdk,确保 Chrome 展码支付时能调用商户回调
75
+ if (this.ApplePayService) {
76
+ this.ApplePayService.setOnBeforeConfirm(callback);
77
+ }
78
+ }
79
+ }, {
80
+ key: "setMerchantAmountOverride",
81
+ value: function setMerchantAmountOverride(amount, currency) {
82
+ this._merchantAmount = amount;
83
+ this._merchantCurrency = currency;
84
+ }
85
+ }, {
62
86
  key: "onReady",
63
87
  value: function onReady(extraParam) {
64
88
  var _this$elementContaine, _this$elementContaine2, _this$elementContaine3, _this$elementContaine4, _this$elementContaine5;
@@ -143,8 +167,12 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
143
167
  parseData: paymentSessionObj,
144
168
  logger: logger,
145
169
  env: _this2.options.env.environment,
146
- shipping: shipping
170
+ shipping: shipping,
171
+ merchantAmount: _this2._merchantAmount,
172
+ merchantCurrency: _this2._merchantCurrency
147
173
  });
174
+ // Chrome 展码链路:同步 onBeforeConfirm 到当前 ApplePaySdk 实例
175
+ applePayService.setOnBeforeConfirm(_this2._onBeforeConfirm);
148
176
  applePayService.startPay().then(function (res) {
149
177
  _this2.eventCenter.dispatchToApp({
150
178
  event: 'getApplePayToken',
@@ -163,19 +191,107 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
163
191
  });
164
192
  });
165
193
  });
194
+ // Apple Pay event bridge: after user authorization (FaceID/TouchID) in iframe, before actual charge,
195
+ // requests SDK layer to execute merchant's onBeforeConfirm callback via beforeConfirm event,
196
+ // and returns the result (continue/abort) to iframe via dispatchToApp.
197
+ this.eventCenter.listen(EVENT.beforeConfirm.name, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
198
+ var paymentMethodType, startTime, _yield$executeWithTim, rawResult, timedOut, shouldContinue;
199
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
200
+ while (1) switch (_context.prev = _context.next) {
201
+ case 0:
202
+ paymentMethodType = 'APPLEPAY';
203
+ if (_this2._onBeforeConfirm) {
204
+ _context.next = 5;
205
+ break;
206
+ }
207
+ logger.logInfo({
208
+ title: 'sdk_before_confirm_skip'
209
+ }, {
210
+ paymentMethodType: paymentMethodType,
211
+ path: 'applePay_eventBridge'
212
+ });
213
+ _this2.eventCenter.dispatchToApp({
214
+ event: EVENT.beforeConfirm.name,
215
+ data: {
216
+ success: true,
217
+ result: true
218
+ }
219
+ });
220
+ return _context.abrupt("return");
221
+ case 5:
222
+ logger.logInfo({
223
+ title: 'sdk_before_confirm_start'
224
+ }, {
225
+ paymentMethodType: paymentMethodType,
226
+ path: 'applePay_eventBridge'
227
+ });
228
+ _context.prev = 6;
229
+ startTime = Date.now();
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
+ logger.logError({
241
+ title: 'sdk_before_confirm_timeout'
242
+ });
243
+ shouldContinue = false;
244
+ }
245
+ logger.logInfo({
246
+ title: 'sdk_element_beforeConfirm_callback_result'
247
+ }, {
248
+ shouldContinue: shouldContinue
249
+ });
250
+ _this2.eventCenter.dispatchToApp({
251
+ event: EVENT.beforeConfirm.name,
252
+ data: {
253
+ success: true,
254
+ result: !!shouldContinue
255
+ }
256
+ });
257
+ _context.next = 23;
258
+ break;
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
+ });
269
+ _this2.eventCenter.dispatchToApp({
270
+ event: EVENT.beforeConfirm.name,
271
+ data: {
272
+ success: false,
273
+ result: false
274
+ }
275
+ });
276
+ case 23:
277
+ case "end":
278
+ return _context.stop();
279
+ }
280
+ }, _callee, null, [[6, 19]]);
281
+ })));
166
282
  }
167
283
  }, {
168
284
  key: "initApplePaySdk",
169
285
  value: function () {
170
- var _initApplePaySdk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
286
+ var _initApplePaySdk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
171
287
  var _this$elementContaine6;
172
- var _ref, paymentSessionObj, paymentSession;
173
- return _regeneratorRuntime().wrap(function _callee$(_context) {
174
- while (1) switch (_context.prev = _context.next) {
288
+ var _ref2, paymentSessionObj, paymentSession;
289
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
290
+ while (1) switch (_context2.prev = _context2.next) {
175
291
  case 0:
176
- _ref = ((_this$elementContaine6 = this.elementContainer) === null || _this$elementContaine6 === void 0 ? void 0 : _this$elementContaine6.getPaymentContext()) || {}, paymentSessionObj = _ref.paymentSessionObj, paymentSession = _ref.paymentSession;
292
+ _ref2 = ((_this$elementContaine6 = this.elementContainer) === null || _this$elementContaine6 === void 0 ? void 0 : _this$elementContaine6.getPaymentContext()) || {}, paymentSessionObj = _ref2.paymentSessionObj, paymentSession = _ref2.paymentSession;
177
293
  if (!isSkipRenderPaymentMethod(paymentSessionObj)) {
178
- _context.next = 13;
294
+ _context2.next = 13;
179
295
  break;
180
296
  }
181
297
  this.ApplePayService = new ApplePaySdk({
@@ -184,29 +300,29 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
184
300
  logger: logger,
185
301
  env: this.options.env.environment
186
302
  });
187
- _context.prev = 3;
303
+ _context2.prev = 3;
188
304
  logger.logInfo({
189
305
  title: 'a3753.b107385.c398110'
190
306
  });
191
- _context.next = 7;
307
+ _context2.next = 7;
192
308
  return this.ApplePayService.initApplePaySession();
193
309
  case 7:
194
310
  logger.logInfo({
195
311
  title: 'a3753.b107385.c398112'
196
312
  });
197
- _context.next = 13;
313
+ _context2.next = 13;
198
314
  break;
199
315
  case 10:
200
- _context.prev = 10;
201
- _context.t0 = _context["catch"](3);
316
+ _context2.prev = 10;
317
+ _context2.t0 = _context2["catch"](3);
202
318
  logger.logError({
203
319
  title: 'a3753.b107385.c398111'
204
320
  });
205
321
  case 13:
206
322
  case "end":
207
- return _context.stop();
323
+ return _context2.stop();
208
324
  }
209
- }, _callee, this, [[3, 10]]);
325
+ }, _callee2, this, [[3, 10]]);
210
326
  }));
211
327
  function initApplePaySdk() {
212
328
  return _initApplePaySdk.apply(this, arguments);
@@ -227,20 +343,20 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
227
343
  }
228
344
  }, {
229
345
  key: "generateIframeSrc",
230
- value: function generateIframeSrc(_ref2) {
231
- var link = _ref2.link,
232
- instanceId = _ref2.instanceId;
346
+ value: function generateIframeSrc(_ref3) {
347
+ var link = _ref3.link,
348
+ instanceId = _ref3.instanceId;
233
349
  this.instanceId = instanceId;
234
- var _ref3 = this.elementContainer.getPaymentContext() || {},
235
- paymentSession = _ref3.paymentSession,
236
- paymentSessionObj = _ref3.paymentSessionObj,
237
- sdkMetaData = _ref3.sdkMetaData;
350
+ var _ref4 = this.elementContainer.getPaymentContext() || {},
351
+ paymentSession = _ref4.paymentSession,
352
+ paymentSessionObj = _ref4.paymentSessionObj,
353
+ sdkMetaData = _ref4.sdkMetaData;
238
354
  var _this$options = this.options,
239
355
  environment = _this$options.env.environment,
240
356
  analytics = _this$options.analytics,
241
357
  locale = _this$options.locale;
242
- var _ref4 = paymentSessionObj || {},
243
- extendInfo = _ref4.extendInfo;
358
+ var _ref5 = paymentSessionObj || {},
359
+ extendInfo = _ref5.extendInfo;
244
360
  var url = _generateIframeSrc({
245
361
  paymentSession: paymentSession,
246
362
  paymentSessionObj: paymentSessionObj,
@@ -258,19 +374,19 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
258
374
  }, {
259
375
  key: "obtainData",
260
376
  value: function () {
261
- var _obtainData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
377
+ var _obtainData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
262
378
  var _paymentSessionObj$co,
263
379
  _this3 = this;
264
- var requestService, _this$elementContaine7, paymentSession, paymentSessionObj, displayInfo, _displayInfo, debugProps, _this$options2, environment, locale, _ref5, paymentSessionConfig, hostSign, isConnect, LOCAL_MOCK, _queryParse, appType, terminalType, generateActionQueryPromise, generateOneAccountQueryPromise, _yield$Promise$all, _yield$Promise$all2, originActionQueryResult, originOneAccountQueryResult;
265
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
266
- while (1) switch (_context2.prev = _context2.next) {
380
+ var requestService, _this$elementContaine7, paymentSession, paymentSessionObj, displayInfo, _displayInfo, debugProps, _this$options2, environment, locale, _ref6, paymentSessionConfig, hostSign, isConnect, LOCAL_MOCK, _queryParse, appType, terminalType, generateActionQueryPromise, generateOneAccountQueryPromise, _yield$Promise$all, _yield$Promise$all2, originActionQueryResult, originOneAccountQueryResult;
381
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
382
+ while (1) switch (_context3.prev = _context3.next) {
267
383
  case 0:
268
384
  requestService = ServiceProvider.getInstance(this.instanceId).getService('Requester');
269
385
  _this$elementContaine7 = this.elementContainer.getPaymentContext(), paymentSession = _this$elementContaine7.paymentSession, paymentSessionObj = _this$elementContaine7.paymentSessionObj, displayInfo = _this$elementContaine7.displayInfo;
270
386
  _displayInfo = displayInfo;
271
387
  debugProps = _displayInfo.debugProps;
272
388
  _this$options2 = this.options, environment = _this$options2.env.environment, locale = _this$options2.locale;
273
- _ref5 = paymentSessionObj || {}, paymentSessionConfig = _ref5.paymentSessionConfig;
389
+ _ref6 = paymentSessionObj || {}, paymentSessionConfig = _ref6.paymentSessionConfig;
274
390
  hostSign = paymentSession.split('&&')[1] || '';
275
391
  isConnect = paymentSessionObj === null || paymentSessionObj === void 0 || (_paymentSessionObj$co = paymentSessionObj.connectFactor) === null || _paymentSessionObj$co === void 0 ? void 0 : _paymentSessionObj$co.enableConnect;
276
392
  LOCAL_MOCK = (debugProps === null || debugProps === void 0 ? void 0 : debugProps.isDebug) && (debugProps === null || debugProps === void 0 ? void 0 : debugProps.local_mock);
@@ -407,10 +523,10 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
407
523
  });
408
524
  });
409
525
  };
410
- _context2.next = 15;
526
+ _context3.next = 15;
411
527
  return Promise.all(isConnect ? [generateActionQueryPromise(), generateOneAccountQueryPromise()] : [generateActionQueryPromise()]);
412
528
  case 15:
413
- _yield$Promise$all = _context2.sent;
529
+ _yield$Promise$all = _context3.sent;
414
530
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
415
531
  originActionQueryResult = _yield$Promise$all2[0];
416
532
  originOneAccountQueryResult = _yield$Promise$all2[1];
@@ -418,15 +534,15 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
418
534
  originActionQueryResult: originActionQueryResult,
419
535
  originOneAccountQueryResult: originOneAccountQueryResult
420
536
  };
421
- return _context2.abrupt("return", {
537
+ return _context3.abrupt("return", {
422
538
  originActionQueryResult: originActionQueryResult,
423
539
  originOneAccountQueryResult: originOneAccountQueryResult
424
540
  });
425
541
  case 21:
426
542
  case "end":
427
- return _context2.stop();
543
+ return _context3.stop();
428
544
  }
429
- }, _callee2, this);
545
+ }, _callee3, this);
430
546
  }));
431
547
  function obtainData() {
432
548
  return _obtainData.apply(this, arguments);
@@ -441,9 +557,9 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
441
557
  }
442
558
  }, {
443
559
  key: "update",
444
- value: function update(_ref6) {
445
- var data = _ref6.data,
446
- paymentSessionData = _ref6.paymentSessionData;
560
+ value: function update(_ref7) {
561
+ var data = _ref7.data,
562
+ paymentSessionData = _ref7.paymentSessionData;
447
563
  var _parseSessionData = parseSessionData(paymentSessionData),
448
564
  _parseSessionData2 = _slicedToArray(_parseSessionData, 2),
449
565
  parseData = _parseSessionData2[0],
@@ -287,6 +287,26 @@ export interface AddressSubmitData {
287
287
  export interface SubmitFuncParams {
288
288
  handleActions?: boolean;
289
289
  shippingInfo?: ShippingInfo;
290
+ /**
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.
299
+ */
300
+ currency?: string;
301
+ /**
302
+ * Pre-confirmation callback. Executed after user authorization but before actual charge,
303
+ * allowing merchant to create order at this point.
304
+ * - Only effective when payment method is Apple Pay
305
+ * - Invoked via event bridge after user FaceID/TouchID authorization on the payment sheet
306
+ * - Return true: proceed with charge
307
+ * - Return false / timeout / throw error: abort payment, returns MERCHANT_CONFIRM_ABORT error code
308
+ */
309
+ onBeforeConfirm?: () => Promise<boolean>;
290
310
  }
291
311
  export interface SubmitServiceParams extends PaymentSubmitData {
292
312
  accountInfo: AuthSubmitData['accountInfo'];