@alipay/ams-checkout 2.0.14 → 2.0.16

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.
@@ -132,14 +132,18 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
132
132
  });
133
133
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
134
134
  this.eventCenter.listen(EVENT.getApplePayToken.name, function (data) {
135
+ var _this2$obtainDataRes;
135
136
  var _this2$elementContain = _this2.elementContainer.getPaymentContext(),
136
137
  paymentSessionObj = _this2$elementContain.paymentSessionObj,
137
138
  paymentSession = _this2$elementContain.paymentSession;
139
+ // SDK shipping takes priority; fall back to sdkAction.query shippingInfo (from createSession)
140
+ var shipping = (data === null || data === void 0 ? void 0 : data.shipping) || ((_this2$obtainDataRes = _this2.obtainDataRes) === null || _this2$obtainDataRes === void 0 || (_this2$obtainDataRes = _this2$obtainDataRes.originActionQueryResult) === null || _this2$obtainDataRes === void 0 ? void 0 : _this2$obtainDataRes.shippingInfo);
138
141
  var applePayService = new ApplePaySdk({
139
142
  paymentSessionData: paymentSession,
140
143
  parseData: paymentSessionObj,
141
144
  logger: logger,
142
- env: _this2.options.env.environment
145
+ env: _this2.options.env.environment,
146
+ shipping: shipping
143
147
  });
144
148
  applePayService.startPay().then(function (res) {
145
149
  _this2.eventCenter.dispatchToApp({
@@ -272,9 +276,16 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
272
276
  LOCAL_MOCK = (debugProps === null || debugProps === void 0 ? void 0 : debugProps.isDebug) && (debugProps === null || debugProps === void 0 ? void 0 : debugProps.local_mock);
273
277
  _queryParse = queryParse(this.getElementUrl()), appType = _queryParse.appType;
274
278
  terminalType = isElementPad() ? 'WEB' : appType ? 'APP' : isElementPC() ? 'WEB' : 'WAP';
279
+ /**
280
+ * 生成查询支付动作的Promise
281
+ * 该方法负责向后端发起sdkAction查询请求,获取支付相关的动作配置信息。
282
+ * 支持本地mock模式用于开发调试,生产环境会发起真实的HTTP请求。
283
+ * @returns {Promise<CashierSdkActionQueryResult>} 返回支付动作查询结果的Promise
284
+ */
275
285
  generateActionQueryPromise = function generateActionQueryPromise() {
276
286
  return new Promise(function (resolve, reject) {
277
287
  var _displayInfo$merchant;
288
+ // 本地mock模式:直接返回预设的sdkAction,用于开发调试
278
289
  if (LOCAL_MOCK) {
279
290
  setTimeout(function () {
280
291
  resolve(sdkAction);
@@ -294,12 +305,18 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
294
305
  isUserPreferredLocale: true
295
306
  }
296
307
  };
308
+
309
+ // 可选参数:商户指定的储值卡信息
297
310
  if (displayInfo !== null && displayInfo !== void 0 && (_displayInfo$merchant = displayInfo.merchantAppointParam) !== null && _displayInfo$merchant !== void 0 && _displayInfo$merchant.storedCard) {
298
311
  sdkRequestData.merchantAppointParam = displayInfo.merchantAppointParam;
299
312
  }
313
+
314
+ // 可选参数:控制支付完成后是否重定向
300
315
  if (Object.prototype.hasOwnProperty.call(displayInfo, 'notRedirectAfterComplete')) {
301
316
  sdkRequestData.notRedirectAfterComplete = displayInfo.notRedirectAfterComplete;
302
317
  }
318
+
319
+ // 发起支付动作查询请求
303
320
  requestService.request(sdkRequestData, {
304
321
  env: environment,
305
322
  envInfo: {
@@ -309,8 +326,13 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
309
326
  hostSign: hostSign,
310
327
  timeout: 300000,
311
328
  // TODO dev环境接口超时
312
- 'Operation-Type': 'com.ipay.iexpcashier.sdkAction.query'
329
+ 'Operation-Type': 'com.ipay.iexpcashier.sdkAction.query',
330
+ // 避免被第三方库或axios拦截器覆写,降低请求被错误处理的风险
331
+ headers: {
332
+ 'Content-Type': 'application/json' // 手动指定Content-Type为application/json,确保符合MGW预期
333
+ }
313
334
  }).then(function (result) {
335
+ // 记录请求结果日志
314
336
  if (!result.success) {
315
337
  _this3.getLogger().logError({
316
338
  title: 'sdk_event_sdkQuery_failed'
@@ -329,6 +351,7 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
329
351
  }
330
352
  resolve(result);
331
353
  }, function (e) {
354
+ // 请求异常处理:记录错误日志并reject
332
355
  reject(e);
333
356
  _this3.getLogger().logError({
334
357
  title: 'sdk_event_sdkQuery_failed'
@@ -339,19 +362,28 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
339
362
  });
340
363
  });
341
364
  };
365
+ /**
366
+ * 生成查询用户账户信息的Promise
367
+ * 该方法负责向后端发起oneAccount查询请求,获取用户的账户相关信息(如会员等级、权益等)。
368
+ * 支持本地mock模式用于开发调试,生产环境会发起真实的HTTP请求。
369
+ * @returns {Promise<AccountQueryResult>} 返回账户信息查询结果的Promise
370
+ */
342
371
  generateOneAccountQueryPromise = function generateOneAccountQueryPromise() {
343
372
  return new Promise(function (resolve, reject) {
373
+ // 本地mock模式:直接返回预设的oneAccount数据,用于开发调试
344
374
  if (LOCAL_MOCK) {
345
375
  setTimeout(function () {
346
376
  resolve(oneAccount);
347
377
  }, 100);
348
378
  return;
349
379
  }
380
+
381
+ // 发起账户信息查询请求
350
382
  requestService.request({
351
383
  paymentSessionConfig: paymentSessionConfig,
352
384
  paymentSessionData: paymentSession,
353
385
  accountInfo: {
354
- email: ''
386
+ email: '' // 邮箱字段预留,当前传空字符串
355
387
  }
356
388
  }, {
357
389
  env: environment,
@@ -361,10 +393,16 @@ var PaymentProcessor = /*#__PURE__*/function (_BaseElementProcessor) {
361
393
  },
362
394
  timeout: 300000,
363
395
  // TODO dev环境接口超时
364
- 'Operation-Type': 'com.ipay.iexpfront.one.account.query'
396
+ 'Operation-Type': 'com.ipay.iexpfront.one.account.query',
397
+ // 避免被第三方库或axios拦截器覆写,降低请求被错误处理的风险
398
+ headers: {
399
+ 'Content-Type': 'application/json' // 手动指定Content-Type为application/json,确保符合MGW预期
400
+ }
365
401
  }).then(function (result) {
402
+ // 直接透传查询结果,不做额外处理
366
403
  resolve(result);
367
404
  }, function (e) {
405
+ // 请求异常处理:直接reject错误,由调用方处理
368
406
  reject(e);
369
407
  });
370
408
  });
@@ -174,6 +174,7 @@ export interface PaymentMountOptions extends BaseMountOptions {
174
174
  'state-success': string;
175
175
  'state-info': string;
176
176
  'state-marketing': string;
177
+ 'state-conventional': string;
177
178
  'radius-backup': string;
178
179
  'radius-module': string;
179
180
  'radius-component': string;
@@ -373,7 +374,7 @@ interface IUserName {
373
374
  }
374
375
  type Shippings = ShippingsItem[];
375
376
  type IPaymentMethods = IPaymentMethod[];
376
- interface CKPShipping {
377
+ export interface CKPShipping {
377
378
  shippingRateId?: string;
378
379
  shippingRateData?: ShippingRateData;
379
380
  shippingAddress: ShippingAddress;
@@ -15,7 +15,7 @@ import { createLoader } from '@antglobal/create-sdk-loader';
15
15
 
16
16
  import { stageName } from "./stageName";
17
17
  var SDKURL = {
18
- DEV: "https://sdk-dev.marmot-cloud.com/package/ams-checkout/".concat("2.0.14", "/ams-checkout.js"),
18
+ DEV: "https://sdk-dev.marmot-cloud.com/package/ams-checkout/".concat("2.0.16", "/ams-checkout.js"),
19
19
  LOCAL: "http://localhost:3000/ams-checkout.min.js",
20
20
  PROD: 'https://js.antom.com/v2/ams-checkout.js'
21
21
  };
@@ -1,4 +1,5 @@
1
1
  import { type EventPayload, type IPaymentSessionMetaData } from '../../types';
2
+ import type { CKPShipping } from '../../core/component/element/type';
2
3
  import { Logger } from '../../util/logger';
3
4
  export type IChannelBehavior = {
4
5
  usePaymentSessionAsQueryResult: boolean;
@@ -32,11 +33,13 @@ export declare class ApplePaySdk {
32
33
  private paymentStatus;
33
34
  private logger;
34
35
  private env;
35
- constructor({ paymentSessionData, parseData, logger, env, }: {
36
+ private shipping?;
37
+ constructor({ paymentSessionData, parseData, logger, env, shipping, }: {
36
38
  paymentSessionData: string;
37
39
  parseData: IPaymentSessionMetaData;
38
40
  logger: Logger;
39
41
  env?: string;
42
+ shipping?: CKPShipping;
40
43
  });
41
44
  startPay(): Promise<unknown>;
42
45
  begin(): Promise<unknown>;
@@ -136,7 +136,8 @@ export var ApplePaySdk = /*#__PURE__*/function () {
136
136
  parseData = _ref.parseData,
137
137
  logger = _ref.logger,
138
138
  _ref$env = _ref.env,
139
- env = _ref$env === void 0 ? EnvironmentEnum.prod : _ref$env;
139
+ env = _ref$env === void 0 ? EnvironmentEnum.prod : _ref$env,
140
+ shipping = _ref.shipping;
140
141
  _classCallCheck(this, ApplePaySdk);
141
142
  _defineProperty(this, "APPLESDKURL", 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js');
142
143
  _defineProperty(this, "session", null);
@@ -148,10 +149,12 @@ export var ApplePaySdk = /*#__PURE__*/function () {
148
149
  _defineProperty(this, "paymentStatus", void 0);
149
150
  _defineProperty(this, "logger", void 0);
150
151
  _defineProperty(this, "env", void 0);
152
+ _defineProperty(this, "shipping", void 0);
151
153
  this.paymentSessionData = paymentSessionData;
152
154
  this.parseData = parseData;
153
155
  this.env = env;
154
156
  this.logger = logger;
157
+ this.shipping = shipping;
155
158
  }
156
159
  _createClass(ApplePaySdk, [{
157
160
  key: "startPay",
@@ -346,7 +349,8 @@ export var ApplePaySdk = /*#__PURE__*/function () {
346
349
  paymentFactors: params,
347
350
  paymentMethod: {
348
351
  paymentMethodType: 'APPLEPAY'
349
- }
352
+ },
353
+ shipping: this.shipping
350
354
  };
351
355
  _context4.t2 = this.env;
352
356
  _context4.next = 6;
@@ -1384,12 +1384,13 @@ var ComponentApp = /*#__PURE__*/function () {
1384
1384
  });
1385
1385
  }
1386
1386
  if ((data === null || data === void 0 || (_data$context6 = data.context) === null || _data$context6 === void 0 ? void 0 : _data$context6.event) === EVENT.getApplePayToken.name) {
1387
- var _this$_renderParams18, _this$_renderParams19;
1387
+ var _this$_renderParams18, _this$_renderParams19, _data$context7;
1388
1388
  var applePayService = new ApplePaySdk({
1389
1389
  paymentSessionData: (_this$_renderParams18 = this._renderParams) === null || _this$_renderParams18 === void 0 ? void 0 : _this$_renderParams18.sessionData,
1390
1390
  parseData: (_this$_renderParams19 = this._renderParams) === null || _this$_renderParams19 === void 0 ? void 0 : _this$_renderParams19.paymentSessionMetaData,
1391
1391
  logger: this.AMSSDK.logger,
1392
- env: this.AMSSDK.options.env.environment
1392
+ env: this.AMSSDK.options.env.environment,
1393
+ shipping: data === null || data === void 0 || (_data$context7 = data.context) === null || _data$context7 === void 0 || (_data$context7 = _data$context7.data) === null || _data$context7 === void 0 ? void 0 : _data$context7.shipping
1393
1394
  });
1394
1395
  applePayService.startPay().then(function (res) {
1395
1396
  _this7.dispatchToApp({
@@ -1435,11 +1436,11 @@ var ComponentApp = /*#__PURE__*/function () {
1435
1436
  key: "logEventCallback",
1436
1437
  value: function logEventCallback(data, title) {
1437
1438
  if (data.context.event === EVENT.eventCallback.name) {
1438
- var _data$context8;
1439
+ var _data$context9;
1439
1440
  var callbackData = '';
1440
1441
  try {
1441
- var _data$context7;
1442
- callbackData = JSON.stringify((data === null || data === void 0 || (_data$context7 = data.context) === null || _data$context7 === void 0 ? void 0 : _data$context7.data) || '');
1442
+ var _data$context8;
1443
+ callbackData = JSON.stringify((data === null || data === void 0 || (_data$context8 = data.context) === null || _data$context8 === void 0 ? void 0 : _data$context8.data) || '');
1443
1444
  } catch (e) {
1444
1445
  console.error(e);
1445
1446
  }
@@ -1447,7 +1448,7 @@ var ComponentApp = /*#__PURE__*/function () {
1447
1448
  title: title
1448
1449
  }, {
1449
1450
  callbackData: callbackData,
1450
- callbackId: (data === null || data === void 0 || (_data$context8 = data.context) === null || _data$context8 === void 0 ? void 0 : _data$context8.eventCallbackId) || ''
1451
+ callbackId: (data === null || data === void 0 || (_data$context9 = data.context) === null || _data$context9 === void 0 ? void 0 : _data$context9.eventCallbackId) || ''
1451
1452
  }).send();
1452
1453
  }
1453
1454
  }
@@ -572,6 +572,7 @@ export interface CashierSubmitPayRequest {
572
572
  paymentMethodDetail?: Record<string, any>;
573
573
  category?: string;
574
574
  };
575
+ shipping?: import('../core/component/element/type').CKPShipping;
575
576
  }
576
577
  export interface CashierSubmitPayRequest {
577
578
  paymentMethodType?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "exports": {
@@ -58,7 +58,13 @@
58
58
  "generateApi": "intl-oneapi generate && prettier --write src/modern/sdk/oneapi",
59
59
  "lint": "eslint ./src",
60
60
  "test": "jest --coverage --silent",
61
- "tsc": "tsc --noEmit"
61
+ "tsc": "tsc --noEmit",
62
+ "code-review-biz": "node .agents/skills/code-review-biz/scripts/code-review-cli.js",
63
+ "code-review-biz:mr": "node .agents/skills/code-review-biz/scripts/code-review-cli.js --url=",
64
+ "code-review-biz:push": "node .agents/skills/code-review-biz/scripts/code-review-cli.js --mode=pre-push",
65
+ "code-review-biz:init": "node .agents/skills/code-review-biz/scripts/lib/init.js init",
66
+ "code-review-biz:update": "node .agents/skills/code-review-biz/scripts/lib/init.js update",
67
+ "prepare": "husky install || true"
62
68
  },
63
69
  "commitlint": {
64
70
  "extends": [
package/types.d.ts CHANGED
@@ -233,7 +233,7 @@ export declare class AntomSDKError extends AntomError<AntomSDKErrorCodes> {
233
233
  name: string;
234
234
  }
235
235
 
236
- declare const AntomSDKErrorCodes: {
236
+ export declare const AntomSDKErrorCodes: {
237
237
  /**
238
238
  * @description 找不到主元素
239
239
  */
@@ -246,6 +246,26 @@ declare const AntomSDKErrorCodes: {
246
246
  * @description WebApp 初始化超时
247
247
  */
248
248
  readonly SDK_LAUNCH_PAYMENT_APP_ERROR: "SDK_LAUNCH_PAYMENT_APP_ERROR";
249
+ /**
250
+ * @description 参数非法,缺少必填参数或参数值不合法
251
+ */
252
+ readonly PARAM_INVALID: "PARAM_INVALID";
253
+ /**
254
+ * @description channelClientId 查询接口超时
255
+ */
256
+ readonly CHANNEL_CLIENT_ID_QUERY_TIMEOUT: "CHANNEL_CLIENT_ID_QUERY_TIMEOUT";
257
+ /**
258
+ * @description channelClientId 查询返回 success=true 但缺少 channelClientId
259
+ */
260
+ readonly CHANNEL_CLIENT_ID_MISSING: "CHANNEL_CLIENT_ID_MISSING";
261
+ /**
262
+ * @description channelClientId 查询失败(success=false 或其他异常)
263
+ */
264
+ readonly CHANNEL_CLIENT_ID_QUERY_FAILED: "CHANNEL_CLIENT_ID_QUERY_FAILED";
265
+ /**
266
+ * @description channelClientId 查询失败(请求异常,如网络错误、服务器错误等)
267
+ */
268
+ readonly CHANNEL_CLIENT_ID_QUERY_ERROR: "CHANNEL_CLIENT_ID_QUERY_ERROR";
249
269
  readonly GENERATE_ELEMENT_KEY_FAILED: "GENERATE_ELEMENT_KEY_FAILED";
250
270
  readonly ELEMENT_INIT_FAILED: "ELEMENT_INIT_FAILED";
251
271
  readonly MOUNT_TIMEOUT: "MOUNT_TIMEOUT";
@@ -275,9 +295,9 @@ declare const AntomSDKErrorCodes: {
275
295
  readonly INVALID_REDIRECT_URL: "INVALID_REDIRECT_URL";
276
296
  };
277
297
 
278
- declare type AntomSDKErrorCodes = typeof AntomSDKErrorCodes[keyof typeof AntomSDKErrorCodes];
298
+ export declare type AntomSDKErrorCodes = (typeof AntomSDKErrorCodes)[keyof typeof AntomSDKErrorCodes];
279
299
 
280
- export declare type AntomTheme = "default" | "agateGreen" | "night" | "nostalgicGray" | "gamingPurple" | "cherryBlossomPink" | "light";
300
+ export declare type AntomTheme = 'default' | 'agateGreen' | 'night' | 'nostalgicGray' | 'gamingPurple' | 'cherryBlossomPink' | 'light';
281
301
 
282
302
  declare interface APICallbackOptions {
283
303
  requestType: 'fetch' | 'xhr';
@@ -260,7 +260,7 @@ export declare class AntomSDKError extends AntomError<AntomSDKErrorCodes> {
260
260
  name: string;
261
261
  }
262
262
 
263
- declare const AntomSDKErrorCodes: {
263
+ export declare const AntomSDKErrorCodes: {
264
264
  /**
265
265
  * @description 找不到主元素
266
266
  */
@@ -273,6 +273,26 @@ declare const AntomSDKErrorCodes: {
273
273
  * @description WebApp 初始化超时
274
274
  */
275
275
  readonly SDK_LAUNCH_PAYMENT_APP_ERROR: "SDK_LAUNCH_PAYMENT_APP_ERROR";
276
+ /**
277
+ * @description 参数非法,缺少必填参数或参数值不合法
278
+ */
279
+ readonly PARAM_INVALID: "PARAM_INVALID";
280
+ /**
281
+ * @description channelClientId 查询接口超时
282
+ */
283
+ readonly CHANNEL_CLIENT_ID_QUERY_TIMEOUT: "CHANNEL_CLIENT_ID_QUERY_TIMEOUT";
284
+ /**
285
+ * @description channelClientId 查询返回 success=true 但缺少 channelClientId
286
+ */
287
+ readonly CHANNEL_CLIENT_ID_MISSING: "CHANNEL_CLIENT_ID_MISSING";
288
+ /**
289
+ * @description channelClientId 查询失败(success=false 或其他异常)
290
+ */
291
+ readonly CHANNEL_CLIENT_ID_QUERY_FAILED: "CHANNEL_CLIENT_ID_QUERY_FAILED";
292
+ /**
293
+ * @description channelClientId 查询失败(请求异常,如网络错误、服务器错误等)
294
+ */
295
+ readonly CHANNEL_CLIENT_ID_QUERY_ERROR: "CHANNEL_CLIENT_ID_QUERY_ERROR";
276
296
  readonly GENERATE_ELEMENT_KEY_FAILED: "GENERATE_ELEMENT_KEY_FAILED";
277
297
  readonly ELEMENT_INIT_FAILED: "ELEMENT_INIT_FAILED";
278
298
  readonly MOUNT_TIMEOUT: "MOUNT_TIMEOUT";
@@ -302,9 +322,9 @@ declare const AntomSDKErrorCodes: {
302
322
  readonly INVALID_REDIRECT_URL: "INVALID_REDIRECT_URL";
303
323
  };
304
324
 
305
- declare type AntomSDKErrorCodes = typeof AntomSDKErrorCodes[keyof typeof AntomSDKErrorCodes];
325
+ export declare type AntomSDKErrorCodes = (typeof AntomSDKErrorCodes)[keyof typeof AntomSDKErrorCodes];
306
326
 
307
- export declare type AntomTheme = "default" | "agateGreen" | "night" | "nostalgicGray" | "gamingPurple" | "cherryBlossomPink" | "light";
327
+ export declare type AntomTheme = 'default' | 'agateGreen' | 'night' | 'nostalgicGray' | 'gamingPurple' | 'cherryBlossomPink' | 'light';
308
328
 
309
329
  declare interface APICallbackOptions {
310
330
  requestType: 'fetch' | 'xhr';