@seaverse/payment-sdk 0.4.0 → 0.4.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.
package/dist/index.cjs CHANGED
@@ -294,6 +294,13 @@ const BIZ_CODE = {
294
294
  BAD_REQUEST: 400,
295
295
  UNAUTHORIZED: 401,
296
296
  SERVER_ERROR: 500,
297
+ // 业务错误码 (4001-4006)
298
+ DAILY_LIMIT_EXCEEDED: 4001,
299
+ PRODUCT_NOT_FOUND: 4002,
300
+ PRODUCT_DISABLED: 4003,
301
+ INSUFFICIENT_BALANCE: 4004,
302
+ ORDER_NOT_FOUND: 4005,
303
+ INVALID_ORDER_STATUS: 4006,
297
304
  };
298
305
 
299
306
  /**
@@ -404,19 +411,17 @@ class SeaArtPayLoader {
404
411
  */
405
412
  async loadComponent() {
406
413
  try {
407
- // 动态导入 @seaart/payment-component
408
- // 注意:消费方需要在项目中安装此依赖
409
- await Promise.resolve().then(function () { return seaartPayment; });
414
+ // 动态导入内部打包的 Web Component
415
+ // Web Component 已经打包在 SDK 中,用户无需单独安装
416
+ await Promise.resolve().then(function () { return componentBundle; });
410
417
  this.log('模块导入成功');
411
418
  // 等待自定义元素注册完成
412
419
  await this.waitForElementDefined();
413
420
  this.log('自定义元素注册完成');
414
421
  }
415
422
  catch (error) {
416
- // 如果动态导入失败,可能是消费方没有安装依赖
417
423
  const errorMessage = error instanceof Error ? error.message : String(error);
418
- throw new Error(`无法加载 @seaart/payment-component: ${errorMessage}\n` +
419
- '请确保已安装依赖: npm install @seaart/payment-component');
424
+ throw new Error(`无法加载 Web Component: ${errorMessage}`);
420
425
  }
421
426
  }
422
427
  /**
@@ -536,7 +541,8 @@ class CheckoutAPI {
536
541
  const data = await response.json();
537
542
  this.log('结账响应:', data);
538
543
  if (data.code !== BIZ_CODE.SUCCESS) {
539
- throw this.createError(this.mapErrorCode(data.code), data.msg || '结账失败');
544
+ throw this.createError(this.mapErrorCode(data.code), data.msg || '结账失败', undefined, data.code // 传递原始业务错误码
545
+ );
540
546
  }
541
547
  if (!data.data) {
542
548
  throw this.createError('CHECKOUT_FAILED', '结账响应数据为空');
@@ -605,6 +611,14 @@ class CheckoutAPI {
605
611
  return 'UNAUTHORIZED';
606
612
  case BIZ_CODE.SERVER_ERROR:
607
613
  return 'API_ERROR';
614
+ // 业务错误码统一映射为 CHECKOUT_FAILED,通过 bizCode 区分具体原因
615
+ case BIZ_CODE.DAILY_LIMIT_EXCEEDED:
616
+ case BIZ_CODE.PRODUCT_NOT_FOUND:
617
+ case BIZ_CODE.PRODUCT_DISABLED:
618
+ case BIZ_CODE.INSUFFICIENT_BALANCE:
619
+ case BIZ_CODE.ORDER_NOT_FOUND:
620
+ case BIZ_CODE.INVALID_ORDER_STATUS:
621
+ return 'CHECKOUT_FAILED';
608
622
  default:
609
623
  return 'CHECKOUT_FAILED';
610
624
  }
@@ -612,8 +626,8 @@ class CheckoutAPI {
612
626
  /**
613
627
  * 创建支付错误
614
628
  */
615
- createError(code, message, cause) {
616
- return { code, message, cause };
629
+ createError(code, message, cause, bizCode) {
630
+ return { code, message, cause, bizCode };
617
631
  }
618
632
  /**
619
633
  * 检查是否是支付错误
@@ -880,6 +894,7 @@ class PaymentCheckoutClient {
880
894
  payment.setAttribute('transaction-id', options.transactionId);
881
895
  payment.setAttribute('environment', this.config.environment);
882
896
  payment.setAttribute('language', options.language ?? DEFAULT_CHECKOUT_CONFIG.language);
897
+ payment.setAttribute('api-host', this.config.apiHost);
883
898
  // 设置可选属性
884
899
  if (options.userName) {
885
900
  payment.setAttribute('user-name', options.userName);
@@ -18003,9 +18018,20 @@ if (typeof window !== "undefined" && !customElements.get("seaart-payment")) {
18003
18018
  customElements.define("seaart-payment", SeaArtPayment);
18004
18019
  }
18005
18020
 
18006
- var seaartPayment = /*#__PURE__*/Object.freeze({
18007
- __proto__: null,
18008
- default: SeaArtPayment
18021
+ /**
18022
+ * Internal module: SeaArt Payment Component Bundle
18023
+ *
18024
+ * This module re-exports @seaart/payment-component for internal bundling.
18025
+ * End users don't need to install @seaart/payment-component separately -
18026
+ * it's bundled into the SDK during the build process.
18027
+ *
18028
+ * @internal
18029
+ */
18030
+ // Import and register the Web Component
18031
+ // This side-effect will register <seaart-payment> custom element
18032
+
18033
+ var componentBundle = /*#__PURE__*/Object.freeze({
18034
+ __proto__: null
18009
18035
  });
18010
18036
 
18011
18037
  var __defProp = Object.defineProperty;