class GoCardlessPro::Resources::Subscription

Subscriptions create [payments](core-endpoints-payments) according to a schedule.

### Recurrence Rules

The following rules apply when specifying recurrence:

the [mandate](core-endpoints-mandates)'s `next_possible_charge_date` and the subscription will then recur based on the `interval` & `interval_unit`

apply:

| interval_unit | __month__ | day_of_month | | :—————- | :——————————————— | :—————————————– | | yearly | optional (required if `day_of_month` provided) | optional (invalid if `month` not provided) | | monthly | invalid | optional | | weekly | invalid | invalid |

Examples:

| interval_unit | __interval__ | __month__ | day_of_month | valid?

|

| :—————- | :———– | :——– | :————— | :————————————————- | | yearly | 1 | january | -1 | valid

|

| monthly | 6 | | | valid

|

| monthly | 6 | | 12 | valid

|

| weekly | 2 | | | valid

|

| yearly | 1 | march | | invalid - missing `day_of_month` | | yearly | 1 | | 2 | invalid - missing `month` | | monthly | 6 | august | 12 | invalid - `month` must be blank | | weekly | 2 | october | 10 | invalid - `month` and `day_of_month` must be blank |

### Rolling dates

When a charge date falls on a non-business day, one of two things will happen:

date will be rolled __backwards__ to the previous business day (i.e., the last working day of the month).

business day.

Attributes

amount[R]
app_fee[R]
count[R]
created_at[R]
currency[R]
day_of_month[R]
earliest_charge_date_after_resume[R]
end_date[R]
id[R]
interval[R]
interval_unit[R]
metadata[R]
month[R]
name[R]
payment_reference[R]
retry_if_possible[R]
start_date[R]
status[R]
upcoming_payments[R]

Public Class Methods

new(object, response = nil) click to toggle source

Initialize a subscription resource instance @param object [Hash] an object returned from the API

# File lib/gocardless_pro/resources/subscription.rb, line 97
def initialize(object, response = nil)
  @object = object

  @amount = object['amount']
  @app_fee = object['app_fee']
  @count = object['count']
  @created_at = object['created_at']
  @currency = object['currency']
  @day_of_month = object['day_of_month']
  @earliest_charge_date_after_resume = object['earliest_charge_date_after_resume']
  @end_date = object['end_date']
  @id = object['id']
  @interval = object['interval']
  @interval_unit = object['interval_unit']
  @links = object['links']
  @metadata = object['metadata']
  @month = object['month']
  @name = object['name']
  @payment_reference = object['payment_reference']
  @retry_if_possible = object['retry_if_possible']
  @start_date = object['start_date']
  @status = object['status']
  @upcoming_payments = object['upcoming_payments']
  @response = response
end

Public Instance Methods

api_response() click to toggle source
# File lib/gocardless_pro/resources/subscription.rb, line 123
def api_response
  ApiResponse.new(@response)
end
to_h() click to toggle source

Provides the subscription resource as a hash of all its readable attributes

# File lib/gocardless_pro/resources/subscription.rb, line 133
def to_h
  @object
end