use std::sync::Arc;
use serde::Serialize;
use crate::error::FlowResult;
use crate::http::HttpClient;
pub struct PaymentLinkService {
pub(crate) http: Arc<HttpClient>,
}
#[derive(Serialize)]
pub struct CreatePaymentLinkParams {
pub title: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub crypto_currency: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub network: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redirect_url: Option<String>,
}
impl PaymentLinkService {
pub async fn create(&self, params: CreatePaymentLinkParams) -> FlowResult<serde_json::Value> {
let data = self.http.post("/merchants/me/payment-links", Some(¶ms)).await?;
Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
}
pub async fn list(&self) -> FlowResult<serde_json::Value> {
let data = self.http.get("/merchants/me/payment-links", None).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(())
}
}