本页目录

请求参数是包含当前设备 ID 的对象。 getPanelAgentCreditsAccount({ devId })。

getPanelAgentCreditsAccount

版本要求:
@tuya-miniapp/cloud-api≥1.7.4

方法签名
getPanelAgentCreditsAccount(params: )

描述

查询设备当前的 Credits 账户。

参数

参数类型必填说明
是当前设备的 devId

返回值

类型:Promise<GetPanelAgentCreditsAccountResult>
当前 Credits 账户及启用状态

引用对象

typeGetPanelAgentCreditsAccountResult设备的当前 Credits 账户
| {
      /** 当前设备已启用 Credits */
      subscriptionEnabled: true;
      /** 1 为分销,2 为核销 */
      businessMode: 1 | 2;
      /** 当前生效的套餐 */
      plan: PanelAgentCreditsCurrentPlan;
      /** 可用 Credits 十进制字符串,零余额为 "0" */
      remainingCredits: string;
      reset: {
        /** 当前设备可用的重置次数 */
        remaining: number;
      };
    }
  | {
      /** 当前设备未启用 Credits */
      subscriptionEnabled: false;
      /** 0 为显式关闭,null 为未配置 */
      businessMode: 0 | null;
      plan: null;
      remainingCredits: null;
      reset: null;
    }

合法值

GetPanelAgentCreditsAccountResult.businessMode
值说明最低版本
1--
2--

示例代码

请求示例

import { getPanelAgentCreditsAccount } from '@tuya-miniapp/cloud-api';

getPanelAgentCreditsAccount({ devId: 'demo_device' })
  .then(account => console.log(account.subscriptionEnabled, account.remainingCredits))
  .catch(error => console.error('查询 Credits 账户失败', error));

返回示例

{
  "subscriptionEnabled": true,
  "businessMode": 1,
  "plan": {
    "code": "FREE",
    "externalCode": null,
    "capacityCredits": 40,
    "hourlyRecoveryCredits": 4,
    "initialResetCount": 1,
    "isSubscribed": false
  },
  "remainingCredits": "0",
  "reset": { "remaining": 0 }
}

subscriptionEnabled 为 false 时,plan、remainingCredits 和 reset 均为 null。显式关闭的 businessMode 为 0,未配置时为 null。

当前套餐与余额

启用时,plan 是当前生效套餐,其权益字段见套餐字段。

字段含义
plan.isSubscribed当前档位是否为已生效的付费服务。
plan.isTrial当前凭证的试用状态,能取到时返回。
plan.skuCode当前购买的规格编码,能取到时返回。
plan.periodUnit、plan.periodValue当前购买的周期单位与周期值,能取到时返回。
remainingCredits十进制字符串。启用后余额为零时返回 "0"。
reset.remaining当前设备可用的重置次数。

Credits 与 VAS 接入示例