class GoCardlessPro::Resources::Subscription
Subscriptions create [payments](core-endpoints-payments) according to a schedule.
### Recurrence Rules
The following rules apply when specifying recurrence:
-
The first payment must be charged within 1 year.
-
If `day_of_month` and `start_date` are not provided `start_date` will be
the [mandate](core-endpoints-mandates)'s `next_possible_charge_date` and the subscription will then recur based on the `interval` & `interval_unit`
-
If `month` or `day_of_month` are present the following validations
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:
-
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.
Attributes
Public Class Methods
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
# File lib/gocardless_pro/resources/subscription.rb, line 123 def api_response ApiResponse.new(@response) end
Return the links that the resource has
# File lib/gocardless_pro/resources/subscription.rb, line 128 def links @subscription_links ||= Links.new(@links) end
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