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
//! Payment Methods API endpoints.
use crate::client::RestClient;
use crate::error::Result;
use crate::models::{GetPaymentMethodResponse, ListPaymentMethodsResponse, PaymentMethod};
/// API for managing payment methods.
///
/// This API provides endpoints for listing and retrieving payment methods.
pub struct PaymentMethodsApi<'a> {
client: &'a RestClient,
}
impl<'a> PaymentMethodsApi<'a> {
/// Create a new Payment Methods API instance.
pub(crate) fn new(client: &'a RestClient) -> Self {
Self { client }
}
/// List all payment methods.
///
/// # Example
///
/// ```no_run
/// # use coinbase_advanced::{RestClient, Credentials};
/// # async fn example() -> coinbase_advanced::Result<()> {
/// let client = RestClient::builder()
/// .credentials(Credentials::from_env()?)
/// .build()?;
///
/// let payment_methods = client.payment_methods().list().await?;
/// for pm in payment_methods {
/// println!("{}: {} ({})", pm.id, pm.name, pm.payment_type);
/// }
/// # Ok(())
/// # }
/// ```
pub async fn list(&self) -> Result<Vec<PaymentMethod>> {
let response: ListPaymentMethodsResponse =
self.client.get("/payment_methods").await?;
Ok(response.payment_methods)
}
/// Get a specific payment method by ID.
///
/// # Example
///
/// ```no_run
/// # use coinbase_advanced::{RestClient, Credentials};
/// # async fn example() -> coinbase_advanced::Result<()> {
/// let client = RestClient::builder()
/// .credentials(Credentials::from_env()?)
/// .build()?;
///
/// let payment_method = client.payment_methods().get("payment-method-id").await?;
/// println!("Payment method: {} - {}", payment_method.name, payment_method.payment_type);
/// # Ok(())
/// # }
/// ```
pub async fn get(&self, payment_method_id: &str) -> Result<PaymentMethod> {
let endpoint = format!("/payment_methods/{}", payment_method_id);
let response: GetPaymentMethodResponse = self.client.get(&endpoint).await?;
Ok(response.payment_method)
}
}