1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// this file is @generated
#![allow(clippy::doc_markdown, clippy::default_trait_access)]
#[allow(unused_imports, clippy::wildcard_imports)]
use crate::{error::Result, models::*, Configuration};
/// Query and header parameters of [`CreditsWallets::list`].
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct CreditsWalletsListOptions {
/// Only the credit this subscription (`sub_…`) can use: the credit that belongs to it and
/// the customer's credit that belongs to no subscription. Every wallet is still listed.
pub subscription_id: Option<SubscriptionId>,
}
impl CreditsWalletsListOptions {
/// Options with no parameter set.
#[must_use]
pub fn new() -> Self {
Self {
subscription_id: None,
}
}
/// Sets the `subscription_id` query parameter.
#[must_use]
pub fn subscription_id(mut self, subscription_id: impl Into<SubscriptionId>) -> Self {
self.subscription_id = Some(subscription_id.into());
self
}
/// Sets the `subscription_id` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_subscription_id(mut self, subscription_id: Option<SubscriptionId>) -> Self {
self.subscription_id = subscription_id;
self
}
}
/// Query and header parameters of [`CreditsWallets::check`].
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct CreditsWalletsCheckOptions {
/// Defaults to the customer's currency.
pub currency: Option<Currency>,
/// Checks the wallet of this credit unit (its code) instead of a currency.
pub credit_unit: Option<String>,
/// Checks only the credit that can pay for this product: credit not restricted to products,
/// and credit restricted to it. Absent checks all credit.
pub product_id: Option<ProductId>,
/// Checks only the credit this subscription (`sub_…`) can spend, net of its own usage no
/// credit pays: the credit that belongs to it and the customer's credit that belongs to no
/// subscription, once every subscription's unbilled usage is paid. `has_access` is then the
/// decision the access gate makes for that subscription's usage. Absent checks the
/// customer's credit as a whole.
pub subscription_id: Option<SubscriptionId>,
}
impl CreditsWalletsCheckOptions {
/// Options with no parameter set.
#[must_use]
pub fn new() -> Self {
Self {
currency: None,
credit_unit: None,
product_id: None,
subscription_id: None,
}
}
/// Sets the `currency` query parameter.
#[must_use]
pub fn currency(mut self, currency: impl Into<Currency>) -> Self {
self.currency = Some(currency.into());
self
}
/// Sets the `currency` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_currency(mut self, currency: Option<Currency>) -> Self {
self.currency = currency;
self
}
/// Sets the `credit_unit` query parameter.
#[must_use]
pub fn credit_unit(mut self, credit_unit: impl Into<String>) -> Self {
self.credit_unit = Some(credit_unit.into());
self
}
/// Sets the `credit_unit` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_credit_unit(mut self, credit_unit: Option<String>) -> Self {
self.credit_unit = credit_unit;
self
}
/// Sets the `product_id` query parameter.
#[must_use]
pub fn product_id(mut self, product_id: impl Into<ProductId>) -> Self {
self.product_id = Some(product_id.into());
self
}
/// Sets the `product_id` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_product_id(mut self, product_id: Option<ProductId>) -> Self {
self.product_id = product_id;
self
}
/// Sets the `subscription_id` query parameter.
#[must_use]
pub fn subscription_id(mut self, subscription_id: impl Into<SubscriptionId>) -> Self {
self.subscription_id = Some(subscription_id.into());
self
}
/// Sets the `subscription_id` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_subscription_id(mut self, subscription_id: Option<SubscriptionId>) -> Self {
self.subscription_id = subscription_id;
self
}
}
/// Query and header parameters of [`CreditsWallets::update`], built
/// with the required ones by [`new`](Self::new).
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct CreditsWalletsUpdateOptions {
/// The `Idempotency-Key` header parameter.
pub idempotency_key: String,
}
impl CreditsWalletsUpdateOptions {
/// Options with the required parameters set.
#[must_use]
pub fn new(idempotency_key: impl Into<String>) -> Self {
Self {
idempotency_key: idempotency_key.into(),
}
}
}
/// The credits wallets API, from
/// [`Credits::wallets`](crate::api::Credits::wallets).
#[derive(Clone)]
pub struct CreditsWallets {
cfg: std::sync::Arc<Configuration>,
options: crate::api::RequestOptions,
}
impl std::fmt::Debug for CreditsWallets {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CreditsWallets")
.field("options", &self.options)
.finish_non_exhaustive()
}
}
impl CreditsWallets {
pub(super) fn new(cfg: std::sync::Arc<Configuration>) -> Self {
Self {
cfg,
options: crate::api::RequestOptions::default(),
}
}
/// Applies `options` (headers, timeout, retries, idempotency key) to the calls made
/// through the returned value.
#[must_use]
pub fn with_options(mut self, options: crate::api::RequestOptions) -> Self {
self.options = options;
self
}
/// List wallets
///
/// A customer's credit per currency and credit unit: the credit on account, the usage not
/// invoiced yet and the balance left after it, with the wallet's alerts and automatic top-up. The
/// customer's own currency comes first, even when empty. With `subscription_id`, each wallet
/// counts only the credit that subscription can use.
///
/// `GET /api/v1/customers/{id_or_alias}/wallets`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 404, 429, 500).
pub fn list(
&self,
id_or_alias: &str,
options: impl Into<Option<CreditsWalletsListOptions>>,
) -> crate::api::Call<crate::models::WalletListResponse> {
let CreditsWalletsListOptions { subscription_id } = options.into().unwrap_or_default();
crate::request::Request::new(http::Method::GET, "/api/v1/customers/{id_or_alias}/wallets")
.with_path_param("id_or_alias", id_or_alias)
.with_optional_query_param("subscription_id", subscription_id)
.with_options(&self.options)
.json(&self.cfg)
}
/// Check wallet access
///
/// Whether the customer's prepaid credit in a currency or credit unit still covers them, net of
/// usage not invoiced yet. Denies only when the wallet blocks usage once its credit is used up;
/// otherwise access stays allowed and `exhausted` signals the empty balance on its own. With
/// `subscription_id`, only the credit that subscription can use counts: pass it when the
/// customer has several subscriptions, since one subscription's credit cannot pay another's
/// usage. The balance follows usage within a few seconds near zero or a threshold, within a
/// minute otherwise, and the answer is cached for one second: use it to gate consumption, not
/// to bill.
///
/// `GET /api/v1/customers/{id_or_alias}/wallets/check`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 404, 429, 500).
pub fn check(
&self,
id_or_alias: &str,
options: impl Into<Option<CreditsWalletsCheckOptions>>,
) -> crate::api::Call<crate::models::WalletCheck> {
let CreditsWalletsCheckOptions {
currency,
credit_unit,
product_id,
subscription_id,
} = options.into().unwrap_or_default();
crate::request::Request::new(
http::Method::GET,
"/api/v1/customers/{id_or_alias}/wallets/check",
)
.with_path_param("id_or_alias", id_or_alias)
.with_optional_query_param("currency", currency)
.with_optional_query_param("credit_unit", credit_unit)
.with_optional_query_param("product_id", product_id)
.with_optional_query_param("subscription_id", subscription_id)
.with_options(&self.options)
.json(&self.cfg)
}
/// Configure a wallet
///
/// Settings of a customer's wallet in one currency or credit unit: whether usage is refused
/// once its credit is used up, the balances that fire `wallet.balance_low`, and its automatic
/// top-up. Opens the wallet if it does not exist yet. Partial update: omit a field to leave it
/// unchanged.
///
/// `PATCH /api/v1/customers/{id_or_alias}/wallets/{currency}`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 403, 404, 409, 429, 500).
pub fn update(
&self,
id_or_alias: &str,
currency: &str,
patch_wallet_request: crate::models::PatchWalletRequest,
options: CreditsWalletsUpdateOptions,
) -> crate::api::Call<crate::models::Wallet> {
let CreditsWalletsUpdateOptions { idempotency_key } = options;
crate::request::Request::new(
http::Method::PATCH,
"/api/v1/customers/{id_or_alias}/wallets/{currency}",
)
.with_path_param("id_or_alias", id_or_alias)
.with_path_param("currency", currency)
.with_header_param("Idempotency-Key", &idempotency_key)
.with_body_param(patch_wallet_request)
.with_options(&self.options)
.json(&self.cfg)
}
}