@alipay/ams-checkout 0.0.1745390310-dev.6 → 0.0.1745808793-dev.1

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.
@@ -178,6 +178,29 @@ export var AntomSDKCore = /*#__PURE__*/function () {
178
178
  return _ref2.apply(this, arguments);
179
179
  };
180
180
  }());
181
+ eventCenter.listen(EVENT.getSdkVersion.name, /*#__PURE__*/function () {
182
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(data, payload) {
183
+ var _payload$context3;
184
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
185
+ while (1) switch (_context3.prev = _context3.next) {
186
+ case 0:
187
+ eventCenter.dispatchToApp({
188
+ event: 'appEventCallback',
189
+ eventCallbackId: (_payload$context3 = payload.context) === null || _payload$context3 === void 0 ? void 0 : _payload$context3.eventCallbackId,
190
+ data: {
191
+ version: sdkMetaData === null || sdkMetaData === void 0 ? void 0 : sdkMetaData.sdkVersion
192
+ }
193
+ });
194
+ case 1:
195
+ case "end":
196
+ return _context3.stop();
197
+ }
198
+ }, _callee3);
199
+ }));
200
+ return function (_x5, _x6) {
201
+ return _ref3.apply(this, arguments);
202
+ };
203
+ }());
181
204
  eventCenter.listen(EVENT.destroy.name, function (data) {
182
205
  _this.setStatus(IElementStatus.READY);
183
206
  _this.destroy();
@@ -208,14 +231,14 @@ export var AntomSDKCore = /*#__PURE__*/function () {
208
231
  }, {
209
232
  key: "startBizFlow",
210
233
  value: function () {
211
- var _startBizFlow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(options) {
234
+ var _startBizFlow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(options) {
212
235
  var _this$paymentContext$, _this$paymentContext$2, _this$paymentContext$3;
213
236
  var paymentSession, displayInfo, _convertPaymentSessio2, paymentSessionId, paymentSessionMetaData, mid, webAppMatchConfig, webAppVersion, productScene, paymentMethod, _this$bizFlowStartBeh, payload;
214
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
215
- while (1) switch (_context3.prev = _context3.next) {
237
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
238
+ while (1) switch (_context4.prev = _context4.next) {
216
239
  case 0:
217
240
  if (!(!options || !options.paymentSession)) {
218
- _context3.next = 2;
241
+ _context4.next = 2;
219
242
  break;
220
243
  }
221
244
  throw new Error('paymentSession is empty');
@@ -245,61 +268,61 @@ export var AntomSDKCore = /*#__PURE__*/function () {
245
268
  // Invoke processor
246
269
  productScene = (_this$paymentContext$2 = this.paymentContext.paymentSessionObj) === null || _this$paymentContext$2 === void 0 || (_this$paymentContext$2 = _this$paymentContext$2.paymentSessionConfig) === null || _this$paymentContext$2 === void 0 ? void 0 : _this$paymentContext$2.productScene;
247
270
  paymentMethod = (_this$paymentContext$3 = this.paymentContext.paymentSessionObj) === null || _this$paymentContext$3 === void 0 || (_this$paymentContext$3 = _this$paymentContext$3.paymentMethodInfoView) === null || _this$paymentContext$3 === void 0 ? void 0 : _this$paymentContext$3.paymentMethodType;
248
- _context3.prev = 14;
271
+ _context4.prev = 14;
249
272
  if (!this.productProcessors["".concat(productScene, "|").concat(paymentMethod)]) {
250
- _context3.next = 21;
273
+ _context4.next = 21;
251
274
  break;
252
275
  }
253
- _context3.next = 18;
276
+ _context4.next = 18;
254
277
  return this.productProcessors["".concat(productScene, "|").concat(paymentMethod)].startBizFlow(this.paymentContext);
255
278
  case 18:
256
- this.bizFlowStartBehavior = _context3.sent;
257
- _context3.next = 25;
279
+ this.bizFlowStartBehavior = _context4.sent;
280
+ _context4.next = 25;
258
281
  break;
259
282
  case 21:
260
283
  if (!this.productProcessors["".concat(productScene)]) {
261
- _context3.next = 25;
284
+ _context4.next = 25;
262
285
  break;
263
286
  }
264
- _context3.next = 24;
287
+ _context4.next = 24;
265
288
  return this.productProcessors["".concat(productScene)].startBizFlow(this.paymentContext);
266
289
  case 24:
267
- this.bizFlowStartBehavior = _context3.sent;
290
+ this.bizFlowStartBehavior = _context4.sent;
268
291
  case 25:
269
- _context3.next = 30;
292
+ _context4.next = 30;
270
293
  break;
271
294
  case 27:
272
- _context3.prev = 27;
273
- _context3.t0 = _context3["catch"](14);
274
- console.error('Invoke processor failed', _context3.t0);
295
+ _context4.prev = 27;
296
+ _context4.t0 = _context4["catch"](14);
297
+ console.error('Invoke processor failed', _context4.t0);
275
298
  case 30:
276
299
  if (!(!this.bizFlowStartBehavior || this.bizFlowStartBehavior.behaviorType === 'NONE' || !this.bizFlowStartBehavior.payload)) {
277
- _context3.next = 32;
300
+ _context4.next = 32;
278
301
  break;
279
302
  }
280
- return _context3.abrupt("return");
303
+ return _context4.abrupt("return");
281
304
  case 32:
282
305
  if (!(this.bizFlowStartBehavior.behaviorType === 'RENDER')) {
283
- _context3.next = 35;
306
+ _context4.next = 35;
284
307
  break;
285
308
  }
286
309
  this.handleBehaviorRender();
287
- return _context3.abrupt("return");
310
+ return _context4.abrupt("return");
288
311
  case 35:
289
312
  if (!(this.bizFlowStartBehavior.behaviorType === 'REDIRECT')) {
290
- _context3.next = 39;
313
+ _context4.next = 39;
291
314
  break;
292
315
  }
293
316
  payload = (_this$bizFlowStartBeh = this.bizFlowStartBehavior) === null || _this$bizFlowStartBeh === void 0 ? void 0 : _this$bizFlowStartBeh.payload;
294
317
  redirect(payload, this.instanceId);
295
- return _context3.abrupt("return");
318
+ return _context4.abrupt("return");
296
319
  case 39:
297
320
  case "end":
298
- return _context3.stop();
321
+ return _context4.stop();
299
322
  }
300
- }, _callee3, this, [[14, 27]]);
323
+ }, _callee4, this, [[14, 27]]);
301
324
  }));
302
- function startBizFlow(_x5) {
325
+ function startBizFlow(_x7) {
303
326
  return _startBizFlow.apply(this, arguments);
304
327
  }
305
328
  return startBizFlow;
@@ -32,7 +32,7 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
32
32
  // 是否允许submitPay提前调用,在ESP非首次的性能优化场景使用
33
33
  _defineProperty(this, "allowSubmitPayCallAhead", void 0);
34
34
  _defineProperty(this, "channelBehavior", void 0);
35
- _defineProperty(this, "SECURITY_SDK_INIT_TIMEOUT", 18000);
35
+ _defineProperty(this, "SECURITY_SDK_INIT_TIMEOUT", 1500);
36
36
  _defineProperty(this, "SDK_REQUEST_TIMEOUT", 15000);
37
37
  _defineProperty(this, "LOAD_APP_RESOURCES_TIMEOUT", 15000);
38
38
  }
@@ -46,7 +46,7 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
46
46
  this.eventCenter = ServiceProvider.getInstance(this.instanceId).getService('EventCenter');
47
47
 
48
48
  // preload web app
49
- PreloadHelper.preloadWebApp(ProductSceneEnum.EASY_PAY, PaymentMethodCategoryTypeEnum.WALLET, this.initConfig.environment);
49
+ PreloadHelper.preloadWebApp(ProductSceneEnum.EASY_PAY, PaymentMethodCategoryTypeEnum.WALLET, this.initConfig.environment, true);
50
50
  }
51
51
  }, {
52
52
  key: "startBizFlow",
@@ -82,7 +82,7 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
82
82
  return _context.abrupt("return", this.buildRedirectResult(authUrlInfo));
83
83
  case 12:
84
84
  // 下面的场景是需要渲染UI的渠道, 打开WebUrl
85
- webAppUrl = this.buildWebAppUrl(); // const webAppUrl = 'http://svc-9kvjxwjf68cptha8.cloudide.svc.et15-sqa.alipay.net:5173/src/component-app/index.html';
85
+ webAppUrl = this.buildWebAppUrl();
86
86
  resultPayload = {
87
87
  url: webAppUrl,
88
88
  allowClickPopupOutsideClose: (_this$channelBehavior = this.channelBehavior) === null || _this$channelBehavior === void 0 ? void 0 : _this$channelBehavior.allowClickOutsideClose
@@ -113,15 +113,19 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
113
113
  }, {
114
114
  key: "buildWebAppUrl",
115
115
  value: function buildWebAppUrl() {
116
- var _paymentContext$payme3, _paymentContext$payme4, _this$initConfig$anal;
116
+ var _paymentContext$payme3, _paymentContext$payme4, _paymentContext$payme5, _this$initConfig$anal;
117
117
  var paymentContext = this.paymentContext;
118
118
  var paymentMethodCategoryType = (_paymentContext$payme3 = paymentContext.paymentSessionObj.paymentSessionConfig) === null || _paymentContext$payme3 === void 0 ? void 0 : _paymentContext$payme3.paymentMethodCategoryType;
119
- var productSceneVersion = (_paymentContext$payme4 = paymentContext.paymentSessionObj.paymentSessionConfig) === null || _paymentContext$payme4 === void 0 ? void 0 : _paymentContext$payme4.productSceneVersion;
119
+ var productScene = (_paymentContext$payme4 = paymentContext.paymentSessionObj.paymentSessionConfig) === null || _paymentContext$payme4 === void 0 ? void 0 : _paymentContext$payme4.productScene;
120
+ var productSceneVersion = (_paymentContext$payme5 = paymentContext.paymentSessionObj.paymentSessionConfig) === null || _paymentContext$payme5 === void 0 ? void 0 : _paymentContext$payme5.productSceneVersion;
120
121
  var hostSign = this.hostSign;
121
- var webAppUrl = WebAppUrlUtil.getWebAppUrl({
122
+ var mid = paymentContext.paymentSessionObj.clientId;
123
+ var extendInfo = paymentContext.paymentSessionObj.extendInfo;
124
+ var webAppUrl = WebAppUrlUtil.getWebAppV2Url({
122
125
  environment: this.initConfig.environment,
123
126
  paymentMethodCategoryType: paymentMethodCategoryType,
124
127
  sdkMetaData: paymentContext.sdkMetaData,
128
+ productScene: productScene,
125
129
  productSceneVersion: productSceneVersion,
126
130
  isPreload: false,
127
131
  query: {
@@ -130,7 +134,9 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
130
134
  instanceId: this.instanceId,
131
135
  locale: this.initConfig.locale,
132
136
  hostSign: hostSign
133
- }
137
+ },
138
+ mid: mid,
139
+ extendInfo: extendInfo
134
140
  });
135
141
  return webAppUrl;
136
142
  }
@@ -229,7 +235,7 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
229
235
  value: function () {
230
236
  var _processSubmitPay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
231
237
  var _this$paymentContext3, _this$paymentContext4, _this$paymentContext5, _this$channelBehavior2, _this$channelBehavior3, _this$paymentContext$6;
232
- var submitParams, _ref3, _ref3$productSceneVer, productSceneVersion, _ref4, _ref4$action, _ref4$action2, _ref4$action2$enableS, enableSignAgreement, _ref4$action2$autoDeb, autoDebitWithToken, _this$paymentContext$5, paymentMethodType, isAppWebview, backScheme, requestBizId, extParams, requester, res;
238
+ var submitParams, _ref3, _ref3$productSceneVer, productSceneVersion, _ref4, _ref4$action, _ref4$action2, _ref4$action2$enableS, enableSignAgreement, _ref4$action2$autoDeb, autoDebitWithToken, _this$paymentContext$5, paymentMethodType, isAppWebview, backScheme, requestBizId, extParams, requester, _this$paymentContext$7, res;
233
239
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
234
240
  while (1) switch (_context2.prev = _context2.next) {
235
241
  case 0:
@@ -277,13 +283,18 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
277
283
  paymentSessionData: this.paymentContext.paymentSessionId,
278
284
  env: this.initConfig.environment,
279
285
  sdkVersion: this.paymentContext.sdkMetaData.sdkVersion
280
- })) || {};
281
- extParams.complianceSDK = true;
286
+ })) || {}; // 二次支付不再需要该参数
287
+ if (!autoDebitWithToken) {
288
+ extParams.complianceSDK = true;
289
+ }
282
290
  submitParams.extParams = extParams;
283
291
  requester = ServiceProvider.getInstance(this.instanceId).getService('Requester');
284
292
  _context2.prev = 13;
285
293
  _context2.t0 = requester;
286
- _context2.t1 = submitParams;
294
+ _context2.t1 = _objectSpread(_objectSpread({}, submitParams), {}, {
295
+ integrationType: 'SDK',
296
+ sdkVersion: (_this$paymentContext$7 = this.paymentContext.sdkMetaData.sdkVersion) !== null && _this$paymentContext$7 !== void 0 ? _this$paymentContext$7 : '1.0.0'
297
+ });
287
298
  _context2.t2 = this.initConfig.environment;
288
299
  _context2.t3 = this.SDK_REQUEST_TIMEOUT;
289
300
  _context2.next = 20;
@@ -341,13 +352,13 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
341
352
  key: "acquireApdidToken",
342
353
  value: function () {
343
354
  var _acquireApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
344
- var _this$paymentContext$7;
355
+ var _this$paymentContext$8;
345
356
  var securityService, productScene, deviceId;
346
357
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
347
358
  while (1) switch (_context3.prev = _context3.next) {
348
359
  case 0:
349
360
  securityService = ServiceProvider.getInstance(this.instanceId).getService('Security');
350
- productScene = (_this$paymentContext$7 = this.paymentContext.paymentSessionObj) === null || _this$paymentContext$7 === void 0 || (_this$paymentContext$7 = _this$paymentContext$7.paymentSessionConfig) === null || _this$paymentContext$7 === void 0 ? void 0 : _this$paymentContext$7.productScene;
361
+ productScene = (_this$paymentContext$8 = this.paymentContext.paymentSessionObj) === null || _this$paymentContext$8 === void 0 || (_this$paymentContext$8 = _this$paymentContext$8.paymentSessionConfig) === null || _this$paymentContext$8 === void 0 ? void 0 : _this$paymentContext$8.productScene;
351
362
  deviceId = securityService.getDeviceId({
352
363
  productScene: productScene
353
364
  });
@@ -367,14 +378,14 @@ export var EasySafePayProcessor = /*#__PURE__*/function () {
367
378
  key: "initSecuritySDK",
368
379
  value: function () {
369
380
  var _initSecuritySDK = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
370
- var _this$paymentContext$8, _this$paymentContext$9, productSceneVersion, nonCompliant, nonInitSecuritySDK, isFirstTimeToPay, shouldInitSecuritySDK;
381
+ var _this$paymentContext$9, _this$paymentContext$10, productSceneVersion, nonCompliant, nonInitSecuritySDK, isFirstTimeToPay, shouldInitSecuritySDK;
371
382
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
372
383
  while (1) switch (_context4.prev = _context4.next) {
373
384
  case 0:
374
385
  _context4.prev = 0;
375
386
  productSceneVersion = this.paymentContext.paymentSessionObj.paymentSessionConfig.productSceneVersion;
376
- nonCompliant = (_this$paymentContext$8 = this.paymentContext.paymentSessionObj.action) === null || _this$paymentContext$8 === void 0 ? void 0 : _this$paymentContext$8.nonCompliant;
377
- nonInitSecuritySDK = (_this$paymentContext$9 = this.paymentContext.paymentSessionObj.action) === null || _this$paymentContext$9 === void 0 ? void 0 : _this$paymentContext$9.nonInitSecuritySDK;
387
+ nonCompliant = (_this$paymentContext$9 = this.paymentContext.paymentSessionObj.action) === null || _this$paymentContext$9 === void 0 ? void 0 : _this$paymentContext$9.nonCompliant;
388
+ nonInitSecuritySDK = (_this$paymentContext$10 = this.paymentContext.paymentSessionObj.action) === null || _this$paymentContext$10 === void 0 ? void 0 : _this$paymentContext$10.nonInitSecuritySDK;
378
389
  isFirstTimeToPay = !this.paymentContext.paymentSessionObj.action.autoDebitWithToken;
379
390
  shouldInitSecuritySDK = false;
380
391
  if (nonInitSecuritySDK) {
@@ -4,10 +4,10 @@ export default class PreloadHelper {
4
4
  static isWebAppPreloaded: boolean;
5
5
  static isSecuritySDKPreloaded: boolean;
6
6
  private static securitySdkMap;
7
- static preloadWebApp(productScene: ProductSceneEnum, paymentMethodCategoryType: PaymentMethodCategoryTypeEnum, environment?: string): void;
7
+ static preloadWebApp(productScene: ProductSceneEnum, paymentMethodCategoryType: PaymentMethodCategoryTypeEnum, environment?: string, useV2?: boolean): void;
8
8
  static preloadSecuritySDK(product: ProductSceneEnum, securityRegion?: string): void;
9
9
  static getSecuritySdk(scene: any): Security;
10
- static buildWebAppPreloadUrl(productScene: ProductSceneEnum, paymentMethodCategoryType: PaymentMethodCategoryTypeEnum, environment: string): {
10
+ static buildWebAppPreloadUrl(productScene: ProductSceneEnum, paymentMethodCategoryType: PaymentMethodCategoryTypeEnum, environment: string, useV2?: boolean): {
11
11
  preloadUrl: string;
12
12
  containerId: string;
13
13
  };
@@ -8,7 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  import { sdkVersion } from "../../config";
9
9
  import { createPreloadIframe } from "../service/container/utils";
10
10
  import { ProductSceneEnum } from "../../types";
11
- import { getWebAppUrl } from "../utils/web_app_url_utils";
11
+ import { getWebAppUrl, getWebAppV2Url } from "../utils/web_app_url_utils";
12
12
  import { ProductInfoCacheUtil } from "../utils/payment_product_utils";
13
13
  import { getWebAppVersion } from "./payment_context_utils";
14
14
  import { getSecurityConfigStorageKey, getSecurityHost, getSecurityScene, Security } from "../../util/security";
@@ -22,12 +22,13 @@ var PreloadHelper = /*#__PURE__*/function () {
22
22
  key: "preloadWebApp",
23
23
  value: function preloadWebApp(productScene, paymentMethodCategoryType) {
24
24
  var environment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'prod';
25
+ var useV2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
25
26
  try {
26
27
  if (this.isWebAppPreloaded) {
27
28
  console.log('[web-sdk] web app already preloaded');
28
29
  return;
29
30
  }
30
- var _this$buildWebAppPrel = this.buildWebAppPreloadUrl(productScene, paymentMethodCategoryType, environment),
31
+ var _this$buildWebAppPrel = this.buildWebAppPreloadUrl(productScene, paymentMethodCategoryType, environment, useV2),
31
32
  preloadUrl = _this$buildWebAppPrel.preloadUrl,
32
33
  containerId = _this$buildWebAppPrel.containerId;
33
34
  var preloadIframe = createPreloadIframe(containerId);
@@ -89,6 +90,7 @@ var PreloadHelper = /*#__PURE__*/function () {
89
90
  }, {
90
91
  key: "buildWebAppPreloadUrl",
91
92
  value: function buildWebAppPreloadUrl(productScene, paymentMethodCategoryType, environment) {
93
+ var useV2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
92
94
  var productSceneVersion = productScene === ProductSceneEnum.EASY_PAY ? '2.0' : '1.0';
93
95
  var previousProductInfo = ProductInfoCacheUtil.getPreviousProductInfo(productScene);
94
96
  if (previousProductInfo) {
@@ -101,14 +103,16 @@ var PreloadHelper = /*#__PURE__*/function () {
101
103
  webAppVersion: ''
102
104
  };
103
105
  sdkMetaData.webAppVersion = getWebAppVersion(sdkMetaData);
104
- var preloadUrl = getWebAppUrl({
106
+ var preloadUrlParams = {
105
107
  environment: environment,
106
108
  sdkMetaData: sdkMetaData,
107
109
  paymentMethodCategoryType: paymentMethodCategoryType,
108
110
  isPreload: true,
111
+ productScene: productScene,
109
112
  productSceneVersion: productSceneVersion,
110
113
  query: undefined
111
- });
114
+ };
115
+ var preloadUrl = useV2 ? getWebAppV2Url(preloadUrlParams) : getWebAppUrl(preloadUrlParams);
112
116
  return {
113
117
  preloadUrl: preloadUrl,
114
118
  containerId: containerId
@@ -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;
@@ -49,6 +49,6 @@ declare class ApplePayService {
49
49
  /**
50
50
  * Start Pay
51
51
  */
52
- startPay: (param: IPaymentSessionMetaData) => boolean;
52
+ startPay: (param: IPaymentSessionMetaData) => void;
53
53
  }
54
54
  export default ApplePayService;
@@ -133,20 +133,19 @@ var ApplePayService = /*#__PURE__*/function () {
133
133
  recurring: _this.isRecurring
134
134
  })
135
135
  }).send();
136
- console.log(ApplePaySession, '----ApplePaySession---ApplePaySession');
137
136
  if (!ApplePaySession) {
138
137
  _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "ApplePaySession is only support in Safari");
139
- return false;
138
+ return;
140
139
  }
141
140
  if (!(extendInfo !== null && extendInfo !== void 0 && extendInfo.merchantCapabilities) || !(extendInfo !== null && extendInfo !== void 0 && extendInfo.supportedNetworks) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.registeredCountry) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.currency) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.value) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.merchantName)) {
142
141
  _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal params paymentSessionFactor");
143
- return false;
142
+ return;
144
143
  }
145
144
  if (recurringInfo) {
146
145
  var _recurringInfo$interv;
147
146
  if (!(order !== null && order !== void 0 && order.orderDescription) || !(recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL)) {
148
147
  _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal params recurringInfo");
149
- return false;
148
+ return;
150
149
  }
151
150
  var lineItem = {
152
151
  type: 'final',
@@ -214,7 +213,6 @@ var ApplePayService = /*#__PURE__*/function () {
214
213
  recurring: recurringInfo !== null
215
214
  })
216
215
  }).send();
217
- return true;
218
216
  });
219
217
  this.logger = logger;
220
218
  }