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:
-
The first payment
must be charged within 1 year.
-
When neither ‘month` nor `day_of_month`
are present, the subscription will recur from the ‘start_at` based on the `interval_unit`.
-
If ‘month` or `day_of_month` are present, the
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:
-
if the recurrence rule specified ‘-1`
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
Public Class Methods
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
return the links that the resource has
# File lib/gocardless-pro/resources/subscription.rb, line 136 def links Struct.new( *{ mandate: '' }.keys.sort ).new(*@links.sort.map(&:last)) end
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