vynfi 1.9.0

Rust SDK for the VynFi synthetic financial data API
Documentation
use reqwest::Method;

use crate::client::{extract_list, Client};
use crate::error::VynFiError;
use crate::types::*;

/// Billing resource — billing portal, invoices, and payment methods.
///
/// VynFi is pure-prepaid: there are no subscriptions. Buy credits with
/// [`Credits::purchase`](crate::resources::Credits::purchase) instead.
pub struct Billing<'a> {
    client: &'a Client,
}

impl<'a> Billing<'a> {
    pub(crate) fn new(client: &'a Client) -> Self {
        Self { client }
    }

    /// Create a Stripe billing portal session for managing payment methods
    /// and invoices.
    pub async fn portal(&self) -> Result<PortalResponse, VynFiError> {
        self.client
            .request_with_body::<PortalResponse, ()>(Method::POST, "/v1/billing/portal", None)
            .await
    }

    /// List all invoices for the current account.
    pub async fn invoices(&self) -> Result<Vec<Invoice>, VynFiError> {
        let value: serde_json::Value = self
            .client
            .request(Method::GET, "/v1/billing/invoices")
            .await?;
        extract_list(value)
    }

    /// Get the payment method on file.
    pub async fn payment_method(&self) -> Result<serde_json::Value, VynFiError> {
        self.client
            .request(Method::GET, "/v1/billing/payment-method")
            .await
    }
}