// 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 ProductVariantsPricingApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct ReplaceParams {
/// 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: SdkReplaceProductVariantPricingRequestApplicationJson,
}
impl ReplaceParams {
/// Construct a new `ReplaceParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkReplaceProductVariantPricingRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateParams {
/// 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: SdkUpdateProductVariantPricingRequestApplicationJson,
}
impl UpdateParams {
/// Construct a new `UpdateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkUpdateProductVariantPricingRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
impl<'a> ProductVariantsPricingApi<'a> {
/// Replace product variant pricing
///
/// Replace a variant's pricing and payment-method selection. Omitted `compare_at_price` and `bulk_discount` values are cleared. An empty payment-method array is accepted only when the resulting published variant is genuinely free, including having no paid credit-rate tiers. Requires the `listing` Sanctum ability. Relationship IDs are scoped to the current store. Use the ISO 8601 string `expected_updated_at` to reject stale writes. 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 replace(
&self,
product: &str,
variant: &str,
params: ReplaceParams,
) -> Result<SdkReplaceProductVariantPricingResponseValue200ApplicationJson, Error> {
self.replace_with_options(product, variant, params, None)
.await
}
/// Variant of [`Self::replace`] that accepts per-request [`crate::RequestOptions`].
pub async fn replace_with_options(
&self,
product: &str,
variant: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkReplaceProductVariantPricingResponseValue200ApplicationJson, Error> {
self.replace_raw(product, variant, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn replace_raw(
&self,
product: &str,
variant: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkReplaceProductVariantPricingResponseValue200ApplicationJson>,
Error,
> {
let product = crate::client::path_segment(product);
let variant = crate::client::path_segment(variant);
let path = format!("/v2/products/{product}/variants/{variant}/pricing");
let method = http::Method::PUT;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("replaceProductVariantPricing".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PUT /v2/products/{product}/variants/{variant}/pricing",
)
.await
}
/// Partially update product variant pricing
///
/// Update only the supplied pricing, subscription cadence, quantity pricing tier, or payment-method fields; omitted fields retain their current values. An empty payment-method array is accepted only when the resulting published variant is genuinely free, including having no paid credit-rate tiers. Requires the `listing` Sanctum ability. Relationship IDs are scoped to the current store. Use the ISO 8601 string `expected_updated_at` to reject stale writes. 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 update(
&self,
product: &str,
variant: &str,
params: UpdateParams,
) -> Result<SdkUpdateProductVariantPricingResponseValue200ApplicationJson, Error> {
self.update_with_options(product, variant, params, None)
.await
}
/// Variant of [`Self::update`] that accepts per-request [`crate::RequestOptions`].
pub async fn update_with_options(
&self,
product: &str,
variant: &str,
params: UpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkUpdateProductVariantPricingResponseValue200ApplicationJson, Error> {
self.update_raw(product, variant, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn update_raw(
&self,
product: &str,
variant: &str,
params: UpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkUpdateProductVariantPricingResponseValue200ApplicationJson>,
Error,
> {
let product = crate::client::path_segment(product);
let variant = crate::client::path_segment(variant);
let path = format!("/v2/products/{product}/variants/{variant}/pricing");
let method = http::Method::PATCH;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("updateProductVariantPricing".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PATCH /v2/products/{product}/variants/{variant}/pricing",
)
.await
}
}