// 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 SubscriptionsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct CancelParams {
/// 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: SdkCancelSubscriptionRequestApplicationJson,
}
impl CancelParams {
/// Construct a new `CancelParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkCancelSubscriptionRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ListSubscriptionsParams {
/// 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>,
/// Set to false to return at most 100 matching items in one data array without pagination links or metadata.
///
/// Defaults to `true`.
#[serde(skip_serializing_if = "Option::is_none")]
pub pagination: Option<bool>,
/// Filter by one or more subscription statuses. Repeat the parameter to select several; a single `status=ACTIVE` works too. A status outside the list is rejected with a validation error.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "status[]")]
pub status: Option<Vec<SubscriptionsStatus>>,
/// 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 ListSubscriptionsParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
limit: Some(15),
page: Some(1),
pagination: Some(true),
status: Default::default(),
x_store: Default::default(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct SearchSubscriptionsParams {
/// 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>,
/// Set to false to return at most 100 matching items in one data array without pagination links or metadata.
///
/// Defaults to `true`.
#[serde(skip_serializing_if = "Option::is_none")]
pub pagination: Option<bool>,
/// 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: SdkSearchSubscriptionsRequestApplicationJson,
}
impl SearchSubscriptionsParams {
/// Construct a new `SearchSubscriptionsParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkSearchSubscriptionsRequestApplicationJson) -> Self {
Self {
limit: Some(15),
page: Some(1),
pagination: Some(true),
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetSubscriptionParams {
/// 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 GetCapabilitiesParams {
/// 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 CancelAtPeriodEndParams {
/// 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: SdkCancelSubscriptionAtPeriodEndRequestApplicationJson,
}
impl CancelAtPeriodEndParams {
/// Construct a new `CancelAtPeriodEndParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkCancelSubscriptionAtPeriodEndRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CancelImmediatelyParams {
/// 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: SdkCancelSubscriptionImmediatelyRequestApplicationJson,
}
impl CancelImmediatelyParams {
/// Construct a new `CancelImmediatelyParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkCancelSubscriptionImmediatelyRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct KeepParams {
/// 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: SdkKeepSubscriptionRequestApplicationJson,
}
impl KeepParams {
/// Construct a new `KeepParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkKeepSubscriptionRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct PauseParams {
/// 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: SdkPauseSubscriptionRequestApplicationJson,
}
impl PauseParams {
/// Construct a new `PauseParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkPauseSubscriptionRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ResumeParams {
/// 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: SdkResumeSubscriptionRequestApplicationJson,
}
impl ResumeParams {
/// Construct a new `ResumeParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkResumeSubscriptionRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdatePaymentMethodParams {
/// 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: SdkUpdateSubscriptionPaymentMethodRequestApplicationJson,
}
impl UpdatePaymentMethodParams {
/// Construct a new `UpdatePaymentMethodParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkUpdateSubscriptionPaymentMethodRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct PreviewPlanChangeParams {
/// 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: SdkPreviewSubscriptionPlanChangeRequestApplicationJson,
}
impl PreviewPlanChangeParams {
/// Construct a new `PreviewPlanChangeParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkPreviewSubscriptionPlanChangeRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ConfirmPlanChangeParams {
/// 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: SdkConfirmSubscriptionPlanChangeRequestApplicationJson,
}
impl ConfirmPlanChangeParams {
/// Construct a new `ConfirmPlanChangeParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkConfirmSubscriptionPlanChangeRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct PreviewRenewalDateParams {
/// 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: SdkPreviewSubscriptionRenewalDateChangeRequestApplicationJson,
}
impl PreviewRenewalDateParams {
/// Construct a new `PreviewRenewalDateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkPreviewSubscriptionRenewalDateChangeRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ConfirmRenewalDateParams {
/// 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: SdkConfirmSubscriptionRenewalDateChangeRequestApplicationJson,
}
impl ConfirmRenewalDateParams {
/// Construct a new `ConfirmRenewalDateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkConfirmSubscriptionRenewalDateChangeRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
impl<'a> SubscriptionsApi<'a> {
/// Cancel a subscription
///
/// Cancel an active subscription now or at period end, or one with a payment still owed now: a past due one the store bills in house, or a past due or unpaid Stripe, PayPal, or Razorpay subscription. cancel_at_period_end is required. Refund flags are valid only when it is false; period-end cancellation does not refund the last payment. New integrations should use the cancel-at-period-end and cancel-immediately lifecycle actions instead. A provider refusal, or a state check such as a change already in progress or a subscription that is no longer active, returns `422` with the refusal sentence under `errors.subscription`. Requires the `invoice` Sanctum ability. Refunds are off by default. refund_last_payment requests a real refund; pro_rated_refund requires refund_last_payment and defaults to false. While a Stripe, PayPal, or Razorpay subscription is past due or unpaid, its current period was never paid for, so a pro-rated refund returns `422`; a full refund or no refund still works. Cancellation can succeed even if the requested refund fails. A 200 response or confirmed cancellation does not prove a refund, and the action response does not expose the provider refund result. Check the order and payment-provider refund records before retrying; do not replay cancellation as a refund-recovery step. Reuse an idempotency key only with identical action input and actor. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
#[deprecated]
#[allow(deprecated)]
pub async fn cancel(
&self,
subscription: &str,
params: CancelParams,
) -> Result<SdkCancelSubscriptionResponseValue200ApplicationJson, Error> {
self.cancel_with_options(subscription, params, None).await
}
/// Variant of [`Self::cancel`] that accepts per-request [`crate::RequestOptions`].
#[deprecated]
#[allow(deprecated)]
pub async fn cancel_with_options(
&self,
subscription: &str,
params: CancelParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkCancelSubscriptionResponseValue200ApplicationJson, Error> {
self.cancel_raw(subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
#[deprecated]
pub async fn cancel_raw(
&self,
subscription: &str,
params: CancelParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkCancelSubscriptionResponseValue200ApplicationJson>, Error>
{
let subscription = crate::client::path_segment(subscription);
let path = format!("/v2/subscriptions/{subscription}/cancel");
let method = http::Method::PATCH;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("cancelSubscription".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PATCH /v2/subscriptions/{subscription}/cancel",
)
.await
}
/// List subscriptions
///
/// List the subscriptions belonging to the authenticated store, ordered by identifier ascending. Requires the `invoice` Sanctum ability. Use `status[]` to keep only the states you care about. 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_subscriptions(
&self,
params: ListSubscriptionsParams,
) -> Result<SdkListSubscriptionsResponseValue200ApplicationJson, Error> {
self.list_subscriptions_with_options(params, None).await
}
/// Variant of [`Self::list_subscriptions`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_subscriptions_with_options(
&self,
params: ListSubscriptionsParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkListSubscriptionsResponseValue200ApplicationJson, Error> {
self.list_subscriptions_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn list_subscriptions_raw(
&self,
params: ListSubscriptionsParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkListSubscriptionsResponseValue200ApplicationJson>, Error>
{
let path = "/v2/subscriptions".to_string();
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("listSubscriptions".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/subscriptions",
)
.await
}
/// Search subscriptions
///
/// Search the store's subscriptions, ordered by identifier ascending unless `sort` says otherwise. `search.value` matches the provider subscription ID, the provider customer ID, and the customer email. Filter on `id`, `customer_id` (the SellApp customer ID, as in `customer.id`), `provider`, `status`, or `product_variant_id`, and sort on `id`, `status`, `current_period_start`, `current_period_end`, `created_at`, or `updated_at`. Requires the `invoice` Sanctum 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 search_subscriptions(
&self,
params: SearchSubscriptionsParams,
) -> Result<SdkSearchSubscriptionsResponseValue200ApplicationJson, Error> {
self.search_subscriptions_with_options(params, None).await
}
/// Variant of [`Self::search_subscriptions`] that accepts per-request [`crate::RequestOptions`].
pub async fn search_subscriptions_with_options(
&self,
params: SearchSubscriptionsParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkSearchSubscriptionsResponseValue200ApplicationJson, Error> {
self.search_subscriptions_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn search_subscriptions_raw(
&self,
params: SearchSubscriptionsParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkSearchSubscriptionsResponseValue200ApplicationJson>, Error>
{
let path = "/v2/subscriptions/search".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("searchSubscriptions".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/search",
)
.await
}
/// Retrieve a subscription
///
/// Retrieve one subscription by its SellApp subscription record identifier. Requires the `invoice` Sanctum ability. Foreign-store identifiers return not found. 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_subscription(
&self,
product_subscription: &str,
params: GetSubscriptionParams,
) -> Result<SdkGetSubscriptionResponseValue200ApplicationJson, Error> {
self.get_subscription_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::get_subscription`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_subscription_with_options(
&self,
product_subscription: &str,
params: GetSubscriptionParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetSubscriptionResponseValue200ApplicationJson, Error> {
self.get_subscription_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_subscription_raw(
&self,
product_subscription: &str,
params: GetSubscriptionParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkGetSubscriptionResponseValue200ApplicationJson>, Error> {
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getSubscription".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/subscriptions/{productSubscription}",
)
.await
}
/// View subscription capabilities
///
/// Return the lifecycle actions currently supported for a subscription, each with the reason the customer and the seller are shown. A `customer_only` status names who owns the action rather than who may call the API: a store token carries a plan change and a payment method update on the customer's behalf, while a `customer_only` auto-renewal switch stays with the customer portal. `set_auto_renew` has no API route at all. While a Stripe, PayPal, or Razorpay subscription is past due or unpaid, every action except `cancel_immediately` and, on Razorpay, `update_payment_method`, is `unsupported`, and a subscription the store bills in house that is on hold for an unpaid renewal reports `resume` as `customer_only`, because only the customer can pay to resume it. Requires the `invoice` Sanctum 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 get_capabilities(
&self,
product_subscription: &str,
params: GetCapabilitiesParams,
) -> Result<SdkGetSubscriptionCapabilitiesResponseValue200ApplicationJson, Error> {
self.get_capabilities_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::get_capabilities`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_capabilities_with_options(
&self,
product_subscription: &str,
params: GetCapabilitiesParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetSubscriptionCapabilitiesResponseValue200ApplicationJson, Error> {
self.get_capabilities_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_capabilities_raw(
&self,
product_subscription: &str,
params: GetCapabilitiesParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkGetSubscriptionCapabilitiesResponseValue200ApplicationJson>,
Error,
> {
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}/capabilities");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getSubscriptionCapabilities".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/subscriptions/{productSubscription}/capabilities",
)
.await
}
/// Cancel a subscription at period end
///
/// Schedule cancellation at the end of the current billing period without requesting a refund. Inspect capabilities first. PayPal has no cancellation at period end, so on a PayPal subscription this cancels it with PayPal straight away and keeps the customer's access until the period ends; it can't be kept afterwards. The response records the cancellation action; retrieve the subscription to observe its current state. Reuse an idempotency key only with identical action input and actor. A provider refusal, or a state check such as a change already in progress or a subscription that is no longer active, returns `422` with the refusal sentence under `errors.subscription`. Requires the `invoice` Sanctum 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 cancel_at_period_end(
&self,
product_subscription: &str,
params: CancelAtPeriodEndParams,
) -> Result<SdkCancelSubscriptionAtPeriodEndResponseValue200ApplicationJson, Error> {
self.cancel_at_period_end_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::cancel_at_period_end`] that accepts per-request [`crate::RequestOptions`].
pub async fn cancel_at_period_end_with_options(
&self,
product_subscription: &str,
params: CancelAtPeriodEndParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkCancelSubscriptionAtPeriodEndResponseValue200ApplicationJson, Error> {
self.cancel_at_period_end_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn cancel_at_period_end_raw(
&self,
product_subscription: &str,
params: CancelAtPeriodEndParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkCancelSubscriptionAtPeriodEndResponseValue200ApplicationJson>,
Error,
> {
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}/actions/cancel-period-end");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("cancelSubscriptionAtPeriodEnd".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/cancel-period-end",
)
.await
}
/// Cancel a subscription immediately
///
/// Request immediate subscription cancellation. Inspect capabilities for provider support. This ends future billing and can change customer access. It is the one action left on a Stripe or PayPal subscription that is past due or unpaid, and one of two left on a Razorpay one alongside a payment method update. A provider refusal, or a state check such as a change already in progress or a subscription that is no longer active, returns `422` with the refusal sentence under `errors.subscription`. Requires the `invoice` Sanctum ability. Refunds are off by default. refund_last_payment requests a real refund; pro_rated_refund requires refund_last_payment and defaults to false. While a Stripe, PayPal, or Razorpay subscription is past due or unpaid, its current period was never paid for, so a pro-rated refund returns `422`; a full refund or no refund still works. Cancellation can succeed even if the requested refund fails. A 200 response or confirmed cancellation does not prove a refund, and the action response does not expose the provider refund result. Check the order and payment-provider refund records before retrying; do not replay cancellation as a refund-recovery step. Reuse an idempotency key only with identical action input and actor. 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 cancel_immediately(
&self,
product_subscription: &str,
params: CancelImmediatelyParams,
) -> Result<SdkCancelSubscriptionImmediatelyResponseValue200ApplicationJson, Error> {
self.cancel_immediately_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::cancel_immediately`] that accepts per-request [`crate::RequestOptions`].
pub async fn cancel_immediately_with_options(
&self,
product_subscription: &str,
params: CancelImmediatelyParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkCancelSubscriptionImmediatelyResponseValue200ApplicationJson, Error> {
self.cancel_immediately_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn cancel_immediately_raw(
&self,
product_subscription: &str,
params: CancelImmediatelyParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkCancelSubscriptionImmediatelyResponseValue200ApplicationJson>,
Error,
> {
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}/actions/cancel-immediately");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("cancelSubscriptionImmediately".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/cancel-immediately",
)
.await
}
/// Keep a subscription
///
/// Stop a scheduled cancellation so the subscription keeps renewing, which is the undo for cancelling at period end. The subscription has to still be active, still be scheduled to cancel, and its period must not have ended yet. Any of those, a provider that cannot undo its own schedule (a PayPal subscription or a Razorpay trial, both already cancelled with the provider), or a change already in progress returns `422` with the refusal sentence under `errors.subscription`. Requires the `invoice` Sanctum 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 keep(
&self,
product_subscription: &str,
params: KeepParams,
) -> Result<SdkKeepSubscriptionResponseValue200ApplicationJson, Error> {
self.keep_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::keep`] that accepts per-request [`crate::RequestOptions`].
pub async fn keep_with_options(
&self,
product_subscription: &str,
params: KeepParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkKeepSubscriptionResponseValue200ApplicationJson, Error> {
self.keep_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn keep_raw(
&self,
product_subscription: &str,
params: KeepParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkKeepSubscriptionResponseValue200ApplicationJson>, Error> {
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}/actions/keep");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("keepSubscription".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/keep",
)
.await
}
/// Pause a subscription
///
/// Pause a subscription after checking capabilities. Automatic resume dates are supported by Stripe and by subscriptions the store bills in house; use a future resume_at when supplied. Other provider pauses may need an explicit resume action. Customer-originated pauses are also subject to store pause policies. Reuse an idempotency key only with identical input and actor, and retrieve the subscription after the action. A provider refusal, or a state check such as a change already in progress or a subscription that is no longer active, returns `422` with the refusal sentence under `errors.subscription`. Requires the `invoice` Sanctum 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 pause(
&self,
product_subscription: &str,
params: PauseParams,
) -> Result<SdkPauseSubscriptionResponseValue200ApplicationJson, Error> {
self.pause_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::pause`] that accepts per-request [`crate::RequestOptions`].
pub async fn pause_with_options(
&self,
product_subscription: &str,
params: PauseParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkPauseSubscriptionResponseValue200ApplicationJson, Error> {
self.pause_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn pause_raw(
&self,
product_subscription: &str,
params: PauseParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkPauseSubscriptionResponseValue200ApplicationJson>, Error>
{
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}/actions/pause");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("pauseSubscription".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/pause",
)
.await
}
/// Resume a subscription
///
/// Resume a paused subscription and restore related entitlements where possible. A subscription that is not paused, a subscription the store bills in house that is on hold for an unpaid renewal (only the customer can resume it, by paying that renewal from the customer portal), a provider refusal, or a change already in progress returns `422` with the refusal sentence under `errors.subscription`. Requires the `invoice` Sanctum 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 resume(
&self,
product_subscription: &str,
params: ResumeParams,
) -> Result<SdkResumeSubscriptionResponseValue200ApplicationJson, Error> {
self.resume_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::resume`] that accepts per-request [`crate::RequestOptions`].
pub async fn resume_with_options(
&self,
product_subscription: &str,
params: ResumeParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkResumeSubscriptionResponseValue200ApplicationJson, Error> {
self.resume_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn resume_raw(
&self,
product_subscription: &str,
params: ResumeParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkResumeSubscriptionResponseValue200ApplicationJson>, Error>
{
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}/actions/resume");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("resumeSubscription".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/resume",
)
.await
}
/// Update a subscription payment method
///
/// Request a subscription payment method update. A payment method belongs to the customer, and a store token requests the update on their behalf. The customer still enters the new card themselves, so the action stays `pending` and `redirect_url` is where they finish it: Stripe's hosted page for a Stripe subscription, or a SellApp page for a Razorpay one. `return_url` chooses where Stripe sends the customer afterwards; Razorpay ignores it. PayPal subscriptions and subscriptions the store bills in house don't support the update. Read `update_payment_method` in the capabilities response before calling: an unsupported payment method, or a state check such as a change already in progress, a subscription that is no longer active, or a Stripe subscription with a payment still owed, returns `422` with the refusal sentence under `errors.subscription`. Requires the `invoice` Sanctum 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 update_payment_method(
&self,
product_subscription: &str,
params: UpdatePaymentMethodParams,
) -> Result<SdkUpdateSubscriptionPaymentMethodResponseValue200ApplicationJson, Error> {
self.update_payment_method_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::update_payment_method`] that accepts per-request [`crate::RequestOptions`].
pub async fn update_payment_method_with_options(
&self,
product_subscription: &str,
params: UpdatePaymentMethodParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkUpdateSubscriptionPaymentMethodResponseValue200ApplicationJson, Error> {
self.update_payment_method_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn update_payment_method_raw(
&self,
product_subscription: &str,
params: UpdatePaymentMethodParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkUpdateSubscriptionPaymentMethodResponseValue200ApplicationJson>,
Error,
> {
let product_subscription = crate::client::path_segment(product_subscription);
let path =
format!("/v2/subscriptions/{product_subscription}/actions/update-payment-method");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("updateSubscriptionPaymentMethod".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/update-payment-method",
)
.await
}
/// Preview a subscription plan change
///
/// Preview a subscription plan change before confirming it. The preview stores the change it was taken for and returns a `preview_token` the confirmation must send back, alongside the provider's own pricing preview. On Stripe and in-house subscriptions, `preview_payload.payment_required` says whether confirming charges `amount_due` today or leaves any amount to the next invoice, and `preview_payload.renewal_date` says when the subscription renews next. A plan change belongs to the customer, and a store token previews it on their behalf; a provider refusal, or a state check such as a change already in progress or a subscription that is no longer active, returns `422` with the refusal sentence under `errors.subscription`. Requires the `invoice` Sanctum 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 preview_plan_change(
&self,
product_subscription: &str,
params: PreviewPlanChangeParams,
) -> Result<SdkPreviewSubscriptionPlanChangeResponseValue200ApplicationJson, Error> {
self.preview_plan_change_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::preview_plan_change`] that accepts per-request [`crate::RequestOptions`].
pub async fn preview_plan_change_with_options(
&self,
product_subscription: &str,
params: PreviewPlanChangeParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkPreviewSubscriptionPlanChangeResponseValue200ApplicationJson, Error> {
self.preview_plan_change_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn preview_plan_change_raw(
&self,
product_subscription: &str,
params: PreviewPlanChangeParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkPreviewSubscriptionPlanChangeResponseValue200ApplicationJson>,
Error,
> {
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}/actions/change-plan/preview");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("previewSubscriptionPlanChange".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/change-plan/preview",
)
.await
}
/// Confirm a subscription plan change
///
/// Confirm a previously previewed subscription plan change, sending back the `preview_token` for a preview of the same change. A plan change belongs to the customer, and a store token confirms it on their behalf; a provider refusal, or a state check such as a change already in progress or a subscription that is no longer active, returns `422` with the refusal sentence under `errors.subscription`. `approval_url` accompanies a `pending` action whenever the customer still has to approve the revision at the provider or pay the proration order `proration_order_id` names, and is left out entirely when the provider applied the change itself. Requires the `invoice` Sanctum 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 confirm_plan_change(
&self,
product_subscription: &str,
params: ConfirmPlanChangeParams,
) -> Result<SdkConfirmSubscriptionPlanChangeResponseValue200ApplicationJson, Error> {
self.confirm_plan_change_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::confirm_plan_change`] that accepts per-request [`crate::RequestOptions`].
pub async fn confirm_plan_change_with_options(
&self,
product_subscription: &str,
params: ConfirmPlanChangeParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkConfirmSubscriptionPlanChangeResponseValue200ApplicationJson, Error> {
self.confirm_plan_change_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn confirm_plan_change_raw(
&self,
product_subscription: &str,
params: ConfirmPlanChangeParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkConfirmSubscriptionPlanChangeResponseValue200ApplicationJson>,
Error,
> {
let product_subscription = crate::client::path_segment(product_subscription);
let path = format!("/v2/subscriptions/{product_subscription}/actions/change-plan/confirm");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("confirmSubscriptionPlanChange".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/change-plan/confirm",
)
.await
}
/// Preview a subscription renewal date change
///
/// Preview a new renewal date before confirmation when the subscription's billing-date policy requires one. No payment method supports renewal-date changes today: Stripe, PayPal, Razorpay, and subscriptions the store bills in house all report `shift_billing_date` as `unsupported`, so this returns `422` with the refusal sentence under `errors.subscription`. Read the capabilities response first. Requires the `invoice` Sanctum 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 preview_renewal_date(
&self,
product_subscription: &str,
params: PreviewRenewalDateParams,
) -> Result<SdkPreviewSubscriptionRenewalDateChangeResponseValue200ApplicationJson, Error> {
self.preview_renewal_date_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::preview_renewal_date`] that accepts per-request [`crate::RequestOptions`].
pub async fn preview_renewal_date_with_options(
&self,
product_subscription: &str,
params: PreviewRenewalDateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkPreviewSubscriptionRenewalDateChangeResponseValue200ApplicationJson, Error> {
self.preview_renewal_date_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn preview_renewal_date_raw(
&self,
product_subscription: &str,
params: PreviewRenewalDateParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkPreviewSubscriptionRenewalDateChangeResponseValue200ApplicationJson>,
Error,
> {
let product_subscription = crate::client::path_segment(product_subscription);
let path =
format!("/v2/subscriptions/{product_subscription}/actions/change-renewal-date/preview");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("previewSubscriptionRenewalDateChange".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/change-renewal-date/preview",
)
.await
}
/// Confirm a subscription renewal date change
///
/// Confirm a subscription renewal date change, sending a `preview_token` when the variant's billing-date policy requires previews. No payment method supports renewal-date changes today: Stripe, PayPal, Razorpay, and subscriptions the store bills in house all report `shift_billing_date` as `unsupported`, so this returns `422` with the refusal sentence under `errors.subscription`. Read the capabilities response first. Requires the `invoice` Sanctum 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 confirm_renewal_date(
&self,
product_subscription: &str,
params: ConfirmRenewalDateParams,
) -> Result<SdkConfirmSubscriptionRenewalDateChangeResponseValue200ApplicationJson, Error> {
self.confirm_renewal_date_with_options(product_subscription, params, None)
.await
}
/// Variant of [`Self::confirm_renewal_date`] that accepts per-request [`crate::RequestOptions`].
pub async fn confirm_renewal_date_with_options(
&self,
product_subscription: &str,
params: ConfirmRenewalDateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkConfirmSubscriptionRenewalDateChangeResponseValue200ApplicationJson, Error> {
self.confirm_renewal_date_raw(product_subscription, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn confirm_renewal_date_raw(
&self,
product_subscription: &str,
params: ConfirmRenewalDateParams,
options: Option<&crate::RequestOptions>,
) -> Result<
crate::RawResponse<SdkConfirmSubscriptionRenewalDateChangeResponseValue200ApplicationJson>,
Error,
> {
let product_subscription = crate::client::path_segment(product_subscription);
let path =
format!("/v2/subscriptions/{product_subscription}/actions/change-renewal-date/confirm");
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = true;
merged.operation_id = Some("confirmSubscriptionRenewalDateChange".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/subscriptions/{productSubscription}/actions/change-renewal-date/confirm",
)
.await
}
}