Skip to main content

Subscriptions

Struct Subscriptions 

Source
pub struct Subscriptions { /* private fields */ }
Expand description

Subscriptions — the core object. Access via Nombaone::subscriptions.

use nombaone::SubscriptionCreateParams;

let subscription = nombaone
    .subscriptions()
    .create(SubscriptionCreateParams {
        customer_id: "nbo000000000001cus".into(),
        price_id: "nbo000000000001prc".into(),
        payment_method_id: Some("nbo000000000001pmt".into()),
        ..Default::default()
    })
    .await?;
println!("{}", subscription.status); // "active"

Implementations§

Source§

impl Subscriptions

Source

pub fn schedule(&self) -> SubscriptionSchedules

Scheduled (next-cycle) changes.

Source

pub fn dunning(&self) -> SubscriptionDunning

Recovery/dunning state (read-only).

Source

pub fn create(&self, params: SubscriptionCreateParams) -> ApiCall<Subscription>

Create a subscription. This can move money (the first charge), so the SDK sends an Idempotency-Key automatically and reuses it across retries.

§Errors
  • 422 CLIENT_VALIDATION_FAILED — e.g. a missing payment method without a trial.
  • 409 SUBSCRIPTION_PAYMENT_METHOD_REQUIRED
Source

pub fn retrieve(&self, id: &str) -> ApiCall<Subscription>

Retrieve a subscription by id.

§Errors
  • 404 SUBSCRIPTION_NOT_FOUND
Source

pub fn update( &self, id: &str, params: SubscriptionUpdateParams, ) -> ApiCall<Subscription>

Edit metadata or the default payment method. For price/quantity/interval changes use change — those prorate.

Source

pub fn list(&self, params: SubscriptionListParams) -> Paginator<Subscription>

List subscriptions, newest first.

Source

pub fn list_events( &self, id: &str, params: ListPageParams, ) -> Paginator<DomainEvent>

The subscription’s audit trail of domain events, newest first.

Source

pub fn pause( &self, id: &str, params: SubscriptionPauseParams, ) -> ApiCall<Subscription>

Pause billing. The subscription keeps its place in the cycle and resumes cleanly.

§Errors
  • 409 SUBSCRIPTION_ILLEGAL_TRANSITION
Source

pub fn resume(&self, id: &str) -> ApiCall<Subscription>

Resume a paused subscription.

Source

pub fn cancel( &self, id: &str, params: SubscriptionCancelParams, ) -> ApiCall<Subscription>

Cancel a subscription — immediately (default) or at period end.

nombaone
    .subscriptions()
    .cancel("nbo000000000001sub", SubscriptionCancelParams {
        mode: Some(CancelMode::AtPeriodEnd),
        ..Default::default()
    })
    .await?;
Source

pub fn resubscribe( &self, id: &str, params: SubscriptionResubscribeParams, ) -> ApiCall<Subscription>

Start a fresh subscription for a canceled one’s customer, reusing the old price/payment method unless overridden. The subscription must be terminal.

§Errors
  • 409 SUBSCRIPTION_NOT_TERMINAL
Source

pub fn change( &self, id: &str, params: SubscriptionChangeParams, ) -> ApiCall<Subscription>

Change price or quantity mid-cycle, prorating by default. Switching the billing interval mid-cycle is unsupported (PRORATION_INTERVAL_SWITCH_UNSUPPORTED) — queue it with schedule().create() instead.

Source

pub fn update_payment_method( &self, id: &str, params: SubscriptionUpdatePaymentMethodParams, ) -> ApiCall<PaymentMethod>

Swap the payment method that bills this subscription — the card-update path during dunning. Exactly one of payment_method_reference or checkout_token.

Returns the attached PaymentMethod (not the subscription): this endpoint swaps the card and hands back the new payment method.

Source

pub fn retrieve_upcoming_invoice(&self, id: &str) -> ApiCall<UpcomingInvoice>

Preview the next invoice without charging or storing anything.

Source

pub fn apply_discount( &self, id: &str, params: SubscriptionApplyDiscountParams, ) -> ApiCall<Discount>

Apply a coupon to this subscription only.

Source

pub fn remove_discount(&self, id: &str) -> ApiCall<Discount>

Remove the subscription’s active discount. Returns the ended discount.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more