@alipay/ams-checkout 0.0.1766729653-dev.1 → 0.0.1766976687-dev.0
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/umd/ams-checkout.min.js +1 -1
- package/esm/core/component/element/config.d.ts +10 -0
- package/esm/core/component/element/config.js +17 -0
- package/esm/core/component/element/elementController/index.d.ts +4 -2
- package/esm/core/component/element/elementController/index.js +47 -20
- package/esm/core/component/element/index.d.ts +3 -2
- package/esm/core/component/element/index.js +7 -2
- package/esm/core/component/element/type.d.ts +38 -3
- package/esm/core/component/element/type.js +8 -1
- package/esm/core/component/element/util.d.ts +1 -0
- package/esm/core/component/element/util.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare enum ProductScene {
|
|
2
|
+
EXPRESS_CHECKOUT = "EXPRESS_CHECKOUT",
|
|
3
|
+
ELEMENT_PAYMENT = "ELEMENT_PAYMENT"
|
|
4
|
+
}
|
|
5
|
+
interface EventScenario {
|
|
6
|
+
eventName: ProductScene;
|
|
7
|
+
supportedEvents: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const productEventScenarios: EventScenario[];
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// 定义产品场景的枚举
|
|
2
|
+
export var ProductScene = /*#__PURE__*/function (ProductScene) {
|
|
3
|
+
ProductScene["EXPRESS_CHECKOUT"] = "EXPRESS_CHECKOUT";
|
|
4
|
+
ProductScene["ELEMENT_PAYMENT"] = "ELEMENT_PAYMENT";
|
|
5
|
+
return ProductScene;
|
|
6
|
+
}({});
|
|
7
|
+
|
|
8
|
+
// 定义一个事件场景的接口
|
|
9
|
+
|
|
10
|
+
// 存储产品场景及支持的事件名
|
|
11
|
+
export var productEventScenarios = [{
|
|
12
|
+
eventName: ProductScene.EXPRESS_CHECKOUT,
|
|
13
|
+
supportedEvents: [] // 没有支持的事件
|
|
14
|
+
}, {
|
|
15
|
+
eventName: ProductScene.ELEMENT_PAYMENT,
|
|
16
|
+
supportedEvents: ['paymentMethodChanged', 'valuesChanged'] // 支持的事件
|
|
17
|
+
}];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddressMountOptions, ICommonApiResponse, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions } from '../type';
|
|
1
|
+
import { AddressMountOptions, EventDataMap, EVENTNAME, ICommonApiResponse, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions, SubmitFuncParams } from '../type';
|
|
2
2
|
declare class ElementController {
|
|
3
3
|
private options;
|
|
4
4
|
private elementContainer;
|
|
@@ -33,7 +33,7 @@ declare class ElementController {
|
|
|
33
33
|
validateFields(): Promise<{
|
|
34
34
|
isValid: boolean;
|
|
35
35
|
}>;
|
|
36
|
-
submitPayment(): Promise<IPaymentApiResponse>;
|
|
36
|
+
submitPayment(submitParams: SubmitFuncParams): Promise<IPaymentApiResponse>;
|
|
37
37
|
private changeLoading;
|
|
38
38
|
private addEventListener;
|
|
39
39
|
private sendRequestAndWaitWebLaunch;
|
|
@@ -44,5 +44,7 @@ declare class ElementController {
|
|
|
44
44
|
private destroyHandle;
|
|
45
45
|
destroy(): void;
|
|
46
46
|
private setControllerStatusOrView;
|
|
47
|
+
on<T extends EVENTNAME>(event: T, callback: (data: EventDataMap[T]) => void): void;
|
|
48
|
+
private isEventAllowed;
|
|
47
49
|
}
|
|
48
50
|
export default ElementController;
|
|
@@ -40,8 +40,9 @@ import { IContainerStatus } from "../elementContainerService/containerService";
|
|
|
40
40
|
import { EventCenter as ElementEventCenter } from "../EventCenter/index";
|
|
41
41
|
import { oneAccountUpdate, sdkActionUpdate } from "../mock";
|
|
42
42
|
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
|
|
43
|
-
import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeStringify, showToast } from "../util";
|
|
43
|
+
import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeParse, safeStringify, showToast } from "../util";
|
|
44
44
|
import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
|
|
45
|
+
import { productEventScenarios, ProductScene } from "../config";
|
|
45
46
|
var TIMEOUT_DURATION = 10000;
|
|
46
47
|
var ElementController = /*#__PURE__*/function () {
|
|
47
48
|
function ElementController(options) {
|
|
@@ -337,7 +338,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
337
338
|
}, {
|
|
338
339
|
key: "submitPayment",
|
|
339
340
|
value: function () {
|
|
340
|
-
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
341
|
+
var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
|
|
341
342
|
var _this3 = this;
|
|
342
343
|
var startEventId, res, logParams, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
|
|
343
344
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
@@ -369,7 +370,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
369
370
|
_context4.next = 11;
|
|
370
371
|
return new Promise( /*#__PURE__*/function () {
|
|
371
372
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
372
|
-
var that, recordResultCallback, params, processStep, _yield$_this3$onValid2,
|
|
373
|
+
var that, recordResultCallback, params, processStep, _submitParams$handleA, _yield$_this3$onValid2, _data, errorString, errorResult;
|
|
373
374
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
374
375
|
while (1) switch (_context3.prev = _context3.next) {
|
|
375
376
|
case 0:
|
|
@@ -422,7 +423,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
422
423
|
}
|
|
423
424
|
}, _callee2);
|
|
424
425
|
}));
|
|
425
|
-
return function processStep(
|
|
426
|
+
return function processStep(_x3, _x4) {
|
|
426
427
|
return _ref4.apply(this, arguments);
|
|
427
428
|
};
|
|
428
429
|
}(); // 按顺序处理步骤
|
|
@@ -445,23 +446,25 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
445
446
|
return _context3.abrupt("return");
|
|
446
447
|
case 14:
|
|
447
448
|
if (!_this3.elementProcessors[ElementType.payment]) {
|
|
448
|
-
_context3.next =
|
|
449
|
+
_context3.next = 23;
|
|
449
450
|
break;
|
|
450
451
|
}
|
|
451
|
-
|
|
452
|
+
params.handleAction = (_submitParams$handleA = submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleAction) !== null && _submitParams$handleA !== void 0 ? _submitParams$handleA : true;
|
|
453
|
+
params.shipping = submitParams === null || submitParams === void 0 ? void 0 : submitParams.shippingInfo;
|
|
454
|
+
_context3.next = 19;
|
|
452
455
|
return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, params);
|
|
453
|
-
case
|
|
456
|
+
case 19:
|
|
454
457
|
_yield$_this3$onValid2 = _context3.sent;
|
|
455
|
-
|
|
458
|
+
_data = _yield$_this3$onValid2.data;
|
|
456
459
|
// TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
|
|
457
460
|
// TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
|
|
458
|
-
recordResult =
|
|
461
|
+
recordResult = _data;
|
|
459
462
|
recordResultCallback(recordResult);
|
|
460
|
-
case 21:
|
|
461
|
-
_context3.next = 30;
|
|
462
|
-
break;
|
|
463
463
|
case 23:
|
|
464
|
-
_context3.
|
|
464
|
+
_context3.next = 32;
|
|
465
|
+
break;
|
|
466
|
+
case 25:
|
|
467
|
+
_context3.prev = 25;
|
|
465
468
|
_context3.t0 = _context3["catch"](2);
|
|
466
469
|
// 修复error为{}空对象的问题,上报stack&message
|
|
467
470
|
errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
|
|
@@ -478,13 +481,13 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
478
481
|
});
|
|
479
482
|
recordResult = errorResult;
|
|
480
483
|
recordResultCallback(errorResult);
|
|
481
|
-
case
|
|
484
|
+
case 32:
|
|
482
485
|
case "end":
|
|
483
486
|
return _context3.stop();
|
|
484
487
|
}
|
|
485
|
-
}, _callee3, null, [[2,
|
|
488
|
+
}, _callee3, null, [[2, 25]]);
|
|
486
489
|
}));
|
|
487
|
-
return function (
|
|
490
|
+
return function (_x2) {
|
|
488
491
|
return _ref3.apply(this, arguments);
|
|
489
492
|
};
|
|
490
493
|
}());
|
|
@@ -509,7 +512,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
509
512
|
}
|
|
510
513
|
}, _callee4, this, [[8,, 12, 17]]);
|
|
511
514
|
}));
|
|
512
|
-
function submitPayment() {
|
|
515
|
+
function submitPayment(_x) {
|
|
513
516
|
return _submitPayment.apply(this, arguments);
|
|
514
517
|
}
|
|
515
518
|
return submitPayment;
|
|
@@ -654,7 +657,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
654
657
|
}
|
|
655
658
|
}, _callee5, this, [[1, 20]]);
|
|
656
659
|
}));
|
|
657
|
-
function sendRequestAndWaitWebLaunch(
|
|
660
|
+
function sendRequestAndWaitWebLaunch(_x5, _x6) {
|
|
658
661
|
return _sendRequestAndWaitWebLaunch.apply(this, arguments);
|
|
659
662
|
}
|
|
660
663
|
return sendRequestAndWaitWebLaunch;
|
|
@@ -787,7 +790,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
787
790
|
}
|
|
788
791
|
}, _callee6);
|
|
789
792
|
}));
|
|
790
|
-
return function (
|
|
793
|
+
return function (_x8) {
|
|
791
794
|
return _ref5.apply(this, arguments);
|
|
792
795
|
};
|
|
793
796
|
}()));
|
|
@@ -797,7 +800,7 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
797
800
|
}
|
|
798
801
|
}, _callee7);
|
|
799
802
|
}));
|
|
800
|
-
function updatePayment(
|
|
803
|
+
function updatePayment(_x7) {
|
|
801
804
|
return _updatePayment.apply(this, arguments);
|
|
802
805
|
}
|
|
803
806
|
return updatePayment;
|
|
@@ -834,6 +837,30 @@ var ElementController = /*#__PURE__*/function () {
|
|
|
834
837
|
(_this$onStatusChangeC = this.onStatusChangeCallback) === null || _this$onStatusChangeC === void 0 || _this$onStatusChangeC.call(this, "\u72B6\u6001\u7531 ".concat(_status, " \u53D8\u66F4\u4E3A ").concat(status));
|
|
835
838
|
this.elementContainer.setStatus(status);
|
|
836
839
|
}
|
|
840
|
+
}, {
|
|
841
|
+
key: "on",
|
|
842
|
+
value: function on(event, callback) {
|
|
843
|
+
if (!this.isEventAllowed(event)) {
|
|
844
|
+
return console.error("Event \"".concat(event, "\" is not allowed."));
|
|
845
|
+
}
|
|
846
|
+
this.serviceMap.EventCenter.listen(event, function (data) {
|
|
847
|
+
callback === null || callback === void 0 || callback(data);
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
}, {
|
|
851
|
+
key: "isEventAllowed",
|
|
852
|
+
value: function isEventAllowed(event) {
|
|
853
|
+
var _safeParse, _this$elementContaine;
|
|
854
|
+
// 获取当前场景
|
|
855
|
+
var isExpressCheckout = (_safeParse = safeParse((_this$elementContaine = this.elementContainer.getPaymentContext()) === null || _this$elementContaine === void 0 || (_this$elementContaine = _this$elementContaine.paymentSessionObj) === null || _this$elementContaine === void 0 ? void 0 : _this$elementContaine.extendInfo)) === null || _safeParse === void 0 ? void 0 : _safeParse.expressCheckout;
|
|
856
|
+
var productScene = isExpressCheckout ? ProductScene.EXPRESS_CHECKOUT : ProductScene.ELEMENT_PAYMENT;
|
|
857
|
+
// 查找对应的产品场景
|
|
858
|
+
var scenario = productEventScenarios.find(function (s) {
|
|
859
|
+
return s.eventName === productScene;
|
|
860
|
+
});
|
|
861
|
+
// 检查场景存在且事件名称在支持的事件列表中
|
|
862
|
+
return scenario !== undefined && scenario.supportedEvents.includes(event);
|
|
863
|
+
}
|
|
837
864
|
}]);
|
|
838
865
|
return ElementController;
|
|
839
866
|
}();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IElementOptions, PaymentMountOptions } from './type';
|
|
1
|
+
import { EventDataMap, EVENTNAME, IElementOptions, PaymentMountOptions, SubmitFuncParams } from './type';
|
|
2
2
|
export declare class ElementComponent {
|
|
3
3
|
private options;
|
|
4
4
|
private controller;
|
|
@@ -8,6 +8,7 @@ export declare class ElementComponent {
|
|
|
8
8
|
validateFields(): Promise<{
|
|
9
9
|
isValid: boolean;
|
|
10
10
|
}>;
|
|
11
|
-
submitPayment(): Promise<import("./type").IPaymentApiResponse>;
|
|
11
|
+
submitPayment(params: SubmitFuncParams): Promise<import("./type").IPaymentApiResponse>;
|
|
12
12
|
destroy(): void;
|
|
13
|
+
on<T extends EVENTNAME>(event: T, callback: (data: EventDataMap[T]) => void): void;
|
|
13
14
|
}
|
|
@@ -62,14 +62,19 @@ export var ElementComponent = /*#__PURE__*/function () {
|
|
|
62
62
|
}
|
|
63
63
|
}, {
|
|
64
64
|
key: "submitPayment",
|
|
65
|
-
value: function submitPayment() {
|
|
66
|
-
return this.controller.submitPayment();
|
|
65
|
+
value: function submitPayment(params) {
|
|
66
|
+
return this.controller.submitPayment(params);
|
|
67
67
|
}
|
|
68
68
|
}, {
|
|
69
69
|
key: "destroy",
|
|
70
70
|
value: function destroy() {
|
|
71
71
|
this.controller.destroy();
|
|
72
72
|
}
|
|
73
|
+
}, {
|
|
74
|
+
key: "on",
|
|
75
|
+
value: function on(event, callback) {
|
|
76
|
+
this.controller.on(event, callback);
|
|
77
|
+
}
|
|
73
78
|
}]);
|
|
74
79
|
return ElementComponent;
|
|
75
80
|
}();
|
|
@@ -183,9 +183,6 @@ export interface PaymentMountOptions extends BaseMountOptions {
|
|
|
183
183
|
card?: {
|
|
184
184
|
showBrandIcon?: boolean;
|
|
185
185
|
};
|
|
186
|
-
accordion?: {
|
|
187
|
-
showRadio?: boolean;
|
|
188
|
-
};
|
|
189
186
|
};
|
|
190
187
|
notRedirectAfterComplete?: boolean;
|
|
191
188
|
merchantAppointParam?: IMerchantAppointParam;
|
|
@@ -264,9 +261,21 @@ export interface AddressSubmitData {
|
|
|
264
261
|
shippingId: string;
|
|
265
262
|
actionFlag?: 'I' | 'U' | 'D';
|
|
266
263
|
}
|
|
264
|
+
export interface HandleAction {
|
|
265
|
+
threeD?: boolean;
|
|
266
|
+
callApp?: boolean;
|
|
267
|
+
pageRedirect?: boolean;
|
|
268
|
+
qrCode?: boolean;
|
|
269
|
+
}
|
|
270
|
+
export type HandleActionType = boolean | HandleAction;
|
|
271
|
+
export interface SubmitFuncParams {
|
|
272
|
+
shippingInfo?: AddressSubmitData;
|
|
273
|
+
handleAction?: HandleActionType;
|
|
274
|
+
}
|
|
267
275
|
export interface SubmitServiceParams extends PaymentSubmitData {
|
|
268
276
|
accountInfo: AuthSubmitData['accountInfo'];
|
|
269
277
|
shipping?: AddressSubmitData;
|
|
278
|
+
handleAction?: HandleActionType;
|
|
270
279
|
}
|
|
271
280
|
interface SubmitResultActionForm extends ActionForm {
|
|
272
281
|
paymentCodeExpireTime: string;
|
|
@@ -446,4 +455,30 @@ export declare enum EXPOSURE_API_EVENT {
|
|
|
446
455
|
VALIDATAFIELDS = "validateFields",
|
|
447
456
|
UPDATEPAYMENT = "updatePayment"
|
|
448
457
|
}
|
|
458
|
+
export declare enum EVENTNAME {
|
|
459
|
+
PAYMENTMETHODCHANGED = "paymentMethodChanged",
|
|
460
|
+
VALUESCHANGED = "valuesChanged"
|
|
461
|
+
}
|
|
462
|
+
interface PaymentMethodChangedData {
|
|
463
|
+
type: string;
|
|
464
|
+
name: string;
|
|
465
|
+
}
|
|
466
|
+
interface ValuesChangedData {
|
|
467
|
+
region: string;
|
|
468
|
+
state: string;
|
|
469
|
+
city: string;
|
|
470
|
+
address1: string;
|
|
471
|
+
address2: string;
|
|
472
|
+
zipCode: string;
|
|
473
|
+
phoneNo: string;
|
|
474
|
+
name: {
|
|
475
|
+
firstName: string;
|
|
476
|
+
lastName: string;
|
|
477
|
+
middleName: string;
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
export interface EventDataMap {
|
|
481
|
+
[EVENTNAME.PAYMENTMETHODCHANGED]: PaymentMethodChangedData;
|
|
482
|
+
[EVENTNAME.VALUESCHANGED]: ValuesChangedData;
|
|
483
|
+
}
|
|
449
484
|
export {};
|
|
@@ -147,4 +147,11 @@ export var EXPOSURE_API_EVENT = /*#__PURE__*/function (EXPOSURE_API_EVENT) {
|
|
|
147
147
|
EXPOSURE_API_EVENT["VALIDATAFIELDS"] = "validateFields";
|
|
148
148
|
EXPOSURE_API_EVENT["UPDATEPAYMENT"] = "updatePayment";
|
|
149
149
|
return EXPOSURE_API_EVENT;
|
|
150
|
-
}({});
|
|
150
|
+
}({});
|
|
151
|
+
export var EVENTNAME = /*#__PURE__*/function (EVENTNAME) {
|
|
152
|
+
EVENTNAME["PAYMENTMETHODCHANGED"] = "paymentMethodChanged";
|
|
153
|
+
EVENTNAME["VALUESCHANGED"] = "valuesChanged";
|
|
154
|
+
return EVENTNAME;
|
|
155
|
+
}({});
|
|
156
|
+
|
|
157
|
+
// 支付方式改变的回调函数的数据结构
|
|
@@ -83,3 +83,4 @@ export declare const isElementPC: () => boolean;
|
|
|
83
83
|
*/
|
|
84
84
|
export declare const isLoadErrorPage: (params: CashierSdkActionQueryResult) => boolean;
|
|
85
85
|
export declare const safeStringify: (payload: any, defaultValue?: string) => string;
|
|
86
|
+
export declare const safeParse: (payload: any, defaultValue?: Record<string, any>) => Record<string, any>;
|
|
@@ -535,4 +535,14 @@ export var safeStringify = function safeStringify(payload) {
|
|
|
535
535
|
console.error('JSON.stringify failed:', e);
|
|
536
536
|
return defaultValue;
|
|
537
537
|
}
|
|
538
|
+
};
|
|
539
|
+
export var safeParse = function safeParse(payload) {
|
|
540
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
541
|
+
if (!payload) return defaultValue;
|
|
542
|
+
try {
|
|
543
|
+
return JSON.parse(payload) || defaultValue;
|
|
544
|
+
} catch (e) {
|
|
545
|
+
console.error('JSON.parse failed:', e);
|
|
546
|
+
return defaultValue;
|
|
547
|
+
}
|
|
538
548
|
};
|