coinbase_advanced/rest/payment_methods.rs
1//! Payment Methods API endpoints.
2
3use crate::client::RestClient;
4use crate::error::Result;
5use crate::models::{GetPaymentMethodResponse, ListPaymentMethodsResponse, PaymentMethod};
6
7/// API for managing payment methods.
8///
9/// This API provides endpoints for listing and retrieving payment methods.
10pub struct PaymentMethodsApi<'a> {
11 client: &'a RestClient,
12}
13
14impl<'a> PaymentMethodsApi<'a> {
15 /// Create a new Payment Methods API instance.
16 pub(crate) fn new(client: &'a RestClient) -> Self {
17 Self { client }
18 }
19
20 /// List all payment methods.
21 ///
22 /// # Example
23 ///
24 /// ```no_run
25 /// # use coinbase_advanced::{RestClient, Credentials};
26 /// # async fn example() -> coinbase_advanced::Result<()> {
27 /// let client = RestClient::builder()
28 /// .credentials(Credentials::from_env()?)
29 /// .build()?;
30 ///
31 /// let payment_methods = client.payment_methods().list().await?;
32 /// for pm in payment_methods {
33 /// println!("{}: {} ({})", pm.id, pm.name, pm.payment_type);
34 /// }
35 /// # Ok(())
36 /// # }
37 /// ```
38 pub async fn list(&self) -> Result<Vec<PaymentMethod>> {
39 let response: ListPaymentMethodsResponse =
40 self.client.get("/payment_methods").await?;
41 Ok(response.payment_methods)
42 }
43
44 /// Get a specific payment method by ID.
45 ///
46 /// # Example
47 ///
48 /// ```no_run
49 /// # use coinbase_advanced::{RestClient, Credentials};
50 /// # async fn example() -> coinbase_advanced::Result<()> {
51 /// let client = RestClient::builder()
52 /// .credentials(Credentials::from_env()?)
53 /// .build()?;
54 ///
55 /// let payment_method = client.payment_methods().get("payment-method-id").await?;
56 /// println!("Payment method: {} - {}", payment_method.name, payment_method.payment_type);
57 /// # Ok(())
58 /// # }
59 /// ```
60 pub async fn get(&self, payment_method_id: &str) -> Result<PaymentMethod> {
61 let endpoint = format!("/payment_methods/{}", payment_method_id);
62 let response: GetPaymentMethodResponse = self.client.get(&endpoint).await?;
63 Ok(response.payment_method)
64 }
65}