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

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

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

impl<'a> CreditsApi<'a> {
    /// Record a credit transaction
    ///
    /// Atomically grant, consume, or administratively adjust integer credit units. Reusing the same idempotency key with the same transaction is a no-op; conflicting reuse is rejected. 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 record(
        &self,
        params: RecordParams,
    ) -> Result<SdkRecordCreditTransactionResponseValue200ApplicationJson, Error> {
        self.record_with_options(params, None).await
    }

    /// Variant of [`Self::record`] that accepts per-request [`crate::RequestOptions`].
    pub async fn record_with_options(
        &self,
        params: RecordParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkRecordCreditTransactionResponseValue200ApplicationJson, Error> {
        self.record_raw(params, options)
            .await
            .map(|response| response.data)
    }

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