1use payjp_client_core::{PayjpClient, BlockingClient, PayjpRequest, RequestBuilder, PayjpMethod};
2
3#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
4 struct ListBalanceBuilder {
5#[serde(skip_serializing_if = "Option::is_none")]
6 limit: Option<i64>,
7#[serde(skip_serializing_if = "Option::is_none")]
8 offset: Option<i64>,
9#[serde(skip_serializing_if = "Option::is_none")]
10 since: Option<i64>,
11#[serde(skip_serializing_if = "Option::is_none")]
12 until: Option<i64>,
13#[serde(skip_serializing_if = "Option::is_none")]
14 since_due_date: Option<payjp_types::Timestamp>,
15#[serde(skip_serializing_if = "Option::is_none")]
16 until_due_date: Option<payjp_types::Timestamp>,
17#[serde(skip_serializing_if = "Option::is_none")]
18 state: Option<payjp_core::BalanceState>,
19#[serde(skip_serializing_if = "Option::is_none")]
20 closed: Option<bool>,
21#[serde(skip_serializing_if = "Option::is_none")]
22 owner: Option<ListBalanceOwner>,
23#[serde(skip_serializing_if = "Option::is_none")]
24 tenant: Option<String>,
25
26}
27impl ListBalanceBuilder {
28 fn new() -> Self {
29 Self {
30 limit: None,offset: None,since: None,until: None,since_due_date: None,until_due_date: None,state: None,closed: None,owner: None,tenant: None,
31 }
32}
33
34}
35 #[derive(Copy,Clone,Eq, PartialEq,)]pub enum ListBalanceOwner {
37Merchant,
38Tenant,
39
40}
41impl ListBalanceOwner {
42 pub fn as_str(self) -> &'static str {
43 use ListBalanceOwner::*;
44 match self {
45Merchant => "merchant",
46Tenant => "tenant",
47
48 }
49 }
50}
51
52impl std::str::FromStr for ListBalanceOwner {
53 type Err = payjp_types::ParseError;
54 fn from_str(s: &str) -> Result<Self, Self::Err> {
55 use ListBalanceOwner::*;
56 match s {
57 "merchant" => Ok(Merchant),
58"tenant" => Ok(Tenant),
59_ => Err(payjp_types::ParseError)
60
61 }
62 }
63}
64impl std::fmt::Display for ListBalanceOwner {
65 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
66 f.write_str(self.as_str())
67 }
68}
69
70impl std::fmt::Debug for ListBalanceOwner {
71 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
72 f.write_str(self.as_str())
73 }
74}
75impl serde::Serialize for ListBalanceOwner {
76 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
77 serializer.serialize_str(self.as_str())
78 }
79}
80#[cfg(feature = "deserialize")]
81impl<'de> serde::Deserialize<'de> for ListBalanceOwner {
82 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
83 use std::str::FromStr;
84 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
85 Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for ListBalanceOwner"))
86 }
87}
88#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
89pub struct ListBalance {
90 inner: ListBalanceBuilder,
91
92}
93impl ListBalance {
94 pub fn new() -> Self {
96 Self {
97 inner: ListBalanceBuilder::new()
98 }
99}
100 pub fn limit(mut self, limit: impl Into<i64>) -> Self {
102 self.inner.limit = Some(limit.into());
103 self
104}
105 pub fn offset(mut self, offset: impl Into<i64>) -> Self {
107 self.inner.offset = Some(offset.into());
108 self
109}
110 pub fn since(mut self, since: impl Into<i64>) -> Self {
112 self.inner.since = Some(since.into());
113 self
114}
115 pub fn until(mut self, until: impl Into<i64>) -> Self {
117 self.inner.until = Some(until.into());
118 self
119}
120 pub fn since_due_date(mut self, since_due_date: impl Into<payjp_types::Timestamp>) -> Self {
122 self.inner.since_due_date = Some(since_due_date.into());
123 self
124}
125 pub fn until_due_date(mut self, until_due_date: impl Into<payjp_types::Timestamp>) -> Self {
127 self.inner.until_due_date = Some(until_due_date.into());
128 self
129}
130 pub fn state(mut self, state: impl Into<payjp_core::BalanceState>) -> Self {
132 self.inner.state = Some(state.into());
133 self
134}
135 pub fn closed(mut self, closed: impl Into<bool>) -> Self {
137 self.inner.closed = Some(closed.into());
138 self
139}
140 pub fn owner(mut self, owner: impl Into<ListBalanceOwner>) -> Self {
142 self.inner.owner = Some(owner.into());
143 self
144}
145 pub fn tenant(mut self, tenant: impl Into<String>) -> Self {
147 self.inner.tenant = Some(tenant.into());
148 self
149}
150
151}
152 impl Default for ListBalance {
153 fn default() -> Self {
154 Self::new()
155 }
156}impl ListBalance {
157 pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
159 self.customize().send(client).await
160 }
161
162 pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
164 self.customize().send_blocking(client)
165 }
166
167
168}
169
170impl PayjpRequest for ListBalance {
171 type Output = ListBalanceReturned;
172
173 fn build(&self) -> RequestBuilder {
174 RequestBuilder::new(PayjpMethod::Get, "/balances").query(&self.inner)
175}
176
177}
178#[derive(Clone,Debug,)]#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
179#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
180pub struct ListBalanceReturned {
181pub data: Option<Vec<payjp_core::Balance>>,
182
183}
184#[doc(hidden)]
185pub struct ListBalanceReturnedBuilder {
186 data: Option<Option<Vec<payjp_core::Balance>>>,
187
188}
189
190#[allow(unused_variables, irrefutable_let_patterns, clippy::let_unit_value, clippy::match_single_binding, clippy::single_match)]
191const _: () = {
192 use miniserde::de::{Map, Visitor};
193 use miniserde::json::Value;
194 use miniserde::{make_place, Deserialize, Result};
195 use payjp_types::{MapBuilder, ObjectDeser};
196 use payjp_types::miniserde_helpers::FromValueOpt;
197
198 make_place!(Place);
199
200 impl Deserialize for ListBalanceReturned {
201 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
202 Place::new(out)
203 }
204}
205
206struct Builder<'a> {
207 out: &'a mut Option<ListBalanceReturned>,
208 builder: ListBalanceReturnedBuilder,
209}
210
211impl Visitor for Place<ListBalanceReturned> {
212 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
213 Ok(Box::new(Builder {
214 out: &mut self.out,
215 builder: ListBalanceReturnedBuilder::deser_default(),
216 }))
217 }
218}
219
220impl MapBuilder for ListBalanceReturnedBuilder {
221 type Out = ListBalanceReturned;
222 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
223 Ok(match k {
224 "data" => Deserialize::begin(&mut self.data),
225
226 _ => <dyn Visitor>::ignore(),
227 })
228 }
229
230 fn deser_default() -> Self {
231 Self {
232 data: Deserialize::default(),
233
234 }
235 }
236
237 fn take_out(&mut self) -> Option<Self::Out> {
238 let (Some(data),
239) = (self.data.take(),
240) else {
241 return None;
242 };
243 Some(Self::Out { data })
244 }
245}
246
247impl<'a> Map for Builder<'a> {
248 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
249 self.builder.key(k)
250 }
251
252 fn finish(&mut self) -> Result<()> {
253 *self.out = self.builder.take_out();
254 Ok(())
255 }
256}
257
258impl ObjectDeser for ListBalanceReturned {
259 type Builder = ListBalanceReturnedBuilder;
260}
261
262impl FromValueOpt for ListBalanceReturned {
263 fn from_value(v: Value) -> Option<Self> {
264 let Value::Object(obj) = v else {
265 return None;
266 };
267 let mut b = ListBalanceReturnedBuilder::deser_default();
268 for (k, v) in obj {
269 match k.as_str() {
270 "data" => b.data = FromValueOpt::from_value(v),
271
272 _ => {}
273 }
274 }
275 b.take_out()
276 }
277}
278
279};
280 #[derive(Clone,Debug,)]#[derive(serde::Serialize)]
282pub struct RetrieveBalance {
283 balance: payjp_core::BalanceId,
284
285}
286impl RetrieveBalance {
287 pub fn new(balance:impl Into<payjp_core::BalanceId>) -> Self {
289 Self {
290 balance: balance.into(),
291 }
292}
293
294}
295 impl RetrieveBalance {
296 pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
298 self.customize().send(client).await
299 }
300
301 pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
303 self.customize().send_blocking(client)
304 }
305
306
307}
308
309impl PayjpRequest for RetrieveBalance {
310 type Output = payjp_core::Balance;
311
312 fn build(&self) -> RequestBuilder {
313 let balance = &self.balance;
314RequestBuilder::new(PayjpMethod::Get, format!("/balances/{balance}"))
315}
316
317}
318#[derive(Copy,Clone,Debug,)]#[derive(serde::Serialize)]
319 struct StatementUrlsBalanceBuilder {
320#[serde(skip_serializing_if = "Option::is_none")]
321 platformer: Option<bool>,
322
323}
324impl StatementUrlsBalanceBuilder {
325 fn new() -> Self {
326 Self {
327 platformer: None,
328 }
329}
330
331}
332 #[derive(Clone,Debug,)]#[derive(serde::Serialize)]
334pub struct StatementUrlsBalance {
335 inner: StatementUrlsBalanceBuilder,
336 balance: payjp_core::BalanceId,
337
338}
339impl StatementUrlsBalance {
340 pub fn new(balance:impl Into<payjp_core::BalanceId>) -> Self {
342 Self {
343 balance: balance.into(),inner: StatementUrlsBalanceBuilder::new()
344 }
345}
346 pub fn platformer(mut self, platformer: impl Into<bool>) -> Self {
348 self.inner.platformer = Some(platformer.into());
349 self
350}
351
352}
353 impl StatementUrlsBalance {
354 pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
356 self.customize().send(client).await
357 }
358
359 pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
361 self.customize().send_blocking(client)
362 }
363
364
365}
366
367impl PayjpRequest for StatementUrlsBalance {
368 type Output = payjp_shared::StatementUrl;
369
370 fn build(&self) -> RequestBuilder {
371 let balance = &self.balance;
372RequestBuilder::new(PayjpMethod::Post, format!("/balances/{balance}/statement_urls")).form(&self.inner)
373}
374
375}
376