use std::collections::HashMap;
use std::sync::Arc;
use crate::error::FlowResult;
use crate::http::HttpClient;
pub struct PaymentLinkService {
pub(crate) http: Arc<HttpClient>,
}
impl PaymentLinkService {
pub async fn create(&self, params: &serde_json::Value) -> FlowResult<serde_json::Value> {
let data = self.http.post("/merchants/me/payment-links", Some(params)).await?;
Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
}
pub async fn list(&self, page: Option<u32>, limit: Option<u32>) -> FlowResult<serde_json::Value> {
let mut params = HashMap::new();
if let Some(p) = page {
params.insert("page".to_string(), p.to_string());
}
if let Some(l) = limit {
params.insert("limit".to_string(), l.to_string());
}
let p = if params.is_empty() { None } else { Some(¶ms) };
let data = self.http.get("/merchants/me/payment-links", p).await?;
Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
}
pub async fn update(&self, link_id: &str, fields: &serde_json::Value) -> FlowResult<serde_json::Value> {
let data = self.http.patch(&format!("/merchants/me/payment-links/{}", link_id), Some(fields)).await?;
Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
}
pub async fn delete(&self, link_id: &str) -> FlowResult<()> {
self.http.delete(&format!("/merchants/me/payment-links/{}", link_id)).await?;
Ok(())
}
}