sumup_rs/
merchant.rs

1use crate::{Merchant, MerchantProfile, MerchantProfileDetails, Result, SumUpClient};
2
3impl SumUpClient {
4    /// Retrieves the authenticated merchant's profile.
5    ///
6    /// This endpoint returns the profile of the currently authenticated merchant.
7    /// The merchant_code is automatically determined from the API key.
8    pub async fn get_merchant_profile(&self) -> Result<MerchantProfileDetails> {
9        let url = self.build_url("/v0.1/me")?;
10
11        let response = self
12            .http_client
13            .get(url)
14            .bearer_auth(&self.api_key)
15            .send()
16            .await?;
17
18        if response.status().is_success() {
19            let full_profile = response.json::<MerchantProfile>().await?;
20            Ok(full_profile.merchant_profile)
21        } else {
22            self.handle_error(response).await
23        }
24    }
25
26    /// Retrieves a specific merchant's profile.
27    ///
28    /// # Arguments
29    /// * `merchant_code` - The unique merchant code identifier.
30    pub async fn get_merchant(&self, merchant_code: &str) -> Result<Merchant> {
31        let url = self.build_url(&format!("/v0.1/merchants/{}", merchant_code))?;
32
33        let response = self
34            .http_client
35            .get(url)
36            .bearer_auth(&self.api_key)
37            .send()
38            .await?;
39
40        if response.status().is_success() {
41            let merchant = response.json::<Merchant>().await?;
42            Ok(merchant)
43        } else {
44            self.handle_error(response).await
45        }
46    }
47
48    /// Lists all merchant accounts the authenticated user is a member of.
49    /// This is the correct way to "list merchants" according to the API spec.
50    ///
51    /// Note: This uses the memberships endpoint as the API doesn't have a direct
52    /// "list merchants" endpoint. The memberships contain merchant information.
53    pub async fn list_merchants(&self) -> Result<Vec<crate::Membership>> {
54        self.list_memberships().await
55    }
56}