whop_sdk 1.0.13

The official Rust SDK for the Whop API.
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, RequestOptions};
use reqwest::Method;

pub struct AccountLinksClient {
    pub http_client: HttpClient,
}

impl AccountLinksClient {
    pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
        Ok(Self {
            http_client: HttpClient::new(config.clone())?,
        })
    }

    /// Generate a URL that directs a sub-merchant to their account portal, such as the hosted payouts dashboard or the KYC onboarding flow.
    ///
    /// # Arguments
    ///
    /// * `options` - Additional request options such as headers, timeout, etc.
    ///
    /// # Returns
    ///
    /// JSON response from the API
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use whop_sdk::prelude::*;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let config = ClientConfig {
    ///         token: Some("<token>".to_string()),
    ///         ..Default::default()
    ///     };
    ///     let client = Whop::new(config).expect("Failed to build client");
    ///     client
    ///         .account_links
    ///         .create(
    ///             &CreateAccountLinksRequest {
    ///                 company_id: "biz_xxxxxxxxxxxxxx".to_string(),
    ///                 refresh_url: "refresh_url".to_string(),
    ///                 return_url: "return_url".to_string(),
    ///                 use_case: AccountLinkUseCases::AccountOnboarding,
    ///             },
    ///             None,
    ///         )
    ///         .await;
    /// }
    /// ```
    pub async fn create(
        &self,
        request: &CreateAccountLinksRequest,
        options: Option<RequestOptions>,
    ) -> Result<AccountLink, ApiError> {
        self.http_client
            .execute_request(
                Method::POST,
                "account_links",
                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
                None,
                options,
            )
            .await
    }
}