@alipay/ams-checkout 0.0.1746673215-dev.1 → 0.0.1746674797-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.
@@ -1,4 +1,4 @@
1
- import { DisplayTypeEnum, PaymentMethodCategoryTypeEnum } from '../../types';
1
+ import { DisplayTypeEnum, PaymentMethodCategoryTypeEnum, ProductSceneEnum } from '../../types';
2
2
  import { SDKMetaData } from '../index';
3
3
  /**
4
4
  * Tell the SDK which version of the Web App to load.
@@ -16,6 +16,15 @@ export interface WebAppMatchConfig {
16
16
  mid?: string;
17
17
  greyscale?: string;
18
18
  }
19
+ /**
20
+ * Tell the SDK which Web App URL to load.
21
+ * Sent by server inside paymentSession.
22
+ */
23
+ export interface WebAppUrlMatchConfig {
24
+ version: string;
25
+ url: string;
26
+ mid?: string;
27
+ }
19
28
  export interface QueryParams {
20
29
  displayType: DisplayTypeEnum;
21
30
  locale: string;
@@ -27,20 +36,56 @@ export interface QueryParams {
27
36
  export declare const getWebAppUrlInfo: (params: {
28
37
  environment: string;
29
38
  sdkMetaData: SDKMetaData;
39
+ productScene: ProductSceneEnum;
30
40
  productSceneVersion: string;
31
41
  paymentMethodCategoryType: PaymentMethodCategoryTypeEnum;
32
42
  isPreload?: boolean;
33
43
  query: QueryParams;
44
+ v2Url?: string;
34
45
  }) => {
35
46
  path: string;
36
47
  locationSearch: string;
37
48
  };
49
+ export declare const getWebAppV2Url: (params: {
50
+ environment: string;
51
+ sdkMetaData: SDKMetaData;
52
+ productScene: ProductSceneEnum;
53
+ productSceneVersion: string;
54
+ paymentMethodCategoryType: PaymentMethodCategoryTypeEnum;
55
+ isPreload?: boolean;
56
+ query: QueryParams;
57
+ mid?: string;
58
+ extendInfo?: string;
59
+ }) => string;
38
60
  export declare const getWebAppUrl: (params: {
39
61
  environment: string;
40
62
  sdkMetaData: SDKMetaData;
63
+ productScene: ProductSceneEnum;
41
64
  productSceneVersion: string;
42
65
  paymentMethodCategoryType: PaymentMethodCategoryTypeEnum;
43
66
  isPreload?: boolean;
44
67
  query: QueryParams;
68
+ v2Url?: string;
45
69
  }) => string;
46
70
  export declare const parseWebAppMatchConfig: (extendInfo: string) => WebAppMatchConfig[];
71
+ export declare const parseWebAppUrlMatchConfig: (extendInfo: string) => WebAppUrlMatchConfig[];
72
+ /**
73
+ * Save the current checkout URL to localStorage for the specified product scene.
74
+ *
75
+ * @param productScene - The product scene for which the checkout URL should be saved.
76
+ */
77
+ export declare const saveLocalCheckoutUrl: (productScene: ProductSceneEnum, url: string) => void;
78
+ /**
79
+ * Retrieve the saved checkout URL from localStorage for the specified product scene.
80
+ * If no url is found, a default checkout url string is returned.
81
+ *
82
+ * @param productScene - The product scene for which the checkout URL should be retrieved.
83
+ */
84
+ export declare const getLocalCheckoutUrl: (productScene: ProductSceneEnum) => string;
85
+ /**
86
+ * Provide default checkout URL for the specified product scene.
87
+ * Return URL for 'EASY_PAY' product scene, while for other product scenes, it returns an empty string as they are not currently in use
88
+ *
89
+ * @param productScene - The product scene for which the default checkout URL should be provided.
90
+ */
91
+ export declare const defaultCheckoutUrl: (productScene: ProductSceneEnum) => string;
@@ -1,9 +1,11 @@
1
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2
4
  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; }
3
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
6
  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); }
5
- import { ComponentSignEnum } from "../../types";
6
- import { marmotMap } from "../../config";
7
+ import { ComponentSignEnum, ProductSceneEnum } from "../../types";
8
+ import { marmotMap, v2AppMarmotMap } from "../../config";
7
9
  import { queryParse, serialize } from "../../util";
8
10
  import { isDebugLog } from "../../util/debug";
9
11
 
@@ -12,14 +14,21 @@ import { isDebugLog } from "../../util/debug";
12
14
  * Sent by server inside paymentSession.
13
15
  */
14
16
 
17
+ /**
18
+ * Tell the SDK which Web App URL to load.
19
+ * Sent by server inside paymentSession.
20
+ */
21
+
15
22
  export var getWebAppUrlInfo = function getWebAppUrlInfo(params) {
16
23
  var environment = params.environment,
17
24
  sdkMetaData = params.sdkMetaData,
25
+ productScene = params.productScene,
18
26
  productSceneVersion = params.productSceneVersion,
19
27
  paymentMethodCategoryType = params.paymentMethodCategoryType,
20
28
  query = params.query,
21
- isPreload = params.isPreload;
22
- var path = getAppPath(environment, sdkMetaData, productSceneVersion, paymentMethodCategoryType);
29
+ isPreload = params.isPreload,
30
+ v2Url = params.v2Url;
31
+ var path = getAppPath(environment, sdkMetaData, productScene, productSceneVersion, paymentMethodCategoryType, v2Url);
23
32
  var _queryParse = queryParse(),
24
33
  _sandbox = _queryParse._sandbox,
25
34
  _light_sandbox = _queryParse._light_sandbox,
@@ -57,6 +66,29 @@ export var getWebAppUrlInfo = function getWebAppUrlInfo(params) {
57
66
  locationSearch: locationSearch
58
67
  };
59
68
  };
69
+ export var getWebAppV2Url = function getWebAppV2Url(params) {
70
+ var productScene = params.productScene,
71
+ isPreload = params.isPreload,
72
+ mid = params.mid,
73
+ extendInfo = params.extendInfo;
74
+ var webAppUrlMatchConfig = parseWebAppUrlMatchConfig(extendInfo);
75
+ var v2Url = isPreload ? getLocalCheckoutUrl(productScene) : getMatchedWebAppV2Url(productScene, mid, webAppUrlMatchConfig);
76
+ var info = getWebAppUrlInfo(_objectSpread(_objectSpread({}, params), {}, {
77
+ v2Url: v2Url
78
+ }));
79
+ if (!isPreload && v2Url && info.path) {
80
+ console.log('[web-sdk] save web app, url: ', info.path);
81
+ saveLocalCheckoutUrl(productScene, info.path);
82
+ }
83
+ var webAppUrl;
84
+ if (info.path.indexOf('?') !== -1) {
85
+ webAppUrl = "".concat(info.path, "&").concat(info.locationSearch);
86
+ } else {
87
+ webAppUrl = "".concat(info.path, "?").concat(info.locationSearch);
88
+ }
89
+ console.log('[web-sdk] web app, url: ', webAppUrl);
90
+ return webAppUrl;
91
+ };
60
92
  export var getWebAppUrl = function getWebAppUrl(params) {
61
93
  var info = getWebAppUrlInfo(params);
62
94
  var webAppUrl;
@@ -70,8 +102,10 @@ export var getWebAppUrl = function getWebAppUrl(params) {
70
102
  var getAppPath = function getAppPath() {
71
103
  var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
72
104
  var sdkMetaData = arguments.length > 1 ? arguments[1] : undefined;
73
- var productSceneVersion = arguments.length > 2 ? arguments[2] : undefined;
74
- var paymentMethodCategoryType = arguments.length > 3 ? arguments[3] : undefined;
105
+ var productScene = arguments.length > 2 ? arguments[2] : undefined;
106
+ var productSceneVersion = arguments.length > 3 ? arguments[3] : undefined;
107
+ var paymentMethodCategoryType = arguments.length > 4 ? arguments[4] : undefined;
108
+ var v2Url = arguments.length > 5 ? arguments[5] : undefined;
75
109
  var _ref = queryParse() || {},
76
110
  urlTestHost = _ref.host;
77
111
  // only for test while testurl?host=https://xxxxx.test.html
@@ -81,7 +115,12 @@ var getAppPath = function getAppPath() {
81
115
  var validProductSceneVersion = getValidProductSceneVersion(sdkMetaData.productScene, productSceneVersion, paymentMethodCategoryType);
82
116
  var productSceneWithPaymentMethodCategoryType = "".concat(sdkMetaData.productScene, "_").concat(paymentMethodCategoryType);
83
117
  var webAppVersion = sdkMetaData.webAppVersion;
84
- return "".concat(marmotMap[environment], "/").concat(productSceneWithPaymentMethodCategoryType, "/").concat(validProductSceneVersion, "/index.").concat(webAppVersion, ".html");
118
+ switch (productScene) {
119
+ case ProductSceneEnum.EASY_PAY:
120
+ return v2Url !== null && v2Url !== void 0 ? v2Url : defaultCheckoutUrl(productScene);
121
+ default:
122
+ return "".concat(marmotMap[environment], "/").concat(productSceneWithPaymentMethodCategoryType, "/").concat(validProductSceneVersion, "/index.").concat(webAppVersion, ".html");
123
+ }
85
124
  };
86
125
  export var parseWebAppMatchConfig = function parseWebAppMatchConfig(extendInfo) {
87
126
  if (!extendInfo) {
@@ -96,6 +135,18 @@ export var parseWebAppMatchConfig = function parseWebAppMatchConfig(extendInfo)
96
135
  return [];
97
136
  }
98
137
  };
138
+ export var parseWebAppUrlMatchConfig = function parseWebAppUrlMatchConfig(extendInfo) {
139
+ if (!extendInfo) {
140
+ return [];
141
+ }
142
+ try {
143
+ var extendInfoJson = JSON.parse(extendInfo);
144
+ return extendInfoJson === null || extendInfoJson === void 0 ? void 0 : extendInfoJson.checkoutInfo;
145
+ } catch (error) {
146
+ console.error('Parse the url config for Web app failed#', error);
147
+ return [];
148
+ }
149
+ };
99
150
  var getValidProductSceneVersion = function getValidProductSceneVersion(productScene, productSceneVer, paymentMethodCategoryType) {
100
151
  var _supportMapping;
101
152
  var supportMapping = (_supportMapping = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_supportMapping, 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.ELEMENT_PAYMENT, ['1.0']), _defineProperty(_defineProperty(_supportMapping, ComponentSignEnum.ELEMENT_ADDRESS, ['1.0']), ComponentSignEnum.CHECKOUT_PAYMENT, ['1.0']));
@@ -109,4 +160,75 @@ var getValidProductSceneVersion = function getValidProductSceneVersion(productSc
109
160
  });
110
161
  var latestVersion = targetVersions[targetVersions.length - 1];
111
162
  return isSupport ? productSceneVer : latestVersion;
163
+ };
164
+ var KEY_CHECKOUT_URL = "web_url_";
165
+
166
+ /**
167
+ * Save the current checkout URL to localStorage for the specified product scene.
168
+ *
169
+ * @param productScene - The product scene for which the checkout URL should be saved.
170
+ */
171
+ export var saveLocalCheckoutUrl = function saveLocalCheckoutUrl(productScene, url) {
172
+ var key = KEY_CHECKOUT_URL + productScene;
173
+ localStorage.setItem(key, url);
174
+ };
175
+
176
+ /**
177
+ * Retrieve the saved checkout URL from localStorage for the specified product scene.
178
+ * If no url is found, a default checkout url string is returned.
179
+ *
180
+ * @param productScene - The product scene for which the checkout URL should be retrieved.
181
+ */
182
+ export var getLocalCheckoutUrl = function getLocalCheckoutUrl(productScene) {
183
+ var key = KEY_CHECKOUT_URL + productScene;
184
+ var previousCheckoutUrl = localStorage.getItem(key);
185
+ return previousCheckoutUrl !== null && previousCheckoutUrl !== void 0 ? previousCheckoutUrl : defaultCheckoutUrl(productScene);
186
+ };
187
+
188
+ /**
189
+ * Provide default checkout URL for the specified product scene.
190
+ * Return URL for 'EASY_PAY' product scene, while for other product scenes, it returns an empty string as they are not currently in use
191
+ *
192
+ * @param productScene - The product scene for which the default checkout URL should be provided.
193
+ */
194
+ export var defaultCheckoutUrl = function defaultCheckoutUrl(productScene) {
195
+ var defaultEnvironment = 'prod';
196
+ switch (productScene) {
197
+ case ProductSceneEnum.EASY_PAY:
198
+ return "".concat(v2AppMarmotMap[defaultEnvironment], "/easysafepay/pages/sdk-portal/index.html");
199
+ default:
200
+ return '';
201
+ }
202
+ };
203
+ var getMatchedWebAppV2Url = function getMatchedWebAppV2Url(productScene) {
204
+ var mid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
205
+ var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
206
+ if (config.length === 0) {
207
+ // Default checkout url
208
+ return defaultCheckoutUrl(productScene);
209
+ }
210
+ var sortedConfig = config.sort(function (a, b) {
211
+ return parseFloat(b.version) - parseFloat(a.version);
212
+ });
213
+ var targetConfigEntry = sortedConfig.find(function (configEntry) {
214
+ var _configEntry$mid;
215
+ var isMatchMid = (_configEntry$mid = configEntry.mid) !== null && _configEntry$mid !== void 0 && _configEntry$mid.trim() ? configEntry.mid.toUpperCase().includes(mid === null || mid === void 0 ? void 0 : mid.toUpperCase()) : true;
216
+ if (isMatchMid) {
217
+ return configEntry;
218
+ }
219
+ });
220
+ if (targetConfigEntry) {
221
+ // Match merchant ID
222
+ return targetConfigEntry === null || targetConfigEntry === void 0 ? void 0 : targetConfigEntry.url;
223
+ }
224
+ var sortedAllMerchantsConfig = sortedConfig.find(function (configEntry) {
225
+ return configEntry.mid === undefined || configEntry.mid === '';
226
+ });
227
+ if (sortedAllMerchantsConfig) {
228
+ // Match highest version without merchant ID
229
+ return sortedAllMerchantsConfig === null || sortedAllMerchantsConfig === void 0 ? void 0 : sortedAllMerchantsConfig.url;
230
+ }
231
+
232
+ // Default checkout url
233
+ return defaultCheckoutUrl(productScene);
112
234
  };
package/esm/index.js CHANGED
@@ -271,7 +271,7 @@ export var AMSEasyPay = /*#__PURE__*/function () {
271
271
  securityRegion: 'SG',
272
272
  environment: 'prod'
273
273
  };
274
- PreloadHelper.preloadWebApp(ProductSceneEnum.EASY_PAY, PaymentMethodCategoryTypeEnum.WALLET, options.environment);
274
+ PreloadHelper.preloadWebApp(ProductSceneEnum.EASY_PAY, PaymentMethodCategoryTypeEnum.WALLET, options.environment, true);
275
275
  }
276
276
  }]);
277
277
  return AMSEasyPay;
@@ -15,7 +15,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
15
15
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
16
16
  * 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.
17
17
  */
18
- import { elementAppMarmotMap, marmotMap, sdkVersion } from "../../config/index";
18
+ import { v2AppMarmotMap, marmotMap, sdkVersion } from "../../config/index";
19
19
  import { ComponentSignEnum, ComponentSignEnumV2 } from "../../types";
20
20
  import { isDebugLog } from "../../util/debug";
21
21
  import { queryParse, serialize } from "../../util/index";
@@ -103,7 +103,7 @@ export var getAppPath = function getAppPath() {
103
103
  }
104
104
  // 地址应用特殊处理
105
105
  if (componentSign === ComponentSignEnum.ELEMENT_ADDRESS) {
106
- return "".concat(elementAppMarmotMap[environment], "/element-address/").concat(finalAppVersion, "/pages/address/index.html");
106
+ return "".concat(v2AppMarmotMap[environment], "/element-address/").concat(finalAppVersion, "/pages/address/index.html");
107
107
  }
108
108
  // element应用特殊处理
109
109
  if (_toConsumableArray(Object.values(ComponentSignEnumV2)).includes(componentSign)) {
@@ -117,9 +117,9 @@ export var getAppPath = function getAppPath() {
117
117
  }
118
118
  if (isExpressCheckout) {
119
119
  // express_checkout模式走单独映射
120
- return "".concat(elementAppMarmotMap[environment], "/elements/").concat(finalAppVersion, "/pages/express_checkout/index.html");
120
+ return "".concat(v2AppMarmotMap[environment], "/elements/").concat(finalAppVersion, "/pages/express_checkout/index.html");
121
121
  } else {
122
- return "".concat(elementAppMarmotMap[environment], "/elements/").concat(finalAppVersion, "/pages/").concat(productScene.toLowerCase(), "/index.html");
122
+ return "".concat(v2AppMarmotMap[environment], "/elements/").concat(finalAppVersion, "/pages/").concat(productScene.toLowerCase(), "/index.html");
123
123
  }
124
124
  }
125
125
  return "".concat(marmotMap[environment], "/").concat(componentSign, "/").concat(finalProductSceneVersion, "/index.").concat(finalAppVersion, ".html");
@@ -71,11 +71,11 @@ export function getDoubleFaUrl(params) {
71
71
  var isLandscapeOrientation = false; // Web 不含横屏
72
72
 
73
73
  var DOUBLE_FA_URL_MAPPING = {
74
- local: "http://page.alipay.net/page/antom-web-checkout/src/component-app/doubleFA/index.".concat(sdkVersion, ".html"),
75
- dev: "http://page.alipay.net/page/antom-web-checkout/src/component-app/doubleFA/index.".concat(sdkVersion, ".html"),
76
- sit: "http://page.test.alipay.net/page/antom-web-checkout/src/component-app/doubleFA/index.".concat(sdkVersion, ".html"),
77
- pre: "https://pre.ac.alipay.com/page/antom-web-checkout/src/component-app/doubleFA/index.".concat(sdkVersion, ".html"),
78
- prod: "https://ac.alipay.com/page/antom-web-checkout/src/component-app/doubleFA/index.".concat(sdkVersion, ".html")
74
+ local: 'http://page.alipay.net/page/antom-web-checkout-v2/easysafepay/pages/double-fa/index-1.0.1.html',
75
+ dev: 'http://page.alipay.net/page/antom-web-checkout-v2/easysafepay/pages/double-fa/index-1.0.1.html',
76
+ sit: 'http://page.test.alipay.net/page/antom-web-checkout-v2/easysafepay/pages/double-fa/index.html',
77
+ pre: 'https://pre.ac.alipay.com/page/antom-web-checkout-v2/easysafepay/pages/double-fa/index.html',
78
+ prod: 'https://checkout.antom.com/easysafepay/pages/double-fa/index.html'
79
79
  };
80
80
  var doubleFaBaseUrl = DOUBLE_FA_URL_MAPPING[env] || DOUBLE_FA_URL_MAPPING.prod;
81
81
  return "".concat(doubleFaBaseUrl, "?scene=cashierResultPage&instanceId=").concat(instanceId, "&paymentSessionData=").concat(encodeURIComponent(paymentSessionData), "&isLandscape=").concat(isLandscapeOrientation ? 'true' : '', "&pmt=").concat(paymentMethodType, "&locale=").concat(locale, "&sdkVersion=").concat(sdkVersion);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1746673215-dev.1",
3
+ "version": "0.0.1746674797-dev.0",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",