On this page

Pass an object containing the current device ID. getPanelAgentCreditsPlans({ devId }).

getPanelAgentCreditsPlans

Requires:
@tuya-miniapp/cloud-api≥1.7.4
Additional notesRead the full notes
Requires user login and access permission for the current device. The corresponding cloud capability must also be linked in the development settings on the MiniApp Developer Platform.
When enabled, returns the free tier and valid paid tiers in their existing configuration order. Use externalCode in plans to query entitlements or associate a VAS SKU.
When enabled, an empty array indicates that no valid paid services are available. When disabled, freePlan is null and plans is an empty array.
If Highway fails, the original error is preserved. If a successful response is missing required fields, the request is rejected with CREDITS_INVALID_PLANS.

Method signature
getPanelAgentCreditsPlans(params: )

Description

Query the Credits plans available for the current device and business model.

Parameters

ParameterTypeRequiredDescription
YesdevId of the current device

Return Value

Type: Promise<GetPanelAgentCreditsPlansResult>
Current business model, free tier, and valid paid tiers

Referenced Types

typeGetPanelAgentCreditsPlansResultValid Credits plans for the current device and business model
| {
      subscriptionEnabled: true;
      /** 1 为分销,2 为核销 */
      businessMode: 1 | 2;
      /** 当前设备适用的免费档 */
      freePlan: PanelAgentCreditsPlan;
      /** 按现有配置顺序排列的付费档,无有效付费服务时为空数组 */
      plans: PanelAgentCreditsPlan[];
    }
  | {
      subscriptionEnabled: false;
      /** 0 为显式关闭,null 为未配置 */
      businessMode: 0 | null;
      freePlan: null;
      plans: [];
    }

Valid Values

GetPanelAgentCreditsPlansResult.businessMode
ValueDescriptionSince
1--
2--

Examples

Request example

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

getPanelAgentCreditsPlans({ devId: 'demo_device' })
  .then(result => console.log(result.plans.find(plan => plan.externalCode === 'demo_a')))
  .catch(error => console.error('Failed to query Credits plans', error));

Response example

{
  "subscriptionEnabled": true,
  "businessMode": 2,
  "freePlan": {
    "code": "FREE",
    "externalCode": null,
    "capacityCredits": 40,
    "hourlyRecoveryCredits": 4,
    "initialResetCount": 1
  },
  "plans": [
    {
      "code": "demo_a",
      "externalCode": "demo_a",
      "capacityCredits": 100,
      "hourlyRecoveryCredits": 10,
      "monthlyResetCount": 2
    }
  ]
}

When Credits is disabled or unconfigured, freePlan is null and plans is an empty array. When enabled, freePlan.externalCode is null. Use the externalCode of a paid plan to match VAS SKUs.

Plan fields

When enabled, businessMode is 1 (distribution) or 2 (redemption). freePlan is the free plan applicable to the device. plans lists eligible paid plans in server order and is empty when no paid plans are eligible.

FieldDescription
codeThe plan code. The free plan uses FREE.
externalCodeThe paid plan's service code for matching VAS SKUs.
capacityCredits, hourlyRecoveryCreditsThe Credits limit and hourly recovery amount, both numbers.
initialResetCount, monthlyResetCountInitial resets granted for the free plan and monthly resets granted for a paid plan, respectively.
serviceName, versionName, summary, displayOrderService name, plan name, benefits summary, and display order, when available.
capacityMultiple, hourlyRecoveryMultipleThe limit and hourly recovery multipliers relative to the free plan, when available.

Credits and VAS integration example