bachs-sdk 0.1.0

Unofficial Rust SDK for the Bachs API — payments and billing for internet businesses.
Documentation
use crate::client::{Bachs, RequestOptions};
use crate::common::{FlexObject, ListParams, ListResponse, Metadata, Timestamp};
use crate::error::BachsResult;
use reqwest::Method;
use serde::{Deserialize, Serialize};

/// Create the sub-accounts your platform onboards, for marketplace / platform
/// fund routing.
#[derive(Debug, Clone, Serialize)]
pub struct CreateConnectedAccountRequest {
    pub email: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<Metadata>,
}

impl CreateConnectedAccountRequest {
    pub fn new(email: impl Into<String>) -> Self {
        Self {
            email: email.into(),
            country: None,
            metadata: None,
        }
    }

    pub fn country(mut self, country: impl Into<String>) -> Self {
        self.country = Some(country.into());
        self
    }
}

#[derive(Debug, Clone, Deserialize)]
pub struct ConnectedAccount {
    #[serde(default)]
    pub connected_account_id: Option<String>,
    #[serde(default)]
    pub email: Option<String>,
    /// What the account still needs to complete onboarding (capability
    /// requests, KYC tasks, etc).
    #[serde(default)]
    pub tasks: Vec<serde_json::Value>,
    #[serde(default)]
    pub metadata: Metadata,
    #[serde(default)]
    pub created_at: Option<Timestamp>,
    #[serde(flatten)]
    pub extra: FlexObject,
}

pub struct ConnectedAccounts<'a> {
    pub(crate) client: &'a Bachs,
}

impl<'a> ConnectedAccounts<'a> {
    pub async fn create(
        &self,
        req: &CreateConnectedAccountRequest,
    ) -> BachsResult<ConnectedAccount> {
        self.create_with_options(req, None).await
    }

    pub async fn create_with_options(
        &self,
        req: &CreateConnectedAccountRequest,
        options: Option<&RequestOptions>,
    ) -> BachsResult<ConnectedAccount> {
        self.client
            .send(
                Method::POST,
                "/v1/connected-accounts",
                Some(req),
                None,
                options,
            )
            .await
    }

    pub async fn get(&self, connected_account_id: &str) -> BachsResult<ConnectedAccount> {
        self.client
            .send::<(), _>(
                Method::GET,
                &format!("/v1/connected-accounts/{connected_account_id}"),
                None,
                None,
                None,
            )
            .await
    }

    pub async fn list(
        &self,
        params: &ListParams,
    ) -> BachsResult<ListResponse<ConnectedAccount>> {
        let query = params.to_query();
        self.client
            .send::<(), _>(
                Method::GET,
                "/v1/connected-accounts",
                None,
                Some(&query),
                None,
            )
            .await
    }
}