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 ChargesApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    /// Number of items to return per page.
    ///
    /// Defaults to `15`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Page number to return.
    ///
    /// Defaults to `1`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// 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>,
}

impl Default for ListParams {
    #[allow(deprecated)]
    fn default() -> Self {
        Self {
            limit: Some(15),
            page: Some(1),
            x_store: Default::default(),
        }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateParams {
    /// 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: SdkCreateChargeRequestApplicationJson,
}

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

#[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, Default, Serialize)]
pub struct MarkCompletedParams {
    /// 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 MarkVoidedParams {
    /// 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>,
}

impl<'a> ChargesApi<'a> {
    /// List all charges
    ///
    /// Retrieve a paginated list of charges for your store. 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<SdkListChargesResponseValue200ApplicationJson, 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<SdkListChargesResponseValue200ApplicationJson, 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<SdkListChargesResponseValue200ApplicationJson>, Error> {
        let path = "/v2/charges".to_string();
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("listCharges".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(method, &path, &params, options, "GET /v2/charges")
            .await
    }

    /// Create a charge
    ///
    /// Create a standalone charge for payment or a free claim. Requires the charge API ability and store permission. The total is an integer in the currency's minor units: 1999 USD means $19.99. Supplying currency requires total. For a positive paid charge, choose enabled payment_method/payment_methods or use_all_payment_methods; availability depends on the store and currency. CUSTOM_PAYMENT_METHOD is supported: preselection requires custom_payment_method_id. custom_payment_method_ids optionally restricts the available custom methods; omission snapshots the currently usable IDs for this store, without product assignments. Customer proof or confirmation changes custom charges to REVIEW, not COMPLETED. Creating a charge does not prove payment. A repeated create may create another charge; check the original result before retrying. 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 create(
        &self,
        params: CreateParams,
    ) -> Result<SdkCreateChargeResponseValue201ApplicationJson, Error> {
        self.create_with_options(params, None).await
    }

    /// Variant of [`Self::create`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_with_options(
        &self,
        params: CreateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkCreateChargeResponseValue201ApplicationJson, Error> {
        self.create_raw(params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn create_raw(
        &self,
        params: CreateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkCreateChargeResponseValue201ApplicationJson>, Error> {
        let path = "/v2/charges".to_string();
        let method = http::Method::POST;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("createCharge".to_string());
        let options = Some(&merged);
        self.client
            .request_with_body_schema_opts_raw(
                method,
                &path,
                &params,
                Some(&params.body),
                options,
                "POST /v2/charges",
            )
            .await
    }

    /// Retrieve a charge
    ///
    /// Retrieve a charge by its ID to check its details and payment state. The response schema describes the returned fields. 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,
        charge: &str,
        params: GetParams,
    ) -> Result<SdkGetChargeResponseValue200ApplicationJson, Error> {
        self.get_with_options(charge, params, None).await
    }

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

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

    /// Mark pending charge completed
    ///
    /// Manually complete a PENDING or VOIDED ordinary charge, or a custom-payment charge in REVIEW, after independently verifying receipt of funds. This does not collect, capture, or verify payment. Initialized custom-payment wallet top-ups may be approved from PENDING or REVIEW and credit the deposit plus any snapshotted bonus exactly once. Other wallet gateways cannot be completed manually, and voided custom top-ups cannot be revived. Completion emits charge.completed webhooks and store notifications and records applicable platform fees. Requires the charge API ability and update permission. A charge already completed returns 422; retrieve its state before retrying. 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 mark_completed(
        &self,
        charge_id: &str,
        params: MarkCompletedParams,
    ) -> Result<SdkMarkPendingChargeCompletedResponseValue200ApplicationJson, Error> {
        self.mark_completed_with_options(charge_id, params, None)
            .await
    }

    /// Variant of [`Self::mark_completed`] that accepts per-request [`crate::RequestOptions`].
    pub async fn mark_completed_with_options(
        &self,
        charge_id: &str,
        params: MarkCompletedParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkMarkPendingChargeCompletedResponseValue200ApplicationJson, Error> {
        self.mark_completed_raw(charge_id, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn mark_completed_raw(
        &self,
        charge_id: &str,
        params: MarkCompletedParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<
        crate::RawResponse<SdkMarkPendingChargeCompletedResponseValue200ApplicationJson>,
        Error,
    > {
        let charge_id = crate::client::path_segment(charge_id);
        let path = format!("/v2/charges/{charge_id}/completed");
        let method = http::Method::PUT;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("markPendingChargeCompleted".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "PUT /v2/charges/{charge_id}/completed",
            )
            .await
    }

    /// Mark pending charge voided
    ///
    /// Void a PENDING charge or a custom-payment charge in REVIEW. This cancels the internal charge, releases an applicable redeemed reward coupon, and emits charge.voided; it does not refund a payment. Requires the charge API ability and update permission. Other states return 422, including a repeat after successful voiding; retrieve its state before retrying. 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 mark_voided(
        &self,
        charge_id: &str,
        params: MarkVoidedParams,
    ) -> Result<SdkMarkPendingChargeVoidedResponseValue200ApplicationJson, Error> {
        self.mark_voided_with_options(charge_id, params, None).await
    }

    /// Variant of [`Self::mark_voided`] that accepts per-request [`crate::RequestOptions`].
    pub async fn mark_voided_with_options(
        &self,
        charge_id: &str,
        params: MarkVoidedParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkMarkPendingChargeVoidedResponseValue200ApplicationJson, Error> {
        self.mark_voided_raw(charge_id, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn mark_voided_raw(
        &self,
        charge_id: &str,
        params: MarkVoidedParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkMarkPendingChargeVoidedResponseValue200ApplicationJson>, Error>
    {
        let charge_id = crate::client::path_segment(charge_id);
        let path = format!("/v2/charges/{charge_id}/voided");
        let method = http::Method::PUT;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("markPendingChargeVoided".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "PUT /v2/charges/{charge_id}/voided",
            )
            .await
    }
}