@alipay/ams-checkout 2.0.16 → 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.
- package/ams-checkout.js +3 -3
- package/dist/ams-checkout.min.js +1 -1
- package/esm/component/popupWindow.style.js +2 -1
- package/esm/constant/index.d.ts +4 -0
- package/esm/constant/index.js +5 -0
- package/esm/core/component/element/elementContainerService/containerService.js +3 -2
- package/esm/core/component/element/elementController/index.d.ts +2 -0
- package/esm/core/component/element/elementController/index.js +163 -24
- package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +10 -0
- package/esm/core/component/element/elementProcessor/paymentProcessor.js +152 -36
- package/esm/core/component/element/type.d.ts +20 -0
- package/esm/foundation/service/container/utils.js +3 -1
- package/esm/modern/index.js +1 -1
- package/esm/plugin/component/channel.d.ts +12 -1
- package/esm/plugin/component/channel.js +132 -27
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/types/index.d.ts +2 -7
- package/esm/util/beforeConfirm.d.ts +12 -0
- package/esm/util/beforeConfirm.js +68 -0
- package/esm/util/spm-map.d.ts +6 -0
- package/esm/util/spm-map.js +7 -1
- package/package.json +1 -1
- package/types.d.ts +18 -19
- package/types.untrimmed.d.ts +24 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AMSPOPUP_PREFIX, ANIMATION_TIME, MOCKUP_ID, POPUPLOADING_ID } from "../constant";
|
|
1
|
+
import { AMSPOPUP_PREFIX, ANIMATION_TIME, DEFAULT_IFRAME_COLOR_SCHEME, MOCKUP_ID, POPUPLOADING_ID } from "../constant";
|
|
2
2
|
import { getDesignFontSize } from "../util";
|
|
3
3
|
// CSS样式字符串
|
|
4
4
|
var modalStyles = "\n .".concat(AMSPOPUP_PREFIX, "modal {\n /* \u6DFB\u52A0\u5F39\u7A97\u6837\u5F0F */\n background-color: #fff;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 9999; /* \u8BBE\u7F6E\u5F39\u7A97\u7684\u5C42\u7EA7\u4E3A 9999 */\n overflow: hidden;\n }\n .").concat(AMSPOPUP_PREFIX, "modal-mobile{\n background-color: #fff;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);\n position: fixed;\n bottom: 0;\n left: 0%;\n z-index: 9999; /* \u8BBE\u7F6E\u5F39\u7A97\u7684\u5C42\u7EA7\u4E3A 9999 */\n overflow: hidden;\n }\n\n .").concat(AMSPOPUP_PREFIX, "overlay {\n /* \u6DFB\u52A0\u8499\u5C42\u6837\u5F0F */\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.4);\n z-index: 999;\n }\n\n .").concat(AMSPOPUP_PREFIX, "fadeIn {\n /* \u6DFB\u52A0\u6DE1\u5165\u52A8\u753B */\n animation: fadeIn ").concat(ANIMATION_TIME, "ms;\n animation-fill-mode: forwards;\n }\n\n .").concat(AMSPOPUP_PREFIX, "fadeOut {\n /* \u6DFB\u52A0\u6DE1\u51FA\u52A8\u753B */\n animation: fadeOut ").concat(ANIMATION_TIME, "ms;\n animation-fill-mode: forwards;\n }\n\n .").concat(AMSPOPUP_PREFIX, "-drawer-enter {\n animation: slideIn ").concat(ANIMATION_TIME, "ms forwards;\n }\n\n @keyframes slideIn {\n from {\n transform: translateY(100%); /* \u6ED1\u5165\u65F6\u5728\u89C6\u53E3\u5E95\u90E8\u5916 */\n opacity: 0; /* \u521D\u59CB\u900F\u660E\u5EA6\u4E3A 0 */\n }\n to {\n transform: translateY(0); /* \u6ED1\u5165\u7ED3\u675F\u65F6\u5728\u539F\u4F4D\u7F6E */\n opacity: 1; /* \u7ED3\u675F\u65F6\u900F\u660E\u5EA6\u4E3A 1 */\n }\n }\n\n /* \u62BD\u5C49\u4ECE\u5E95\u90E8\u6ED1\u51FA */\n .").concat(AMSPOPUP_PREFIX, "-drawer-exit {\n animation: slideOut ").concat(ANIMATION_TIME, "ms forwards;\n }\n\n @keyframes slideOut {\n from {\n transform: translateY(0); /* \u6ED1\u51FA\u65F6\u4ECE\u5F53\u524D\u4F4D\u7F6E\u5F00\u59CB */\n opacity: 1; /* \u521D\u59CB\u900F\u660E\u5EA6\u4E3A 1 */\n }\n to {\n transform: translateY(100%); /* \u6ED1\u51FA\u7ED3\u675F\u65F6\u5728\u89C6\u53E3\u5E95\u90E8\u5916 */\n opacity: 0; /* \u7ED3\u675F\u65F6\u900F\u660E\u5EA6\u4E3A 0 */\n }\n }\n\n /* \u5B9A\u4E49\u6DE1\u5165\u52A8\u753B */\n @keyframes fadeIn {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n\n @-webkit-keyframes fadeIn {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n\n @-moz-keyframes fadeIn {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n\n /* \u5B9A\u4E49\u6DE1\u51FA\u52A8\u753B */\n @keyframes fadeOut {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n\n @-webkit-keyframes fadeOut {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n\n @-moz-keyframes fadeOut {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n\n\n.ams-component-popup-loading {\n width: 0.8em;\n height:0.8em;\n border-radius: 8px;\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 1001;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n}\n\n.ams-component-popup-loading .line {\n width: 40px;\n height: 40px;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}\n.ams-component-popup-loading .line div {\n position: absolute;\n left: 17.67px;\n top: 0;\n width: 5.33px;\n height: 40px;\n}\n\n.ams-component-popup-loading .line div:before,\n.ams-component-popup-loading .line div:after {\n content: '';\n display: block;\n height: 13.33px;\n background: black;\n border-radius: 5.3px;\n}\n.ams-component-popup-loading .line div:after {\n margin-top: 13.33px;\n}\n\n.ams-component-popup-loading .line div:nth-child(2) {\n -webkit-transform: rotate(45deg);\n}\n\n.ams-component-popup-loading .line div:nth-child(3) {\n -webkit-transform: rotate(90deg);\n}\n\n.ams-component-popup-loading .line div:nth-child(4) {\n -webkit-transform: rotate(135deg);\n}\n\n/** \u52A0\u8F7D\u52A8\u753B **/\n@-webkit-keyframes load {\n 0% {\n opacity: 0;\n }\n\n 100% {\n opacity: 1;\n }\n}\n\n.ams-component-popup-loading .line div:nth-child(1):before {\n -webkit-animation: load 1s linear 0s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(2):before {\n -webkit-animation: load 1s linear 0.125s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(3):before {\n -webkit-animation: load 1s linear 0.25s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(4):before {\n -webkit-animation: load 1s linear 0.375s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(1):after {\n -webkit-animation: load 1s linear 0.5s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(2):after {\n -webkit-animation: load 1s linear 0.675s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(3):after {\n -webkit-animation: load 1s linear 0.75s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(4):after {\n -webkit-animation: load 1s linear 0.875s infinite;\n}\n\n.ams-component-popup-loading-logo {\n width: 0.44em;\n height: 0.44em;\n -webkit-transform:rotate(360deg);\n transform:rotate(360deg);\n -webkit-transition:-webkit-transform 1s linear;\n transition:transform 1s linear;\n animation: ams-component-loading-logo 1s linear infinite;\n}\n");
|
|
@@ -111,6 +111,7 @@ export var createModal = function createModal(_ref2) {
|
|
|
111
111
|
iframe.style.border = 'none';
|
|
112
112
|
iframe.style.width = '100%';
|
|
113
113
|
iframe.style.height = '100%';
|
|
114
|
+
iframe.style.colorScheme = DEFAULT_IFRAME_COLOR_SCHEME;
|
|
114
115
|
if (styleConfig) {
|
|
115
116
|
modal.style.backgroundColor = styleConfig.backgroundColor;
|
|
116
117
|
iframe.style.backgroundColor = styleConfig.backgroundColor;
|
package/esm/constant/index.d.ts
CHANGED
|
@@ -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;
|
|
@@ -310,6 +313,7 @@ export declare const LISTENER_PREFIX = "_ams_sdk_component_listener";
|
|
|
310
313
|
export declare const INLINE_BASE_STYLE_ID = "ams-inline-component-style";
|
|
311
314
|
export declare const INLINE_IMG_CLASSNAME = "inline-loading";
|
|
312
315
|
export declare const AMSPOPUP_PREFIX = "ams-popup";
|
|
316
|
+
export declare const DEFAULT_IFRAME_COLOR_SCHEME = "light dark";
|
|
313
317
|
export declare const LOADTIME_LIMIT = 15000;
|
|
314
318
|
export declare const POPUP_LOADTIME_LOG_LIMIT = 3000;
|
|
315
319
|
export declare const ANIMATION_TIME = 300;
|
package/esm/constant/index.js
CHANGED
|
@@ -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',
|
|
@@ -318,6 +322,7 @@ export var LISTENER_PREFIX = '_ams_sdk_component_listener';
|
|
|
318
322
|
export var INLINE_BASE_STYLE_ID = 'ams-inline-component-style';
|
|
319
323
|
export var INLINE_IMG_CLASSNAME = 'inline-loading';
|
|
320
324
|
export var AMSPOPUP_PREFIX = 'ams-popup';
|
|
325
|
+
export var DEFAULT_IFRAME_COLOR_SCHEME = 'light dark';
|
|
321
326
|
export var LOADTIME_LIMIT = 15000;
|
|
322
327
|
export var POPUP_LOADTIME_LOG_LIMIT = 3000;
|
|
323
328
|
export var ANIMATION_TIME = 300;
|
|
@@ -5,7 +5,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
import { EVENT } from "../../../../constant";
|
|
8
|
+
import { EVENT, DEFAULT_IFRAME_COLOR_SCHEME } from "../../../../constant";
|
|
9
9
|
import { ServiceProvider } from "./../../../../foundation/service";
|
|
10
10
|
import { isElementPC, isElementPad } from "../util";
|
|
11
11
|
import { DisplayTypeEnum, PlatformEnum, ProductSceneEnum } from "./../../../../types";
|
|
@@ -49,7 +49,8 @@ export var ContainerController = /*#__PURE__*/function () {
|
|
|
49
49
|
selector: selector,
|
|
50
50
|
appendAliasContainerId: true,
|
|
51
51
|
iframeStyle: {
|
|
52
|
-
display: 'block'
|
|
52
|
+
display: 'block',
|
|
53
|
+
colorScheme: DEFAULT_IFRAME_COLOR_SCHEME
|
|
53
54
|
}
|
|
54
55
|
}, processor.generateIframeSrc({
|
|
55
56
|
link: iframesSrcLink,
|
|
@@ -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 =
|
|
402
|
-
_context4.next =
|
|
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,
|
|
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 =
|
|
585
|
+
_context3.next = 28;
|
|
482
586
|
break;
|
|
483
587
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
|
|
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
|
|
497
|
-
_context3.next =
|
|
632
|
+
case 28:
|
|
633
|
+
_context3.next = 37;
|
|
498
634
|
break;
|
|
499
|
-
case
|
|
500
|
-
_context3.prev =
|
|
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
|
|
653
|
+
case 37:
|
|
518
654
|
case "end":
|
|
519
655
|
return _context3.stop();
|
|
520
656
|
}
|
|
521
|
-
}, _callee3, null, [[2,
|
|
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
|
|
663
|
+
case 39:
|
|
528
664
|
return _context4.abrupt("return", _context4.sent);
|
|
529
|
-
case
|
|
530
|
-
_context4.prev =
|
|
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(
|
|
542
|
-
case
|
|
677
|
+
return _context4.finish(40);
|
|
678
|
+
case 45:
|
|
543
679
|
case "end":
|
|
544
680
|
return _context4.stop();
|
|
545
681
|
}
|
|
546
|
-
}, _callee4, this, [[
|
|
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;
|