@alipay/ams-checkout 0.0.1781004142-dev.0 → 0.0.1781004142-dev.11
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.
- package/ams-checkout.js +3 -3
- package/dist/ams-checkout.min.js +1 -1
- package/esm/core/component/element/elementController/index.js +136 -48
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +3 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +72 -19
- package/esm/core/component/element/type.d.ts +12 -17
- package/esm/core/component/element/type.js +0 -4
- package/esm/plugin/component/channel.d.ts +5 -1
- package/esm/plugin/component/channel.js +25 -13
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/types/index.d.ts +2 -7
- package/esm/util/spm-map.d.ts +6 -0
- package/esm/util/spm-map.js +7 -1
- package/package.json +1 -1
|
@@ -60,7 +60,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
60
60
|
_defineProperty(this, "submitPayPromise", void 0);
|
|
61
61
|
_defineProperty(this, "elementEventCenter", void 0);
|
|
62
62
|
/** Current selected payment method type (e.g. 'APPLEPAY', 'CARD'), updated via paymentMethodChanged event */
|
|
63
|
-
_defineProperty(this, "currentPaymentMethodType",
|
|
63
|
+
_defineProperty(this, "currentPaymentMethodType", '');
|
|
64
64
|
_defineProperty(this, "onValidateFunc", function (event, target) {
|
|
65
65
|
return new Promise(function (resolve) {
|
|
66
66
|
event.emitAndListen({
|
|
@@ -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, paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS, timerId, 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,118 @@ 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
|
+
paymentMethodType = this.currentPaymentMethodType || 'UNKNOWN';
|
|
405
406
|
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm && !isApplePay)) {
|
|
406
|
-
_context4.next =
|
|
407
|
+
_context4.next = 38;
|
|
407
408
|
break;
|
|
408
409
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
410
|
+
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
411
|
+
this.serviceMap.Log.logInfo({
|
|
412
|
+
title: 'sdk_before_confirm_start'
|
|
413
|
+
}, {
|
|
414
|
+
paymentMethodType: paymentMethodType,
|
|
415
|
+
path: 'nonApplePay_sync'
|
|
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);
|
|
422
|
+
});
|
|
423
|
+
_context4.prev = 14;
|
|
424
|
+
_context4.next = 17;
|
|
425
|
+
return Promise.race([submitParams.onBeforeConfirm(), timeoutPromise]);
|
|
426
|
+
case 17:
|
|
413
427
|
shouldContinue = _context4.sent;
|
|
428
|
+
case 18:
|
|
429
|
+
_context4.prev = 18;
|
|
430
|
+
clearTimeout(timerId);
|
|
431
|
+
return _context4.finish(18);
|
|
432
|
+
case 21:
|
|
414
433
|
if (!(shouldContinue === false)) {
|
|
415
|
-
_context4.next =
|
|
434
|
+
_context4.next = 26;
|
|
416
435
|
break;
|
|
417
436
|
}
|
|
437
|
+
this.serviceMap.Log.logInfo({
|
|
438
|
+
title: 'sdk_before_confirm_abort'
|
|
439
|
+
}, {
|
|
440
|
+
paymentMethodType: paymentMethodType,
|
|
441
|
+
path: 'nonApplePay_sync'
|
|
442
|
+
});
|
|
418
443
|
this.changeLoading(false);
|
|
444
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
445
|
+
eventCode: PaymentStatus.FAIL,
|
|
446
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
447
|
+
});
|
|
419
448
|
return _context4.abrupt("return", {
|
|
420
449
|
status: PaymentStatus.FAIL,
|
|
421
450
|
error: {
|
|
422
|
-
code: '
|
|
423
|
-
message: '
|
|
451
|
+
code: 'MERCHANT_CONFIRM_ABORT',
|
|
452
|
+
message: 'Merchant canceled payment.',
|
|
424
453
|
needChangeSessionForRetry: false
|
|
425
454
|
}
|
|
426
455
|
});
|
|
427
|
-
case
|
|
428
|
-
|
|
456
|
+
case 26:
|
|
457
|
+
this.serviceMap.Log.logInfo({
|
|
458
|
+
title: 'sdk_before_confirm_success'
|
|
459
|
+
}, {
|
|
460
|
+
paymentMethodType: paymentMethodType,
|
|
461
|
+
path: 'nonApplePay_sync'
|
|
462
|
+
});
|
|
463
|
+
_context4.next = 36;
|
|
429
464
|
break;
|
|
430
|
-
case
|
|
431
|
-
_context4.prev =
|
|
432
|
-
_context4.t0 = _context4["catch"](
|
|
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
|
+
}
|
|
433
485
|
this.changeLoading(false);
|
|
434
|
-
this.
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
msg: safeStringify({
|
|
438
|
-
error: 'onBeforeConfirm callback error'
|
|
439
|
-
})
|
|
486
|
+
this.elementEventCenter.endEvent(startEventId, {
|
|
487
|
+
eventCode: PaymentStatus.FAIL,
|
|
488
|
+
errorName: 'MERCHANT_CONFIRM_ABORT'
|
|
440
489
|
});
|
|
441
490
|
return _context4.abrupt("return", {
|
|
442
491
|
status: PaymentStatus.FAIL,
|
|
443
492
|
error: {
|
|
444
|
-
code: '
|
|
445
|
-
message: '
|
|
493
|
+
code: 'MERCHANT_CONFIRM_ABORT',
|
|
494
|
+
message: 'Merchant canceled payment.',
|
|
446
495
|
needChangeSessionForRetry: false
|
|
447
496
|
}
|
|
448
497
|
});
|
|
449
|
-
case
|
|
498
|
+
case 36:
|
|
499
|
+
_context4.next = 39;
|
|
500
|
+
break;
|
|
501
|
+
case 38:
|
|
502
|
+
if (!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm)) {
|
|
503
|
+
this.serviceMap.Log.logInfo({
|
|
504
|
+
title: 'sdk_before_confirm_skip'
|
|
505
|
+
}, {
|
|
506
|
+
paymentMethodType: paymentMethodType,
|
|
507
|
+
path: isApplePay ? 'applePay_eventBridge' : 'nonApplePay_sync'
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
case 39:
|
|
450
511
|
recordResult = null;
|
|
451
|
-
_context4.prev =
|
|
452
|
-
_context4.next =
|
|
512
|
+
_context4.prev = 40;
|
|
513
|
+
_context4.next = 43;
|
|
453
514
|
return new Promise( /*#__PURE__*/function () {
|
|
454
515
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
455
|
-
var that, recordResultCallback, params, processStep,
|
|
516
|
+
var that, recordResultCallback, params, processStep, hasBeforeConfirmForApplePay, hasAmount, hasCurrency, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
456
517
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
457
518
|
while (1) switch (_context3.prev = _context3.next) {
|
|
458
519
|
case 0:
|
|
@@ -528,31 +589,58 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
528
589
|
return _context3.abrupt("return");
|
|
529
590
|
case 14:
|
|
530
591
|
if (!_this3.elementProcessors[ElementType.payment]) {
|
|
531
|
-
_context3.next =
|
|
592
|
+
_context3.next = 28;
|
|
532
593
|
break;
|
|
533
594
|
}
|
|
534
595
|
// Apple Pay: set onBeforeConfirm on paymentProcessor for event bridge callback after iframe authorization
|
|
535
596
|
hasBeforeConfirmForApplePay = isApplePay && !!(submitParams !== null && submitParams !== void 0 && submitParams.onBeforeConfirm);
|
|
597
|
+
_this3.serviceMap.Log.logInfo({
|
|
598
|
+
title: 'sdk_element_submitPayment_setBeforeConfirm'
|
|
599
|
+
}, {
|
|
600
|
+
msg: safeStringify({
|
|
601
|
+
hasBeforeConfirmForApplePay: hasBeforeConfirmForApplePay,
|
|
602
|
+
isApplePay: isApplePay
|
|
603
|
+
})
|
|
604
|
+
});
|
|
536
605
|
_this3.elementProcessors[ElementType.payment].setOnBeforeConfirm(hasBeforeConfirmForApplePay ? submitParams.onBeforeConfirm : null);
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
606
|
+
hasAmount = !!(submitParams !== null && submitParams !== void 0 && submitParams.amount);
|
|
607
|
+
hasCurrency = !!(submitParams !== null && submitParams !== void 0 && submitParams.currency);
|
|
608
|
+
if ((hasAmount || hasCurrency) && !(hasAmount && hasCurrency)) {
|
|
609
|
+
_this3.serviceMap.Log.logError({
|
|
610
|
+
title: 'sdk_element_submitPayment_amountCurrencyMismatch'
|
|
611
|
+
}, {
|
|
612
|
+
msg: safeStringify({
|
|
613
|
+
amount: submitParams === null || submitParams === void 0 ? void 0 : submitParams.amount,
|
|
614
|
+
currency: submitParams === null || submitParams === void 0 ? void 0 : submitParams.currency,
|
|
615
|
+
reason: 'amount and currency must be provided together, both ignored'
|
|
616
|
+
})
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
_this3.elementProcessors[ElementType.payment].setMerchantAmountOverride(hasAmount && hasCurrency ? submitParams.amount : null, hasAmount && hasCurrency ? submitParams.currency : null);
|
|
620
|
+
_context3.next = 24;
|
|
621
|
+
return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, function (_submitParams$handleA) {
|
|
622
|
+
return _objectSpread(_objectSpread(_objectSpread({}, params), {}, {
|
|
623
|
+
handleActions: (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleActions) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true,
|
|
624
|
+
shipping: submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo
|
|
625
|
+
}, hasAmount && hasCurrency ? {
|
|
626
|
+
amount: submitParams.amount,
|
|
627
|
+
currency: submitParams.currency
|
|
628
|
+
} : {}), {}, {
|
|
629
|
+
hasBeforeConfirm: hasBeforeConfirmForApplePay
|
|
630
|
+
});
|
|
631
|
+
}());
|
|
632
|
+
case 24:
|
|
545
633
|
_yield$_this3$onValid2 = _context3.sent;
|
|
546
634
|
_data = _yield$_this3$onValid2.data;
|
|
547
635
|
// TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
|
|
548
636
|
// TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
|
|
549
637
|
recordResult = _data;
|
|
550
638
|
recordResultCallback(recordResult);
|
|
551
|
-
case
|
|
552
|
-
_context3.next =
|
|
639
|
+
case 28:
|
|
640
|
+
_context3.next = 37;
|
|
553
641
|
break;
|
|
554
|
-
case
|
|
555
|
-
_context3.prev =
|
|
642
|
+
case 30:
|
|
643
|
+
_context3.prev = 30;
|
|
556
644
|
_context3.t0 = _context3["catch"](2);
|
|
557
645
|
// 修复error为{}空对象的问题,上报stack&message
|
|
558
646
|
errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
|
|
@@ -569,20 +657,20 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
569
657
|
});
|
|
570
658
|
recordResult = errorResult;
|
|
571
659
|
recordResultCallback(errorResult);
|
|
572
|
-
case
|
|
660
|
+
case 37:
|
|
573
661
|
case "end":
|
|
574
662
|
return _context3.stop();
|
|
575
663
|
}
|
|
576
|
-
}, _callee3, null, [[2,
|
|
664
|
+
}, _callee3, null, [[2, 30]]);
|
|
577
665
|
}));
|
|
578
666
|
return function (_x2) {
|
|
579
667
|
return _ref3.apply(this, arguments);
|
|
580
668
|
};
|
|
581
669
|
}());
|
|
582
|
-
case
|
|
670
|
+
case 43:
|
|
583
671
|
return _context4.abrupt("return", _context4.sent);
|
|
584
|
-
case
|
|
585
|
-
_context4.prev =
|
|
672
|
+
case 44:
|
|
673
|
+
_context4.prev = 44;
|
|
586
674
|
_logParams = {
|
|
587
675
|
eventCode: (_recordResult = recordResult) === null || _recordResult === void 0 ? void 0 : _recordResult.status,
|
|
588
676
|
errorName: (_recordResult2 = recordResult) === null || _recordResult2 === void 0 || (_recordResult2 = _recordResult2.error) === null || _recordResult2 === void 0 ? void 0 : _recordResult2.code,
|
|
@@ -593,12 +681,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
593
681
|
};
|
|
594
682
|
this.elementEventCenter.endEvent(startEventId, _logParams);
|
|
595
683
|
this.changeLoading(false);
|
|
596
|
-
return _context4.finish(
|
|
597
|
-
case
|
|
684
|
+
return _context4.finish(44);
|
|
685
|
+
case 49:
|
|
598
686
|
case "end":
|
|
599
687
|
return _context4.stop();
|
|
600
688
|
}
|
|
601
|
-
}, _callee4, this, [[
|
|
689
|
+
}, _callee4, this, [[12, 29], [14,, 18, 21], [40,, 44, 49]]);
|
|
602
690
|
}));
|
|
603
691
|
function submitPayment(_x) {
|
|
604
692
|
return _submitPayment.apply(this, arguments);
|
|
@@ -8,7 +8,10 @@ declare class PaymentProcessor extends BaseElementProcessor {
|
|
|
8
8
|
* triggered via beforeConfirm event after Apple Pay authorization in iframe.
|
|
9
9
|
*/
|
|
10
10
|
private _onBeforeConfirm;
|
|
11
|
+
private _merchantAmount;
|
|
12
|
+
private _merchantCurrency;
|
|
11
13
|
setOnBeforeConfirm(callback: (() => Promise<boolean>) | null): void;
|
|
14
|
+
setMerchantAmountOverride(amount: string | null, currency: string | null): void;
|
|
12
15
|
onReady(extraParam: any): void;
|
|
13
16
|
getLogger(): LogService;
|
|
14
17
|
private addEventListener;
|
|
@@ -62,6 +62,8 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
62
62
|
* triggered via beforeConfirm event after Apple Pay authorization in iframe.
|
|
63
63
|
*/
|
|
64
64
|
_defineProperty(_assertThisInitialized(_this), "_onBeforeConfirm", null);
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "_merchantAmount", null);
|
|
66
|
+
_defineProperty(_assertThisInitialized(_this), "_merchantCurrency", null);
|
|
65
67
|
return _this;
|
|
66
68
|
}
|
|
67
69
|
_createClass(PaymentProcessor, [{
|
|
@@ -69,6 +71,12 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
69
71
|
value: function setOnBeforeConfirm(callback) {
|
|
70
72
|
this._onBeforeConfirm = callback;
|
|
71
73
|
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "setMerchantAmountOverride",
|
|
76
|
+
value: function setMerchantAmountOverride(amount, currency) {
|
|
77
|
+
this._merchantAmount = amount;
|
|
78
|
+
this._merchantCurrency = currency;
|
|
79
|
+
}
|
|
72
80
|
}, {
|
|
73
81
|
key: "onReady",
|
|
74
82
|
value: function onReady(extraParam) {
|
|
@@ -154,7 +162,9 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
154
162
|
parseData: paymentSessionObj,
|
|
155
163
|
logger: logger,
|
|
156
164
|
env: _this2.options.env.environment,
|
|
157
|
-
shipping: shipping
|
|
165
|
+
shipping: shipping,
|
|
166
|
+
merchantAmount: _this2._merchantAmount,
|
|
167
|
+
merchantCurrency: _this2._merchantCurrency
|
|
158
168
|
});
|
|
159
169
|
applePayService.startPay().then(function (res) {
|
|
160
170
|
_this2.eventCenter.dispatchToApp({
|
|
@@ -178,14 +188,21 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
178
188
|
// requests SDK layer to execute merchant's onBeforeConfirm callback via beforeConfirm event,
|
|
179
189
|
// and returns the result (continue/abort) to iframe via dispatchToApp.
|
|
180
190
|
this.eventCenter.listen(EVENT.beforeConfirm.name, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
181
|
-
var shouldContinue;
|
|
191
|
+
var paymentMethodType, BEFORE_CONFIRM_TIMEOUT_MS, timeoutPromise, startTime, shouldContinue, isTimeout;
|
|
182
192
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
183
193
|
while (1) switch (_context.prev = _context.next) {
|
|
184
194
|
case 0:
|
|
195
|
+
paymentMethodType = 'APPLEPAY';
|
|
185
196
|
if (_this2._onBeforeConfirm) {
|
|
186
|
-
_context.next =
|
|
197
|
+
_context.next = 5;
|
|
187
198
|
break;
|
|
188
199
|
}
|
|
200
|
+
logger.logInfo({
|
|
201
|
+
title: 'sdk_before_confirm_skip'
|
|
202
|
+
}, {
|
|
203
|
+
paymentMethodType: paymentMethodType,
|
|
204
|
+
path: 'applePay_eventBridge'
|
|
205
|
+
});
|
|
189
206
|
_this2.eventCenter.dispatchToApp({
|
|
190
207
|
event: EVENT.beforeConfirm.name,
|
|
191
208
|
data: {
|
|
@@ -194,12 +211,36 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
194
211
|
}
|
|
195
212
|
});
|
|
196
213
|
return _context.abrupt("return");
|
|
197
|
-
case
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
214
|
+
case 5:
|
|
215
|
+
BEFORE_CONFIRM_TIMEOUT_MS = 15000;
|
|
216
|
+
logger.logInfo({
|
|
217
|
+
title: 'sdk_before_confirm_start'
|
|
218
|
+
}, {
|
|
219
|
+
paymentMethodType: paymentMethodType,
|
|
220
|
+
path: 'applePay_eventBridge'
|
|
221
|
+
});
|
|
222
|
+
_context.prev = 7;
|
|
223
|
+
timeoutPromise = new Promise(function (_, reject) {
|
|
224
|
+
return setTimeout(function () {
|
|
225
|
+
return reject(new Error('onBeforeConfirm timed out'));
|
|
226
|
+
}, BEFORE_CONFIRM_TIMEOUT_MS);
|
|
227
|
+
});
|
|
228
|
+
startTime = Date.now();
|
|
229
|
+
_context.next = 12;
|
|
230
|
+
return Promise.race([_this2._onBeforeConfirm(), timeoutPromise]);
|
|
231
|
+
case 12:
|
|
202
232
|
shouldContinue = _context.sent;
|
|
233
|
+
if (Date.now() - startTime >= BEFORE_CONFIRM_TIMEOUT_MS) {
|
|
234
|
+
logger.logError({
|
|
235
|
+
title: 'sdk_before_confirm_timeout'
|
|
236
|
+
});
|
|
237
|
+
shouldContinue = false;
|
|
238
|
+
}
|
|
239
|
+
logger.logInfo({
|
|
240
|
+
title: 'sdk_element_beforeConfirm_callback_result'
|
|
241
|
+
}, {
|
|
242
|
+
shouldContinue: shouldContinue
|
|
243
|
+
});
|
|
203
244
|
_this2.eventCenter.dispatchToApp({
|
|
204
245
|
event: EVENT.beforeConfirm.name,
|
|
205
246
|
data: {
|
|
@@ -207,16 +248,28 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
207
248
|
result: shouldContinue !== false
|
|
208
249
|
}
|
|
209
250
|
});
|
|
210
|
-
_context.next =
|
|
251
|
+
_context.next = 23;
|
|
211
252
|
break;
|
|
212
|
-
case
|
|
213
|
-
_context.prev =
|
|
214
|
-
_context.t0 = _context["catch"](
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
253
|
+
case 18:
|
|
254
|
+
_context.prev = 18;
|
|
255
|
+
_context.t0 = _context["catch"](7);
|
|
256
|
+
isTimeout = _context.t0 instanceof Error && _context.t0.message === 'onBeforeConfirm timed out';
|
|
257
|
+
if (isTimeout) {
|
|
258
|
+
logger.logError({
|
|
259
|
+
title: 'sdk_before_confirm_timeout'
|
|
260
|
+
}, {
|
|
261
|
+
paymentMethodType: paymentMethodType,
|
|
262
|
+
path: 'applePay_eventBridge'
|
|
263
|
+
});
|
|
264
|
+
} else {
|
|
265
|
+
logger.logError({
|
|
266
|
+
title: 'sdk_before_confirm_error'
|
|
267
|
+
}, {
|
|
268
|
+
paymentMethodType: paymentMethodType,
|
|
269
|
+
errorMessage: String((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0).slice(0, 200),
|
|
270
|
+
path: 'applePay_eventBridge'
|
|
271
|
+
});
|
|
272
|
+
}
|
|
220
273
|
_this2.eventCenter.dispatchToApp({
|
|
221
274
|
event: EVENT.beforeConfirm.name,
|
|
222
275
|
data: {
|
|
@@ -224,11 +277,11 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
|
|
|
224
277
|
result: false
|
|
225
278
|
}
|
|
226
279
|
});
|
|
227
|
-
case
|
|
280
|
+
case 23:
|
|
228
281
|
case "end":
|
|
229
282
|
return _context.stop();
|
|
230
283
|
}
|
|
231
|
-
}, _callee, null, [[
|
|
284
|
+
}, _callee, null, [[7, 18]]);
|
|
232
285
|
})));
|
|
233
286
|
}
|
|
234
287
|
}, {
|
|
@@ -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.
|
|
301
|
-
*
|
|
302
|
-
*
|
|
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
|
-
|
|
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
|
-
* -
|
|
309
|
-
* -
|
|
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
|
|
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";
|
|
@@ -34,12 +34,16 @@ export declare class ApplePaySdk {
|
|
|
34
34
|
private logger;
|
|
35
35
|
private env;
|
|
36
36
|
private shipping?;
|
|
37
|
-
|
|
37
|
+
private merchantAmount;
|
|
38
|
+
private merchantCurrency;
|
|
39
|
+
constructor({ paymentSessionData, parseData, logger, env, shipping, merchantAmount, merchantCurrency, }: {
|
|
38
40
|
paymentSessionData: string;
|
|
39
41
|
parseData: IPaymentSessionMetaData;
|
|
40
42
|
logger: Logger;
|
|
41
43
|
env?: string;
|
|
42
44
|
shipping?: CKPShipping;
|
|
45
|
+
merchantAmount?: string | null;
|
|
46
|
+
merchantCurrency?: string | null;
|
|
43
47
|
});
|
|
44
48
|
startPay(): Promise<unknown>;
|
|
45
49
|
begin(): Promise<unknown>;
|
|
@@ -137,7 +137,11 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
137
137
|
logger = _ref.logger,
|
|
138
138
|
_ref$env = _ref.env,
|
|
139
139
|
env = _ref$env === void 0 ? EnvironmentEnum.prod : _ref$env,
|
|
140
|
-
shipping = _ref.shipping
|
|
140
|
+
shipping = _ref.shipping,
|
|
141
|
+
_ref$merchantAmount = _ref.merchantAmount,
|
|
142
|
+
merchantAmount = _ref$merchantAmount === void 0 ? null : _ref$merchantAmount,
|
|
143
|
+
_ref$merchantCurrency = _ref.merchantCurrency,
|
|
144
|
+
merchantCurrency = _ref$merchantCurrency === void 0 ? null : _ref$merchantCurrency;
|
|
141
145
|
_classCallCheck(this, ApplePaySdk);
|
|
142
146
|
_defineProperty(this, "APPLESDKURL", 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js');
|
|
143
147
|
_defineProperty(this, "session", null);
|
|
@@ -150,11 +154,15 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
150
154
|
_defineProperty(this, "logger", void 0);
|
|
151
155
|
_defineProperty(this, "env", void 0);
|
|
152
156
|
_defineProperty(this, "shipping", void 0);
|
|
157
|
+
_defineProperty(this, "merchantAmount", void 0);
|
|
158
|
+
_defineProperty(this, "merchantCurrency", void 0);
|
|
153
159
|
this.paymentSessionData = paymentSessionData;
|
|
154
160
|
this.parseData = parseData;
|
|
155
161
|
this.env = env;
|
|
156
162
|
this.logger = logger;
|
|
157
163
|
this.shipping = shipping;
|
|
164
|
+
this.merchantAmount = merchantAmount;
|
|
165
|
+
this.merchantCurrency = merchantCurrency;
|
|
158
166
|
}
|
|
159
167
|
_createClass(ApplePaySdk, [{
|
|
160
168
|
key: "startPay",
|
|
@@ -337,7 +345,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
337
345
|
key: "submitPay",
|
|
338
346
|
value: function () {
|
|
339
347
|
var _submitPay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
340
|
-
var _this$parseData2;
|
|
348
|
+
var _this$parseData2, _this$parseData3, _this$parseData4;
|
|
341
349
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
342
350
|
while (1) switch (_context4.prev = _context4.next) {
|
|
343
351
|
case 0:
|
|
@@ -350,7 +358,11 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
350
358
|
paymentMethod: {
|
|
351
359
|
paymentMethodType: 'APPLEPAY'
|
|
352
360
|
},
|
|
353
|
-
shipping: this.shipping
|
|
361
|
+
shipping: this.shipping,
|
|
362
|
+
paymentAmount: {
|
|
363
|
+
value: this.merchantAmount || ((_this$parseData3 = this.parseData) === null || _this$parseData3 === void 0 || (_this$parseData3 = _this$parseData3.paymentSessionFactor) === null || _this$parseData3 === void 0 || (_this$parseData3 = _this$parseData3.paymentAmount) === null || _this$parseData3 === void 0 ? void 0 : _this$parseData3.value),
|
|
364
|
+
currency: this.merchantCurrency || ((_this$parseData4 = this.parseData) === null || _this$parseData4 === void 0 || (_this$parseData4 = _this$parseData4.paymentSessionFactor) === null || _this$parseData4 === void 0 || (_this$parseData4 = _this$parseData4.paymentAmount) === null || _this$parseData4 === void 0 ? void 0 : _this$parseData4.currency)
|
|
365
|
+
}
|
|
354
366
|
};
|
|
355
367
|
_context4.t2 = this.env;
|
|
356
368
|
_context4.next = 6;
|
|
@@ -405,7 +417,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
405
417
|
key: "initApplePaySession",
|
|
406
418
|
value: function () {
|
|
407
419
|
var _initApplePaySession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
408
|
-
var _this$logger7, _this$
|
|
420
|
+
var _this$logger7, _this$parseData5, _this$logger6, _ref4, recurringInfo, version, _this$logger8;
|
|
409
421
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
410
422
|
while (1) switch (_context5.prev = _context5.next) {
|
|
411
423
|
case 0:
|
|
@@ -440,7 +452,7 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
440
452
|
}
|
|
441
453
|
throw new Error('Apple Pay not supported');
|
|
442
454
|
case 12:
|
|
443
|
-
_ref4 = ((_this$
|
|
455
|
+
_ref4 = ((_this$parseData5 = this.parseData) === null || _this$parseData5 === void 0 ? void 0 : _this$parseData5.paymentSessionFactor) || {}, recurringInfo = _ref4.recurringInfo;
|
|
444
456
|
version = recurringInfo ? APPLE_PAY_RECURRING_VERSION : APPLE_PAY_VERSION;
|
|
445
457
|
if (this.isCanMakePayments(version)) {
|
|
446
458
|
_context5.next = 16;
|
|
@@ -487,8 +499,8 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
487
499
|
}, {
|
|
488
500
|
key: "initSessionParams",
|
|
489
501
|
get: function get() {
|
|
490
|
-
var _this$
|
|
491
|
-
var _ref5 = ((_this$
|
|
502
|
+
var _this$parseData6;
|
|
503
|
+
var _ref5 = ((_this$parseData6 = this.parseData) === null || _this$parseData6 === void 0 ? void 0 : _this$parseData6.paymentSessionFactor) || {},
|
|
492
504
|
merchantInfo = _ref5.merchantInfo,
|
|
493
505
|
order = _ref5.order,
|
|
494
506
|
paymentAmount = _ref5.paymentAmount,
|
|
@@ -496,13 +508,13 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
496
508
|
extendInfo = _ref5.extendInfo;
|
|
497
509
|
var request = {
|
|
498
510
|
countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
|
|
499
|
-
currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
|
|
511
|
+
currencyCode: this.merchantCurrency || (paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency),
|
|
500
512
|
merchantCapabilities: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities,
|
|
501
513
|
supportedNetworks: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks,
|
|
502
514
|
total: {
|
|
503
515
|
label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
|
|
504
516
|
type: 'final',
|
|
505
|
-
amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
|
|
517
|
+
amount: this.merchantAmount || (paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value)
|
|
506
518
|
},
|
|
507
519
|
requiredBillingContactFields: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.requiredBillingContactFields,
|
|
508
520
|
requiredShippingContactFields: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.requiredShippingContactFields
|
|
@@ -538,8 +550,8 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
538
550
|
}, {
|
|
539
551
|
key: "isRequiredParameters",
|
|
540
552
|
get: function get() {
|
|
541
|
-
var _this$
|
|
542
|
-
var _ref6 = ((_this$
|
|
553
|
+
var _this$parseData7;
|
|
554
|
+
var _ref6 = ((_this$parseData7 = this.parseData) === null || _this$parseData7 === void 0 ? void 0 : _this$parseData7.paymentSessionFactor) || {},
|
|
543
555
|
merchantInfo = _ref6.merchantInfo,
|
|
544
556
|
extendInfo = _ref6.extendInfo,
|
|
545
557
|
paymentAmount = _ref6.paymentAmount;
|
|
@@ -612,14 +624,14 @@ export var ApplePaySdk = /*#__PURE__*/function () {
|
|
|
612
624
|
key: "getDeviceId",
|
|
613
625
|
value: function () {
|
|
614
626
|
var _getDeviceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
615
|
-
var _yield$BusManager$pub, _this$
|
|
627
|
+
var _yield$BusManager$pub, _this$parseData8;
|
|
616
628
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
617
629
|
while (1) switch (_context6.prev = _context6.next) {
|
|
618
630
|
case 0:
|
|
619
631
|
_context6.next = 2;
|
|
620
632
|
return BusManager.publishForResult(new BusMessage(SecuritySDKActionEnum.getSecurityDeviceId, JSON.stringify({
|
|
621
633
|
deviceIdParameter: {
|
|
622
|
-
productScene: (_this$
|
|
634
|
+
productScene: (_this$parseData8 = this.parseData) === null || _this$parseData8 === void 0 || (_this$parseData8 = _this$parseData8.paymentSessionConfig) === null || _this$parseData8 === void 0 ? void 0 : _this$parseData8.productScene
|
|
623
635
|
}
|
|
624
636
|
})), {
|
|
625
637
|
fallback: ''
|