Skip to content

Commit

Permalink
Merge pull request #66 from gocardless/template-changes
Browse files Browse the repository at this point in the history
Changes from gocardless-pro-ruby-template
  • Loading branch information
sandilya-narahari authored Apr 3, 2020
2 parents 8c8e8ce + 6e499b8 commit c186d2a
Show file tree
Hide file tree
Showing 15 changed files with 602 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/gocardless_pro/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def default_options
'User-Agent' => user_agent.to_s,
'Content-Type' => 'application/json',
'GoCardless-Client-Library' => 'gocardless-pro-ruby',
'GoCardless-Client-Version' => '2.18.0',
'GoCardless-Client-Version' => '2.18.1',
},
}
end
Expand Down
3 changes: 1 addition & 2 deletions lib/gocardless_pro/resources/creditor_bank_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ module Resources
# `links[creditor_bank_account]` in the error response.
#
# <p class="restricted-notice"><strong>Restricted</strong>: This API is not
# available for
# partner integrations.</p>
# available for partner integrations.</p>
class CreditorBankAccount
attr_reader :account_holder_name
attr_reader :account_number_ending
Expand Down
8 changes: 3 additions & 5 deletions lib/gocardless_pro/resources/customer_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ module Resources
# way, it is no longer visible using this API.
#
# <p class="restricted-notice"><strong>Restricted</strong>: This API is
# currently
# only available for approved integrators - please <a
# href="mailto:[email protected]">get
# in touch</a> if you would like to use this API.</p>
#
# currently only available for approved integrators - please <a
# href="mailto:[email protected]">get in touch</a> if you would like to
# use this API.</p>
class CustomerNotification
attr_reader :action_taken
attr_reader :action_taken_at
Expand Down
13 changes: 5 additions & 8 deletions lib/gocardless_pro/resources/mandate_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ module Resources
# system](#mandate-import-entries-list-all-mandate-import-entries).
#
# <p class="notice">Note that all Mandate Imports have an upper limit of
# 30,000 entries, so
# we recommend you split your import into several smaller imports if you're
# planning to
# exceed this threshold.</p>
# 30,000 entries, so we recommend you split your import into several smaller
# imports if you're planning to exceed this threshold.</p>
#
# <p class="restricted-notice"><strong>Restricted</strong>: This API is
# currently
# only available for approved integrators - please <a
# href="mailto:[email protected]">get
# in touch</a> if you would like to use this API.</p>
# currently only available for approved integrators - please <a
# href="mailto:[email protected]">get in touch</a> if you would like to
# use this API.</p>
class MandateImport
attr_reader :created_at
attr_reader :id
Expand Down
8 changes: 3 additions & 5 deletions lib/gocardless_pro/resources/mandate_import_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ module Resources
# been imported.
#
# <p class="restricted-notice"><strong>Restricted</strong>: This API is
# currently
# only available for approved integrators - please <a
# href="mailto:[email protected]">get
# in touch</a> if you would like to use this API.</p>
#
# currently only available for approved integrators - please <a
# href="mailto:[email protected]">get in touch</a> if you would like to
# use this API.</p>
class MandateImportEntry
attr_reader :created_at
attr_reader :record_identifier
Expand Down
2 changes: 2 additions & 0 deletions lib/gocardless_pro/resources/redirect_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class RedirectFlow
attr_reader :created_at
attr_reader :description
attr_reader :id
attr_reader :metadata
attr_reader :redirect_url
attr_reader :scheme
attr_reader :session_token
Expand All @@ -64,6 +65,7 @@ def initialize(object, response = nil)
@description = object['description']
@id = object['id']
@links = object['links']
@metadata = object['metadata']
@redirect_url = object['redirect_url']
@scheme = object['scheme']
@session_token = object['session_token']
Expand Down
65 changes: 36 additions & 29 deletions lib/gocardless_pro/resources/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,45 @@ module Resources
# 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_date` based on the `interval_unit`.
# - If `month` or `day_of_month` are present, the recurrence rules will be
# applied from the `start_date`, and the following validations apply:
# - 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 (required if `month` provided) |
# | monthly | invalid |
# required |
# | weekly | invalid |
# invalid |
# | __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?
# |
# | :-------------- | :--------- | :------ | :------------- |
# | __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 |
# | 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
#
Expand All @@ -73,6 +78,7 @@ class Subscription
attr_reader :created_at
attr_reader :currency
attr_reader :day_of_month
attr_reader :earliest_charge_date_after_resume
attr_reader :end_date
attr_reader :id
attr_reader :interval
Expand All @@ -97,6 +103,7 @@ def initialize(object, response = nil)
@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']
Expand Down
3 changes: 1 addition & 2 deletions lib/gocardless_pro/services/customers_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def update(identity, options = {})
# ID.
#
# <p class="restricted-notice"><strong>The action of removing a customer cannot
# be
# reversed, so please use with care.</strong></p>
# be reversed, so please use with care.</strong></p>
# Example URL: /customers/:identity
#
# @param identity # Unique identifier, beginning with "CU".
Expand Down
2 changes: 1 addition & 1 deletion lib/gocardless_pro/services/mandates_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def cancel(identity, options = {})
# This will fail with a `mandate_not_inactive` error if the mandate is already
# being submitted, or is active.
#
# Mandates can be resubmitted up to 3 times.
# Mandates can be resubmitted up to 10 times.
# Example URL: /mandates/:identity/actions/reinstate
#
# @param identity # Unique identifier, beginning with "MD". Note that this prefix may not
Expand Down
114 changes: 114 additions & 0 deletions lib/gocardless_pro/services/subscriptions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,120 @@ def update(identity, options = {})
Resources::Subscription.new(unenvelope_body(response.body), response)
end

# Pause a subscription object.
# No payments will be created until it is resumed.
#
# This can only be used with subscriptions created with `count` or
# subscriptions without `count` and `end_date`
# If the subscription has `count` its `end_date` will be `null` after pausing.
#
# This fails with:
#
# - `forbidden` if the subscription was created by an app and you are not
# authenticated as that app, or if the subscription was not created by an app
# and you are authenticated as an app
#
# - `validation_failed` if invalid data is provided when attempting to pause a
# subscription.
#
# - `subscription_not_active` if the subscription is no longer active.
#
# - `subscription_already_ended` if the subscription has taken all payments.
#
# Example URL: /subscriptions/:identity/actions/pause
#
# @param identity # Unique identifier, beginning with "SB".
# @param options [Hash] parameters as a hash, under a params key.
def pause(identity, options = {})
path = sub_url('/subscriptions/:identity/actions/pause', 'identity' => identity)

params = options.delete(:params) || {}
options[:params] = {}
options[:params]['data'] = params

options[:retry_failures] = false

begin
response = make_request(:post, path, options)

# Response doesn't raise any errors until #body is called
response.tap(&:body)
rescue InvalidStateError => e
if e.idempotent_creation_conflict?
case @api_service.on_idempotency_conflict
when :raise
raise IdempotencyConflict, e.error
when :fetch
return get(e.conflicting_resource_id)
else
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
end
end

raise e
end

return if response.body.nil?

Resources::Subscription.new(unenvelope_body(response.body), response)
end

# Resume a subscription object.
# Payments will start to be created again based on the subscriptions recurrence
# rules.
#
# This fails with:
#
# - `forbidden` if the subscription was created by an app and you are not
# authenticated as that app, or if the subscription was not created by an app
# and you are authenticated as an app
#
# - `validation_failed` if invalid data is provided when attempting to resume a
# subscription.
#
# - `subscription_not_paused` if the subscription is not paused.
#
# - `subscription_already_scheduled_to_resume` if a subscription already has a
# scheduled resume date.
#
# Example URL: /subscriptions/:identity/actions/resume
#
# @param identity # Unique identifier, beginning with "SB".
# @param options [Hash] parameters as a hash, under a params key.
def resume(identity, options = {})
path = sub_url('/subscriptions/:identity/actions/resume', 'identity' => identity)

params = options.delete(:params) || {}
options[:params] = {}
options[:params]['data'] = params

options[:retry_failures] = false

begin
response = make_request(:post, path, options)

# Response doesn't raise any errors until #body is called
response.tap(&:body)
rescue InvalidStateError => e
if e.idempotent_creation_conflict?
case @api_service.on_idempotency_conflict
when :raise
raise IdempotencyConflict, e.error
when :fetch
return get(e.conflicting_resource_id)
else
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
end
end

raise e
end

return if response.body.nil?

Resources::Subscription.new(unenvelope_body(response.body), response)
end

# Immediately cancels a subscription; no more payments will be created under it.
# Any metadata supplied to this endpoint will be stored on the payment
# cancellation event it causes.
Expand Down
2 changes: 1 addition & 1 deletion lib/gocardless_pro/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module GoCardlessPro

module GoCardlessPro
# Current version of the GC gem
VERSION = '2.18.0'.freeze
VERSION = '2.18.1'.freeze
end
9 changes: 9 additions & 0 deletions spec/resources/redirect_flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand All @@ -38,6 +39,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand All @@ -56,6 +58,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand Down Expand Up @@ -107,6 +110,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand Down Expand Up @@ -148,6 +152,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand Down Expand Up @@ -185,6 +190,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand Down Expand Up @@ -219,6 +225,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand Down Expand Up @@ -274,6 +281,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand Down Expand Up @@ -313,6 +321,7 @@
'description' => 'description-input',
'id' => 'id-input',
'links' => 'links-input',
'metadata' => 'metadata-input',
'redirect_url' => 'redirect_url-input',
'scheme' => 'scheme-input',
'session_token' => 'session_token-input',
Expand Down
Loading

0 comments on commit c186d2a

Please sign in to comment.