class GoCardless::Resources::Subscription

Subscriptions create [payments](developer.gocardless.com/pro/#api-endpoints-payments) according to a schedule.

#### Recurrence Rules

The following rules apply when specifying recurrence:

must be charged within 1 year.

are present, the subscription will recur from the ‘start_at` based on the `interval_unit`.

recurrence rules will be applied from the ‘start_at`, and the following validations apply:

| interval_unit | month

| day_of_month                            |

| :————– | :——————————————— | :————————————– | | yearly | optional (required if ‘day_of_month` provided) | optional (required if `month` provided) | | monthly | invalid

| required                                |

| weekly | invalid | invalid

|

Examples:

| interval_unit | interval | month | day_of_month | valid?

|

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

|

| yearly | 1 | march |

| invalid - missing `day_of_month`                   |

| monthly

| 6          |         | 12             | valid
                |

| monthly | 6 | august | 12

| invalid - `month` must be blank                    |

| weekly

| 2          |         |                | valid
                |

| 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:

as the ‘day_of_month`, the charge date will be rolled __backwards__ to the previous business day (i.e., the last working day of the month). - otherwise the charge date will be rolled __forwards__ to the next business day.

Represents an instance of a subscription resource returned from the API

Attributes

amount[R]
count[R]
created_at[R]
currency[R]
day_of_month[R]
end_at[R]
id[R]
interval[R]
interval_unit[R]
metadata[R]
month[R]
name[R]
start_at[R]
status[R]
upcoming_payments[R]

Public Class Methods

new(object) click to toggle source

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

# File lib/gocardless-pro/resources/subscription.rb, line 114
def initialize(object)
  @object = object

  @amount = object['amount']
  @count = object['count']
  @created_at = object['created_at']
  @currency = object['currency']
  @day_of_month = object['day_of_month']
  @end_at = object['end_at']
  @id = object['id']
  @interval = object['interval']
  @interval_unit = object['interval_unit']
  @links = object['links']
  @metadata = object['metadata']
  @month = object['month']
  @name = object['name']
  @start_at = object['start_at']
  @status = object['status']
  @upcoming_payments = object['upcoming_payments']
end

Public Instance Methods

to_h() click to toggle source

Provides the resource as a hash of all it’s readable attributes

# File lib/gocardless-pro/resources/subscription.rb, line 147
def to_h
  @object
end