sumup_rs/
payouts.rs

1use crate::{Payout, PayoutListResponse, Result, SumUpClient};
2use serde::Serialize;
3
4#[derive(Debug, Clone, Serialize)]
5pub struct PayoutListQuery {
6    pub start_date: String, // Required: YYYY-MM-DD format
7    pub end_date: String,   // Required: YYYY-MM-DD format
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub limit: Option<i32>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub offset: Option<i32>,
12}
13
14impl SumUpClient {
15    /// Lists all payouts for the authenticated merchant.
16    ///
17    /// # Arguments
18    /// * `query` - Query parameters including required start_date and end_date
19    ///
20    /// Note: This endpoint requires a merchant_code. Use list_merchant_payouts instead.
21    /// The /v1.0/me/payouts endpoint does not exist in the SumUp API.
22    #[deprecated(
23        since = "0.2.0",
24        note = "Use list_merchant_payouts instead. The /me/payouts endpoint does not exist."
25    )]
26    pub async fn list_payouts(&self, _query: &PayoutListQuery) -> Result<PayoutListResponse> {
27        Err(crate::Error::ApiError {
28            status: 404,
29            body: crate::ApiErrorBody {
30                error_type: None,
31                title: Some("Endpoint not implemented".to_string()),
32                status: Some(404),
33                detail: Some("The /v1.0/me/payouts endpoint does not exist in the SumUp API. Use list_merchant_payouts instead.".to_string()),
34                error_code: None,
35                message: None,
36                param: None,
37                additional_fields: std::collections::HashMap::new(),
38            }
39        })
40    }
41
42    /// Lists payouts for a specific merchant.
43    ///
44    /// # Arguments
45    /// * `merchant_code` - The unique merchant code identifier
46    /// * `query` - Query parameters including required start_date and end_date
47    pub async fn list_merchant_payouts(
48        &self,
49        merchant_code: &str,
50        query: &PayoutListQuery,
51    ) -> Result<PayoutListResponse> {
52        let url = self.build_url(&format!("/v1.0/merchants/{}/payouts", merchant_code))?;
53
54        let response = self
55            .http_client
56            .get(url)
57            .bearer_auth(&self.api_key)
58            .query(query)
59            .send()
60            .await?;
61
62        if response.status().is_success() {
63            let payouts = response.json::<PayoutListResponse>().await?;
64            Ok(payouts)
65        } else {
66            self.handle_error(response).await
67        }
68    }
69
70    /// Retrieves an identified payout resource.
71    ///
72    /// # Arguments
73    /// * `payout_id` - The unique payout identifier
74    pub async fn retrieve_payout(&self, payout_id: &str) -> Result<Payout> {
75        let url = self.build_url(&format!("/v1.0/me/payouts/{}", payout_id))?;
76
77        let response = self
78            .http_client
79            .get(url)
80            .bearer_auth(&self.api_key)
81            .send()
82            .await?;
83
84        if response.status().is_success() {
85            let payout = response.json::<Payout>().await?;
86            Ok(payout)
87        } else {
88            self.handle_error(response).await
89        }
90    }
91
92    /// Retrieves a payout for a specific merchant.
93    ///
94    /// # Arguments
95    /// * `merchant_code` - The unique merchant code identifier
96    /// * `payout_id` - The unique payout identifier
97    pub async fn retrieve_merchant_payout(
98        &self,
99        merchant_code: &str,
100        payout_id: &str,
101    ) -> Result<Payout> {
102        let url = self.build_url(&format!(
103            "/v1.0/merchants/{}/payouts/{}",
104            merchant_code, payout_id
105        ))?;
106
107        let response = self
108            .http_client
109            .get(url)
110            .bearer_auth(&self.api_key)
111            .send()
112            .await?;
113
114        if response.status().is_success() {
115            let payout = response.json::<Payout>().await?;
116            Ok(payout)
117        } else {
118            self.handle_error(response).await
119        }
120    }
121}