Class: GoCardlessPro::Resources::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/gocardless_pro/resources/subscription.rb

Overview

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

### Recurrence Rules

The following rules apply when specifying recurrence:

  • 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.

Defined Under Namespace

Classes: Links

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, response = nil) ⇒ Subscription

Initialize a subscription resource instance



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/gocardless_pro/resources/subscription.rb', line 76

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']
   = object['metadata']
  @month = object['month']
  @name = object['name']
  @parent_plan_paused = object['parent_plan_paused']
  @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

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def amount
  @amount
end

#app_feeObject (readonly)

Returns the value of attribute app_fee.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def app_fee
  @app_fee
end

#countObject (readonly)

Returns the value of attribute count.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def count
  @count
end

#created_atObject (readonly)

Returns the value of attribute created_at.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def created_at
  @created_at
end

#currencyObject (readonly)

Returns the value of attribute currency.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def currency
  @currency
end

#day_of_monthObject (readonly)

Returns the value of attribute day_of_month.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def day_of_month
  @day_of_month
end

#earliest_charge_date_after_resumeObject (readonly)

Returns the value of attribute earliest_charge_date_after_resume.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def earliest_charge_date_after_resume
  @earliest_charge_date_after_resume
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def end_date
  @end_date
end

#idObject (readonly)

Returns the value of attribute id.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def id
  @id
end

#intervalObject (readonly)

Returns the value of attribute interval.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def interval
  @interval
end

#interval_unitObject (readonly)

Returns the value of attribute interval_unit.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def interval_unit
  @interval_unit
end

#metadataObject (readonly)

Returns the value of attribute metadata.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def 
  
end

#monthObject (readonly)

Returns the value of attribute month.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def month
  @month
end

#nameObject (readonly)

Returns the value of attribute name.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def name
  @name
end

#parent_plan_pausedObject (readonly)

Returns the value of attribute parent_plan_paused.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def parent_plan_paused
  @parent_plan_paused
end

#payment_referenceObject (readonly)

Returns the value of attribute payment_reference.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def payment_reference
  @payment_reference
end

#retry_if_possibleObject (readonly)

Returns the value of attribute retry_if_possible.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def retry_if_possible
  @retry_if_possible
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def start_date
  @start_date
end

#statusObject (readonly)

Returns the value of attribute status.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def status
  @status
end

#upcoming_paymentsObject (readonly)

Returns the value of attribute upcoming_payments.



71
72
73
# File 'lib/gocardless_pro/resources/subscription.rb', line 71

def upcoming_payments
  @upcoming_payments
end

Instance Method Details

#api_responseObject



103
104
105
# File 'lib/gocardless_pro/resources/subscription.rb', line 103

def api_response
  ApiResponse.new(@response)
end

Return the links that the resource has



108
109
110
# File 'lib/gocardless_pro/resources/subscription.rb', line 108

def links
  @subscription_links ||= Links.new(@links)
end

#to_hObject

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



113
114
115
# File 'lib/gocardless_pro/resources/subscription.rb', line 113

def to_h
  @object
end