tencent_sdk/services/billing.rs
1use crate::{
2 client::{TencentCloudAsync, TencentCloudBlocking},
3 core::{Endpoint, TencentCloudResult},
4};
5use serde::Deserialize;
6use std::borrow::Cow;
7
8#[derive(Debug, Deserialize)]
9/// Response payload returned by `DescribeAccountBalance`.
10///
11/// | Field | Type | Description |
12/// |-------|------|-------------|
13/// | `response` | [`AccountBalance`] | Raw response content from Tencent Cloud.
14pub struct AccountBalanceResponse {
15 #[serde(rename = "Response")]
16 pub response: AccountBalance,
17}
18
19#[derive(Debug, Deserialize)]
20/// Detailed billing attributes mapped from Tencent Cloud billing service.
21///
22/// | Field | Type | Description |
23/// |-------|------|-------------|
24/// | `uin` | `Option<u64>` | UIN of the queried account. |
25/// | `real_balance` | `Option<f64>` | Actual available balance (cents). |
26/// | `cash_account_balance` | `Option<f64>` | Cash balance (cents). |
27/// | `income_into_account_balance` | `Option<f64>` | Income balance (cents). |
28/// | `present_account_balance` | `Option<f64>` | Promotional balance (cents). |
29/// | `freeze_amount` | `Option<f64>` | Frozen amount (cents). |
30/// | `owe_amount` | `Option<f64>` | Outstanding amount (cents). |
31/// | `credit_amount` | `Option<f64>` | Credit limit (cents). |
32/// | `credit_balance` | `Option<f64>` | Remaining credit (cents). |
33/// | `real_credit_balance` | `Option<f64>` | Actual usable credit (cents). |
34/// | `balance` | `Option<f64>` | Deprecated alias of `real_balance`. |
35/// | `request_id` | `String` | Unique request identifier.
36pub struct AccountBalance {
37 #[serde(rename = "Uin")]
38 pub uin: Option<u64>,
39 #[serde(rename = "RealBalance")]
40 pub real_balance: Option<f64>,
41 #[serde(rename = "CashAccountBalance")]
42 pub cash_account_balance: Option<f64>,
43 #[serde(rename = "IncomeIntoAccountBalance")]
44 pub income_into_account_balance: Option<f64>,
45 #[serde(rename = "PresentAccountBalance")]
46 pub present_account_balance: Option<f64>,
47 #[serde(rename = "FreezeAmount")]
48 pub freeze_amount: Option<f64>,
49 #[serde(rename = "OweAmount")]
50 pub owe_amount: Option<f64>,
51 #[serde(rename = "CreditAmount")]
52 pub credit_amount: Option<f64>,
53 #[serde(rename = "CreditBalance")]
54 pub credit_balance: Option<f64>,
55 #[serde(rename = "RealCreditBalance")]
56 pub real_credit_balance: Option<f64>,
57 #[serde(rename = "Balance")]
58 pub balance: Option<f64>,
59 #[serde(rename = "RequestId")]
60 pub request_id: String,
61}
62
63/// TencentCloud Billing `DescribeAccountBalance` endpoint definition.
64///
65/// | Item | Value |
66/// |------|-------|
67/// | Service | `billing` |
68/// | Action | `DescribeAccountBalance` |
69/// | Version | `2018-07-09` |
70/// | Host | `billing.tencentcloudapi.com` |
71/// | Rate Limit | 20 req/s |
72pub struct DescribeAccountBalance;
73
74impl Endpoint for DescribeAccountBalance {
75 type Output = AccountBalanceResponse;
76
77 fn service(&self) -> Cow<'static, str> {
78 Cow::Borrowed("billing")
79 }
80
81 fn action(&self) -> Cow<'static, str> {
82 Cow::Borrowed("DescribeAccountBalance")
83 }
84
85 fn version(&self) -> Cow<'static, str> {
86 Cow::Borrowed("2018-07-09")
87 }
88}
89
90/// Execute the Billing `DescribeAccountBalance` action with the async client.
91///
92/// # Tencent Cloud Reference
93/// | Item | Value |
94/// |------|-------|
95/// | Service | `billing` |
96/// | Action | `DescribeAccountBalance` |
97/// | Version | `2018-07-09` |
98/// | Rate Limit | 20 req/s |
99///
100/// # Request Payload
101/// The API expects an empty JSON object (`{}`).
102///
103/// # Response Highlights
104/// | Field | Description |
105/// |-------|-------------|
106/// | `RealBalance` | Current available balance expressed in cents. |
107/// | `CashAccountBalance` | Cash balance expressed in cents. |
108/// | `PresentAccountBalance` | Promotional balance expressed in cents. |
109/// | `RequestId` | Unique identifier for troubleshooting. |
110///
111/// Returns [`AccountBalanceResponse`].
112pub async fn describe_account_balance_async(
113 client: &TencentCloudAsync,
114) -> TencentCloudResult<AccountBalanceResponse> {
115 client.request(&DescribeAccountBalance).await
116}
117
118/// Execute the Billing `DescribeAccountBalance` action with the blocking client.
119///
120/// This helper mirrors [`describe_account_balance_async`] but executes synchronously.
121pub fn describe_account_balance_blocking(
122 client: &TencentCloudBlocking,
123) -> TencentCloudResult<AccountBalanceResponse> {
124 client.request(&DescribeAccountBalance)
125}
126
127#[cfg(test)]
128mod tests {
129 use super::*;
130
131 #[test]
132 fn deserialize_account_balance_response() {
133 let payload = r#"{
134 "Response": {
135 "Uin": 123456789,
136 "RealBalance": 100.0,
137 "CashAccountBalance": 80.0,
138 "IncomeIntoAccountBalance": 10.0,
139 "PresentAccountBalance": 10.0,
140 "FreezeAmount": 0.0,
141 "OweAmount": 0.0,
142 "CreditAmount": 0.0,
143 "CreditBalance": 0.0,
144 "RealCreditBalance": 0.0,
145 "Balance": 100.0,
146 "RequestId": "req-123"
147 }
148 }"#;
149
150 let parsed: AccountBalanceResponse = serde_json::from_str(payload).unwrap();
151 assert_eq!(parsed.response.request_id, "req-123");
152 assert_eq!(parsed.response.uin, Some(123456789));
153 }
154}