delopay 0.2.0

Official Rust SDK for the DeloPay payments API
Documentation
//! The `mandates` resource.

use std::sync::Arc;

use crate::core::encoding::encode_segment;
use crate::core::error::Result;
use crate::core::models::mandate::MandateResponse;
use crate::http::client::Inner;
use crate::http::transport::HttpMethod;

/// The `mandates` resource, obtained via [`crate::Delopay::mandates`].
#[derive(Debug, Clone)]
pub struct Mandates {
    inner: Arc<Inner>,
}

impl Mandates {
    pub(crate) fn new(inner: Arc<Inner>) -> Self {
        Self { inner }
    }

    /// Retrieve a mandate by ID.
    pub async fn retrieve(&self, mandate_id: &str) -> Result<MandateResponse> {
        let path = format!("/mandates/{}", encode_segment(mandate_id));
        self.inner
            .request(HttpMethod::Get, &path, None, &[], None)
            .await
    }

    /// Revoke a mandate.
    pub async fn revoke(&self, mandate_id: &str) -> Result<MandateResponse> {
        let path = format!("/mandates/revoke/{}", encode_segment(mandate_id));
        self.inner
            .request(HttpMethod::Post, &path, None, &[], None)
            .await
    }

    /// List mandates.
    pub async fn list(&self) -> Result<Vec<MandateResponse>> {
        self.inner
            .request(HttpMethod::Get, "/mandates/list", None, &[], None)
            .await
    }
}