sellapp-sdk 0.1.1

Official Rust SDK for the SellApp API: manage products, orders, subscriptions, and customers.
// This file is auto-generated by oagen. Do not edit.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;

pub struct PaymentMethodsApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct GetParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct EnableParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: SdkEnableOrDisablePaymentMethodRequestApplicationJson,
}

impl EnableParams {
    /// Construct a new `EnableParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: SdkEnableOrDisablePaymentMethodRequestApplicationJson) -> Self {
        Self {
            x_store: Default::default(),
            body,
        }
    }
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ConnectParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct ValidateParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: ValidateParamsBodyOneOf,
}

impl ValidateParams {
    /// Construct a new `ValidateParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: ValidateParamsBodyOneOf) -> Self {
        Self {
            x_store: Default::default(),
            body,
        }
    }
}

impl<'a> PaymentMethodsApi<'a> {
    /// List payment methods
    ///
    /// List safe, pollable setup and checkout status for every payment method available to the store. Provider credentials and wallet addresses are never serialized. Requires the `payment-method` ability or the stronger legacy `store` ability. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn list(
        &self,
        params: ListParams,
    ) -> Result<SdkListPaymentMethodsResponseValue200ApplicationJson, Error> {
        self.list_with_options(params, None).await
    }

    /// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_with_options(
        &self,
        params: ListParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListPaymentMethodsResponseValue200ApplicationJson, Error> {
        self.list_raw(params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn list_raw(
        &self,
        params: ListParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkListPaymentMethodsResponseValue200ApplicationJson>, Error>
    {
        let path = "/v2/payment-methods".to_string();
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("listPaymentMethods".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "GET /v2/payment-methods",
            )
            .await
    }

    /// Retrieve payment method status
    ///
    /// Poll one payment method's connection, health, required-input, and checkout-enabled state. No stored secret is returned. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn get(
        &self,
        payment_method: &str,
        params: GetParams,
    ) -> Result<SdkGetPaymentMethodStatusResponseValue200ApplicationJson, Error> {
        self.get_with_options(payment_method, params, None).await
    }

    /// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_with_options(
        &self,
        payment_method: &str,
        params: GetParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkGetPaymentMethodStatusResponseValue200ApplicationJson, Error> {
        self.get_raw(payment_method, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn get_raw(
        &self,
        payment_method: &str,
        params: GetParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkGetPaymentMethodStatusResponseValue200ApplicationJson>, Error>
    {
        let payment_method = crate::client::path_segment(payment_method);
        let path = format!("/v2/payment-methods/{payment_method}");
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("getPaymentMethodStatus".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "GET /v2/payment-methods/{paymentMethod}",
            )
            .await
    }

    /// Enable or disable a payment method
    ///
    /// Change checkout availability after setup has succeeded. Enabling a disconnected method returns an actionable validation error. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn enable(
        &self,
        payment_method: &str,
        params: EnableParams,
    ) -> Result<SdkEnableOrDisablePaymentMethodResponseValue200ApplicationJson, Error> {
        self.enable_with_options(payment_method, params, None).await
    }

    /// Variant of [`Self::enable`] that accepts per-request [`crate::RequestOptions`].
    pub async fn enable_with_options(
        &self,
        payment_method: &str,
        params: EnableParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkEnableOrDisablePaymentMethodResponseValue200ApplicationJson, Error> {
        self.enable_raw(payment_method, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn enable_raw(
        &self,
        payment_method: &str,
        params: EnableParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<
        crate::RawResponse<SdkEnableOrDisablePaymentMethodResponseValue200ApplicationJson>,
        Error,
    > {
        let payment_method = crate::client::path_segment(payment_method);
        let path = format!("/v2/payment-methods/{payment_method}");
        let method = http::Method::PATCH;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("enableOrDisablePaymentMethod".to_string());
        let options = Some(&merged);
        self.client
            .request_with_body_schema_opts_raw(
                method,
                &path,
                &params,
                Some(&params.body),
                options,
                "PATCH /v2/payment-methods/{paymentMethod}",
            )
            .await
    }

    /// Create a payment connection handoff
    ///
    /// Return a provider-hosted connect URL and a status URL to poll. Currently supported for Stripe and PayPal; unsupported methods return a validation error. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn connect(
        &self,
        payment_method: &str,
        params: ConnectParams,
    ) -> Result<SdkCreatePaymentConnectionHandoffResponseValue200ApplicationJson, Error> {
        self.connect_with_options(payment_method, params, None)
            .await
    }

    /// Variant of [`Self::connect`] that accepts per-request [`crate::RequestOptions`].
    pub async fn connect_with_options(
        &self,
        payment_method: &str,
        params: ConnectParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkCreatePaymentConnectionHandoffResponseValue200ApplicationJson, Error> {
        self.connect_raw(payment_method, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn connect_raw(
        &self,
        payment_method: &str,
        params: ConnectParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<
        crate::RawResponse<SdkCreatePaymentConnectionHandoffResponseValue200ApplicationJson>,
        Error,
    > {
        let payment_method = crate::client::path_segment(payment_method);
        let path = format!("/v2/payment-methods/{payment_method}/connect");
        let method = http::Method::POST;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("createPaymentConnectionHandoff".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "POST /v2/payment-methods/{paymentMethod}/connect",
            )
            .await
    }

    /// Validate and save payment method configuration
    ///
    /// Validate provider credentials or crypto wallet input with the same setup services used by the dashboard, then save the configuration. Secret fields are write-only and never appear in responses or audit payloads. Supported methods are NMI, Mercado Pago, Razorpay, Mollie, LiFi, and Bitcart-backed crypto wallets. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn validate(
        &self,
        payment_method: &str,
        params: ValidateParams,
    ) -> Result<SdkValidateAndSavePaymentMethodConfigurationResponseValue200ApplicationJson, Error>
    {
        self.validate_with_options(payment_method, params, None)
            .await
    }

    /// Variant of [`Self::validate`] that accepts per-request [`crate::RequestOptions`].
    pub async fn validate_with_options(
        &self,
        payment_method: &str,
        params: ValidateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkValidateAndSavePaymentMethodConfigurationResponseValue200ApplicationJson, Error>
    {
        self.validate_raw(payment_method, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn validate_raw(
        &self,
        payment_method: &str,
        params: ValidateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<
        crate::RawResponse<
            SdkValidateAndSavePaymentMethodConfigurationResponseValue200ApplicationJson,
        >,
        Error,
    > {
        let payment_method = crate::client::path_segment(payment_method);
        let path = format!("/v2/payment-methods/{payment_method}/configuration");
        let method = http::Method::PUT;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("validateAndSavePaymentMethodConfiguration".to_string());
        let options = Some(&merged);
        self.client
            .request_with_body_schema_opts_raw(
                method,
                &path,
                &params,
                Some(&params.body),
                options,
                "PUT /v2/payment-methods/{paymentMethod}/configuration",
            )
            .await
    }
}