@alipay/ams-checkout 1.18.0 → 1.20.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.
@@ -0,0 +1,27 @@
1
+ import { IcreateComponent, IoptionsParams } from '../../../types';
2
+ import { Logger } from '../../../util/logger';
3
+ type LOCAL_URL = string;
4
+ export type CKPEmbeddedAppEnv = 'dev' | 'sit' | 'pre' | 'prod';
5
+ export type CKPEmbeddedEventType = 'SDK_PAYMENT_SUCCESSFUL' | 'SDK_PAYMENT_FAIL' | 'SDK_PAYMENT_CANCEL' | 'SDK_PAYMENT_CLICK_BACK_TO_MERCHANT';
6
+ export declare const getCKPPageAddress: (env: IoptionsParams['environment'] | LOCAL_URL) => string;
7
+ export declare class AMSCheckoutPage {
8
+ logger: Logger;
9
+ private _instanceId;
10
+ private originOptions;
11
+ private readonly APP_IFRAME_ID;
12
+ private eventListener?;
13
+ constructor(options: Pick<IoptionsParams, 'environment' | 'locale' | 'onEventCallback'>);
14
+ private generateIframeSrc;
15
+ private eventListenerWrapper;
16
+ private addListener;
17
+ private removeListener;
18
+ /**
19
+ * 挂载组件
20
+ */
21
+ mountComponent(params: Pick<IcreateComponent, 'sessionData'>, selector: string): Promise<void>;
22
+ /**
23
+ * 卸载组件
24
+ */
25
+ unmount(): void;
26
+ }
27
+ export {};
@@ -0,0 +1,166 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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 { v4 as uuid } from 'uuid';
9
+ import { environmentEnum } from "../../../types";
10
+ import { queryParse } from "../../../util";
11
+ import { LogConfig, Logger } from "../../../util/logger";
12
+ var CKP_PAYMENT_PAGE_HOST = {
13
+ DEV: 'https://dev.page.alipay.net',
14
+ TEST: 'https://test.page.alipay.net',
15
+ PRE: 'https://pre.ac.alipay.com',
16
+ PROD: 'https://ac.alipay.com'
17
+ };
18
+
19
+ // for local development
20
+
21
+ var CKP_PAGE_ADDRESS = '/page/antom-web-checkout-v2/checkout-page/pages/payment/index.html';
22
+ export var getCKPPageAddress = function getCKPPageAddress(env) {
23
+ switch (env) {
24
+ case 'dev':
25
+ return "".concat(CKP_PAYMENT_PAGE_HOST.DEV).concat(CKP_PAGE_ADDRESS);
26
+ case 'sit':
27
+ return "".concat(CKP_PAYMENT_PAGE_HOST.TEST).concat(CKP_PAGE_ADDRESS);
28
+ case 'pre':
29
+ return "".concat(CKP_PAYMENT_PAGE_HOST.PRE).concat(CKP_PAGE_ADDRESS);
30
+ case 'prod':
31
+ case 'sandbox':
32
+ case 'light_sandbox':
33
+ return "".concat(CKP_PAYMENT_PAGE_HOST.PROD).concat(CKP_PAGE_ADDRESS);
34
+ default:
35
+ // for local development, e.g. http://localhost:5173/checkout-page/src/pages/payment/index.html
36
+ return env;
37
+ }
38
+ };
39
+ export var AMSCheckoutPage = /*#__PURE__*/function () {
40
+ function AMSCheckoutPage(options) {
41
+ var _this = this;
42
+ _classCallCheck(this, AMSCheckoutPage);
43
+ _defineProperty(this, "logger", void 0);
44
+ _defineProperty(this, "_instanceId", void 0);
45
+ _defineProperty(this, "originOptions", void 0);
46
+ _defineProperty(this, "APP_IFRAME_ID", 'antom-checkout-page-sub-page-iframe');
47
+ _defineProperty(this, "eventListener", void 0);
48
+ _defineProperty(this, "generateIframeSrc", function (sessionData) {
49
+ var env = _this.originOptions.environment || 'prod';
50
+ var session = sessionData || '';
51
+ var lang = _this.originOptions.locale || 'en_US';
52
+ var ckpPageAddress = getCKPPageAddress(env);
53
+ console.log('[antom-web-sdk] <antom-checkout-page> generateIframeSrc', _this.originOptions, env, session, lang, ckpPageAddress);
54
+
55
+ // 先获取去除的 query 参数的 url
56
+ var url = ckpPageAddress.split('?')[0];
57
+ var queryObj = queryParse(ckpPageAddress);
58
+ queryObj.sessionData = session;
59
+ queryObj.lang = lang;
60
+ queryObj.mode = 'embed';
61
+ if (env === 'sandbox') {
62
+ queryObj.shadow = 'true';
63
+ }
64
+ Object.keys(queryObj).forEach(function (key) {
65
+ url += "".concat(url.includes('?') ? '&' : '?').concat(key, "=").concat(encodeURIComponent(queryObj[key]));
66
+ });
67
+ return url;
68
+ });
69
+ _defineProperty(this, "eventListenerWrapper", function (event) {
70
+ var _ref = JSON.parse(event.data) || {},
71
+ code = _ref.code,
72
+ message = _ref.message,
73
+ result = _ref.result;
74
+ if (code && code.startsWith('SDK_PAYMENT')) {
75
+ var _this$eventListener;
76
+ console.log('[antom-web-sdk] <antom-checkout-page> eventListenerWrapper', event, message, result);
77
+ (_this$eventListener = _this.eventListener) === null || _this$eventListener === void 0 || _this$eventListener.call(_this, {
78
+ code: code,
79
+ message: message,
80
+ result: result
81
+ });
82
+ }
83
+ });
84
+ _defineProperty(this, "addListener", function () {
85
+ window.addEventListener('message', _this.eventListenerWrapper);
86
+ });
87
+ _defineProperty(this, "removeListener", function () {
88
+ window.removeEventListener('message', _this.eventListenerWrapper);
89
+ });
90
+ options.environment = options.environment || environmentEnum.prod;
91
+ this._instanceId = uuid();
92
+ this.originOptions = options;
93
+ this.eventListener = options.onEventCallback;
94
+ this.logger = new Logger(LogConfig, ![environmentEnum.prod, environmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment));
95
+ Logger.setInstance(this.logger);
96
+ this.logger.setMedta({
97
+ instanceId: this._instanceId
98
+ });
99
+ this.logger.initTracker();
100
+ this.logger.setComponentStartTime(Date.now());
101
+ this.logger.setTrackId(this._instanceId);
102
+ this.logger.logInfo({
103
+ title: 'NEW_AMSSDK_BY_MECHANT',
104
+ msg: "".concat(options === null || options === void 0 ? void 0 : options.environment, "_").concat(options === null || options === void 0 ? void 0 : options.locale)
105
+ }).send();
106
+ }
107
+ _createClass(AMSCheckoutPage, [{
108
+ key: "mountComponent",
109
+ value:
110
+ /**
111
+ * 挂载组件
112
+ */
113
+ function mountComponent(params, selector) {
114
+ if (params.sessionData === undefined || params.sessionData === '' || typeof params.sessionData !== 'string') {
115
+ this.logger.logError({
116
+ title: 'PARAMS_ERROR_INVALID_SESSION_DATA'
117
+ });
118
+ console.error('[antom-web-sdk] <antom-checkout-page> mountComponent: sessionData is required and must be a string');
119
+ throw new Error('PARAMS_ERROR_INVALID_SESSION_DATA');
120
+ }
121
+ if (document.querySelector(this.APP_IFRAME_ID)) {
122
+ this.logger.logError({
123
+ title: 'PARAMS_ERROR_ALREADY_MOUNTED'
124
+ });
125
+ console.error('[antom-web-sdk] <antom-checkout-page> mountComponent: already mounted, please unmount first');
126
+ throw new Error('PARAMS_ERROR_ALREADY_MOUNTED');
127
+ }
128
+ this.addListener();
129
+ var ckpPageAddress = this.generateIframeSrc(params.sessionData);
130
+ var iframe = document.createElement('iframe');
131
+ iframe.id = this.APP_IFRAME_ID;
132
+ iframe.src = ckpPageAddress;
133
+ iframe.width = '100%';
134
+ iframe.height = '100%';
135
+ iframe.style.border = 'none';
136
+ var wrapper = document.querySelector(selector);
137
+ if (wrapper) {
138
+ wrapper.innerHTML = '';
139
+ wrapper.appendChild(iframe);
140
+ } else {
141
+ this.logger.logError({
142
+ title: 'PARAMS_ERROR_INVALID_SELECTOR'
143
+ });
144
+ console.error('[antom-web-sdk] <antom-checkout-page> mountComponent: invalid selector');
145
+ this.removeListener();
146
+ throw new Error('PARAMS_ERROR_INVALID_SELECTOR');
147
+ }
148
+ return Promise.resolve();
149
+ }
150
+
151
+ /**
152
+ * 卸载组件
153
+ */
154
+ }, {
155
+ key: "unmount",
156
+ value: function unmount() {
157
+ this.removeListener();
158
+ var iframe = document.getElementById(this.APP_IFRAME_ID);
159
+ if (iframe) {
160
+ iframe.remove();
161
+ }
162
+ return;
163
+ }
164
+ }]);
165
+ return AMSCheckoutPage;
166
+ }();
package/esm/index.d.ts CHANGED
@@ -6,7 +6,8 @@
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
8
  import { AMSComponent } from './core/component/index';
9
- import { IoptionsParams, componentSignEnum } from './types';
9
+ import { componentSignEnum, IoptionsParams } from './types';
10
+ export { AMSCheckoutPage } from './core/component/ckp';
10
11
  export * from './types';
11
12
  export declare class AMSCheckout extends AMSComponent {
12
13
  constructor(_options: any, channelType?: componentSignEnum[], productSceneVersion?: string);
package/esm/index.js CHANGED
@@ -21,8 +21,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
21
21
  import { AMSComponent } from "./core/component/index";
22
22
  import { componentSignEnum } from "./types";
23
23
  import { productSceneEnum } from "./types/index";
24
- import { Logger, LogConfig } from "./util/logger";
24
+ import { LogConfig, Logger } from "./util/logger";
25
25
  var logger = new Logger(LogConfig, true);
26
+ export { AMSCheckoutPage } from "./core/component/ckp";
26
27
  export * from "./types";
27
28
  export var AMSCheckout = /*#__PURE__*/function (_AMSComponent) {
28
29
  _inherits(AMSCheckout, _AMSComponent);
@@ -52,7 +52,7 @@ var getAppVersion = function getAppVersion(_extendInfo, productScene, mid) {
52
52
  }
53
53
  };
54
54
  var getFinalProductSceneVersion = function getFinalProductSceneVersion(componentSign, productSceneVersion) {
55
- var signSupportMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, componentSignEnum.NONE, ['']), componentSignEnum.AUTO_DEBIT_WALLET, ['1.0']), componentSignEnum.AUTO_DEBIT_PAY_WALLET, ['']), componentSignEnum.CASHIER_PAYMENT_BANK, ['1.0']), componentSignEnum.CASHIER_PAYMENT_CARD, ['1.0']), componentSignEnum.CASHIER_PAYMENT_APM, ['1.0']), componentSignEnum.EASY_PAY_WALLET, ['1.0', '2.0']), componentSignEnum.EASY_PAY_APM, ['2.0']), componentSignEnum.VAULTING_CARD, ['1.0']);
55
+ var signSupportMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, componentSignEnum.NONE, ['']), componentSignEnum.AUTO_DEBIT_WALLET, ['1.0']), componentSignEnum.AUTO_DEBIT_PAY_WALLET, ['']), componentSignEnum.CASHIER_PAYMENT_BANK, ['1.0']), componentSignEnum.CASHIER_PAYMENT_CARD, ['1.0']), componentSignEnum.CASHIER_PAYMENT_APM, ['1.0']), componentSignEnum.EASY_PAY_WALLET, ['1.0', '2.0']), componentSignEnum.EASY_PAY_APM, ['2.0']), componentSignEnum.VAULTING_CARD, ['1.0']), componentSignEnum.CHECKOUT_PAYMENT, ['1.0.0']);
56
56
  var supportProductSceneVersion = signSupportMap[componentSign];
57
57
  // 从左到右,从旧到新
58
58
  var isSupport = supportProductSceneVersion.find(function (it) {
@@ -57,7 +57,7 @@ var ComponentApp = /*#__PURE__*/function () {
57
57
  _defineProperty(this, "_multipleCallbackEvents", void 0);
58
58
  _defineProperty(this, "_merchantAppointParam", void 0);
59
59
  _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
60
- this._appVersion = '1.18.0';
60
+ this._appVersion = '1.19.0';
61
61
  this._isInitComponent = false;
62
62
  this._selector = "#".concat(COMPONENT_SECTION_ID);
63
63
  this.createIframeNode = function () {
@@ -49,7 +49,8 @@ export declare enum componentSignEnum {
49
49
  'AUTO_DEBIT_WALLET' = "AUTO_DEBIT_WALLET",
50
50
  'AUTO_DEBIT_PAY_WALLET' = "AUTO_DEBIT_PAY_WALLET",
51
51
  'NONE' = "NONE",
52
- 'VAULTING_CARD' = "VAULTING_CARD"
52
+ 'VAULTING_CARD' = "VAULTING_CARD",
53
+ 'CHECKOUT_PAYMENT' = "CHECKOUT_PAYMENT"
53
54
  }
54
55
  export declare enum productSceneEnum {
55
56
  'EASY_PAY' = "EASY_PAY",
@@ -58,7 +59,8 @@ export declare enum productSceneEnum {
58
59
  'AUTO_DEBIT_PAY' = "AUTO_DEBIT_PAY",
59
60
  'VAULTING' = "VAULTING",
60
61
  'FLASH_BUY' = "FLASH_BUY",
61
- 'CARD_APPLE_PAY' = "CARD_APPLE_PAY"
62
+ 'CARD_APPLE_PAY' = "CARD_APPLE_PAY",
63
+ 'CHECKOUT_PAYMENT' = "CHECKOUT_PAYMENT"
62
64
  }
63
65
  export declare enum paymentMethodCategoryTypeEnum {
64
66
  'CARD' = "CARD",
@@ -25,6 +25,7 @@ export var componentSignEnum = /*#__PURE__*/function (componentSignEnum) {
25
25
  componentSignEnum["AUTO_DEBIT_PAY_WALLET"] = "AUTO_DEBIT_PAY_WALLET";
26
26
  componentSignEnum["NONE"] = "NONE";
27
27
  componentSignEnum["VAULTING_CARD"] = "VAULTING_CARD";
28
+ componentSignEnum["CHECKOUT_PAYMENT"] = "CHECKOUT_PAYMENT";
28
29
  return componentSignEnum;
29
30
  }({});
30
31
  export var productSceneEnum = /*#__PURE__*/function (productSceneEnum) {
@@ -35,6 +36,7 @@ export var productSceneEnum = /*#__PURE__*/function (productSceneEnum) {
35
36
  productSceneEnum["VAULTING"] = "VAULTING";
36
37
  productSceneEnum["FLASH_BUY"] = "FLASH_BUY";
37
38
  productSceneEnum["CARD_APPLE_PAY"] = "CARD_APPLE_PAY";
39
+ productSceneEnum["CHECKOUT_PAYMENT"] = "CHECKOUT_PAYMENT";
38
40
  return productSceneEnum;
39
41
  }({});
40
42
  export var paymentMethodCategoryTypeEnum = /*#__PURE__*/function (paymentMethodCategoryTypeEnum) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "1.18.0",
3
+ "version": "1.20.0",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",