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

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListRefundsParams {
    /// 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 GetRefundParams {
    /// 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> RefundsApi<'a> {
    /// List refunds
    ///
    /// List refunds for orders and standalone charges in the selected store, one page at a time. 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_refunds(
        &self,
        params: ListRefundsParams,
    ) -> Result<SdkListRefundsResponseValue200ApplicationJson, Error> {
        self.list_refunds_with_options(params, None).await
    }

    /// Variant of [`Self::list_refunds`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_refunds_with_options(
        &self,
        params: ListRefundsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListRefundsResponseValue200ApplicationJson, Error> {
        self.list_refunds_raw(params, options)
            .await
            .map(|response| response.data)
    }

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

    /// Retrieve a refund
    ///
    /// Retrieve one store-scoped refund. 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_refund(
        &self,
        refund: &str,
        params: GetRefundParams,
    ) -> Result<SdkGetRefundResponseValue200ApplicationJson, Error> {
        self.get_refund_with_options(refund, params, None).await
    }

    /// Variant of [`Self::get_refund`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_refund_with_options(
        &self,
        refund: &str,
        params: GetRefundParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkGetRefundResponseValue200ApplicationJson, Error> {
        self.get_refund_raw(refund, params, options)
            .await
            .map(|response| response.data)
    }

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