Class: Airwallex::BillingSubscription

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List, APIOperations::Retrieve
Includes:
APIOperations::Update
Defined in:
lib/airwallex/resources/billing_subscription.rb

Overview

Represents a Billing subscription, e.g. a multi-part instalment plan.

Examples:

Create a subscription with a deferred start date

# Flat payload, no wrapper key. Prices attach via an items: array of
# { price_id:, quantity: }, not a flat price_id. legal_entity_id comes
# from ConnectedAccount#legal_entity_id, not a separate resource.
# payment_source_id references a PaymentSource (see
# Airwallex::PaymentSource for the full consent -> source -> subscription
# chain), not a PaymentConsent directly.
 = Airwallex::ConnectedAccount.retrieve("acct_123")
subscription = Airwallex::BillingSubscription.create(
  billing_customer_id: billing_customer.id,
  currency: "AUD",
  collection_method: "AUTO_CHARGE",
  legal_entity_id: .legal_entity_id,
  payment_source_id: payment_source.id,
  starts_at: "2026-09-01T00:00:00+1000",
  items: [{ price_id: price.id, quantity: 1 }]
)
subscription.status #=> "PENDING"

Cancel a subscription

subscription.cancel

Instance Attribute Summary

Attributes inherited from APIResource

#attributes, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::Retrieve

retrieve

Methods included from APIOperations::List

list

Methods included from APIOperations::Update

included, #save, #update

Methods inherited from APIResource

#changed_attributes, #dirty?, #initialize, #inspect, #method_missing, #refresh, #refresh_from, resource_name, #respond_to_missing?, #to_hash, #to_json, #to_s

Constructor Details

This class inherits a constructor from Airwallex::APIResource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Airwallex::APIResource

Class Method Details

.resource_pathString

Returns API resource path for billing subscriptions.

Returns:

  • (String)

    API resource path for billing subscriptions



34
35
36
# File 'lib/airwallex/resources/billing_subscription.rb', line 34

def self.resource_path
  "/api/v1/billing/subscriptions"
end

Instance Method Details

#cancel(params = {}) ⇒ BillingSubscription

Cancel this subscription

Parameters:

  • params (Hash) (defaults to: {})

    additional cancellation params

Returns:



42
43
44
45
46
# File 'lib/airwallex/resources/billing_subscription.rb', line 42

def cancel(params = {})
  response = Airwallex.client.post("#{self.class.resource_path}/#{id}/cancel", params)
  refresh_from(response)
  self
end

#item(item_id) ⇒ BillingSubscriptionItem

Retrieve a single line item on this subscription

Parameters:

  • item_id (String)

    the subscription item id

Returns:



68
69
70
71
# File 'lib/airwallex/resources/billing_subscription.rb', line 68

def item(item_id)
  response = Airwallex.client.get("#{self.class.resource_path}/#{id}/items/#{item_id}")
  BillingSubscriptionItem.new(response)
end

#items(params = {}) ⇒ ListObject<BillingSubscriptionItem>

List the line items on this subscription

Parameters:

  • params (Hash) (defaults to: {})

    additional query params (e.g. pagination)

Returns:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/airwallex/resources/billing_subscription.rb', line 52

def items(params = {})
  response = Airwallex.client.get("#{self.class.resource_path}/#{id}/items", params)

  ListObject.new(
    data: extract_item_rows(response),
    has_more: extract_has_more(response),
    next_cursor: extract_next_cursor(response),
    resource_class: BillingSubscriptionItem,
    params: params
  )
end