gocardless_pro 2.23.0 → 2.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -4
  3. data/lib/gocardless_pro.rb +27 -0
  4. data/lib/gocardless_pro/api_service.rb +4 -0
  5. data/lib/gocardless_pro/client.rb +41 -1
  6. data/lib/gocardless_pro/error/authentication_error.rb +4 -0
  7. data/lib/gocardless_pro/error/permission_error.rb +4 -0
  8. data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
  9. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
  10. data/lib/gocardless_pro/resources/bank_authorisation.rb +85 -0
  11. data/lib/gocardless_pro/resources/billing_request.rb +108 -0
  12. data/lib/gocardless_pro/resources/billing_request_flow.rb +72 -0
  13. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  14. data/lib/gocardless_pro/resources/creditor.rb +2 -3
  15. data/lib/gocardless_pro/resources/event.rb +12 -0
  16. data/lib/gocardless_pro/resources/institution.rb +45 -0
  17. data/lib/gocardless_pro/resources/payer_authorisation.rb +131 -0
  18. data/lib/gocardless_pro/resources/payout_item.rb +4 -0
  19. data/lib/gocardless_pro/resources/scenario_simulator.rb +42 -0
  20. data/lib/gocardless_pro/resources/tax_rate.rb +3 -0
  21. data/lib/gocardless_pro/resources/webhook.rb +62 -0
  22. data/lib/gocardless_pro/services/bank_authorisations_service.rb +80 -0
  23. data/lib/gocardless_pro/services/billing_request_flows_service.rb +70 -0
  24. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  25. data/lib/gocardless_pro/services/billing_requests_service.rb +352 -0
  26. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +0 -4
  27. data/lib/gocardless_pro/services/creditors_service.rb +0 -2
  28. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +0 -4
  29. data/lib/gocardless_pro/services/customers_service.rb +0 -2
  30. data/lib/gocardless_pro/services/instalment_schedules_service.rb +0 -6
  31. data/lib/gocardless_pro/services/institutions_service.rb +56 -0
  32. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  33. data/lib/gocardless_pro/services/mandates_service.rb +0 -6
  34. data/lib/gocardless_pro/services/payer_authorisations_service.rb +202 -0
  35. data/lib/gocardless_pro/services/payments_service.rb +0 -6
  36. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  37. data/lib/gocardless_pro/services/refunds_service.rb +0 -2
  38. data/lib/gocardless_pro/services/scenario_simulators_service.rb +170 -0
  39. data/lib/gocardless_pro/services/subscriptions_service.rb +10 -13
  40. data/lib/gocardless_pro/services/webhooks_service.rb +111 -0
  41. data/lib/gocardless_pro/version.rb +1 -1
  42. data/spec/api_service_spec.rb +12 -1
  43. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  44. data/spec/resources/bank_authorisation_spec.rb +259 -0
  45. data/spec/resources/billing_request_flow_spec.rb +219 -0
  46. data/spec/resources/billing_request_spec.rb +782 -0
  47. data/spec/resources/billing_request_template_spec.rb +502 -0
  48. data/spec/resources/institution_spec.rb +103 -0
  49. data/spec/resources/payer_authorisation_spec.rb +418 -0
  50. data/spec/resources/scenario_simulator_spec.rb +63 -0
  51. data/spec/resources/webhook_spec.rb +323 -0
  52. data/spec/services/bank_authorisations_service_spec.rb +353 -0
  53. data/spec/services/billing_request_flows_service_spec.rb +253 -0
  54. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  55. data/spec/services/billing_requests_service_spec.rb +1082 -0
  56. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -13
  57. data/spec/services/creditors_service_spec.rb +0 -13
  58. data/spec/services/customer_bank_accounts_service_spec.rb +0 -13
  59. data/spec/services/customers_service_spec.rb +0 -13
  60. data/spec/services/instalment_schedules_service_spec.rb +0 -26
  61. data/spec/services/institutions_service_spec.rb +223 -0
  62. data/spec/services/mandate_imports_service_spec.rb +0 -13
  63. data/spec/services/mandates_service_spec.rb +0 -13
  64. data/spec/services/payer_authorisations_service_spec.rb +559 -0
  65. data/spec/services/payments_service_spec.rb +0 -13
  66. data/spec/services/redirect_flows_service_spec.rb +0 -13
  67. data/spec/services/refunds_service_spec.rb +0 -13
  68. data/spec/services/scenario_simulators_service_spec.rb +74 -0
  69. data/spec/services/subscriptions_service_spec.rb +0 -13
  70. data/spec/services/webhooks_service_spec.rb +545 -0
  71. metadata +54 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 380e86ab83d0876327222f7966dbae08687e51cec34c468f2f57b9064a6de49b
4
- data.tar.gz: 92a6001ee0d724bb218d3d4ef6e245389842391b8d251e7b79afe6210432367a
3
+ metadata.gz: ed30309cc0e32f7ec8fe6136447f06a06b7f6b42fea7ccadd35313cd2a5ca0a1
4
+ data.tar.gz: cd88fcef318324644a91336c487e2704283e12120c938bc48bfbba5cbaa36919
5
5
  SHA512:
6
- metadata.gz: 6241d24b24dcf35224c87bf2c559c3a0c6f543ef4f3e2c73885e8aee1a4cccc9e8fb748d323df5768c9acd01510b0ae78cf8182d2d684a7feb119bd91ad0c5ac
7
- data.tar.gz: 2981ece7e5ad7cef1056ed51a02dc805c5a4c3d41ec483604e2b0ae2a552ca6cd2d2da1e7a92fa1740c9ce61b55e3fecd27c9138817bcf87a8d830047acdd552
6
+ metadata.gz: af3903ffe4dc7425072a286abc535fa379fd8d293307112d6f26b66d1ed283b7f8a440cddf833f255b13507b09ed5671d43e30773b1b50305c736ae30c84520b
7
+ data.tar.gz: c1f579f53780f7c1f96464810e2a5186fddf1d041af62f7cf975fa6d7e4304c1d149b74ff9fdf3d07985e41bb1ee46eb71ac67d556aab49343e85650e02f06b7
data/.circleci/config.yml CHANGED
@@ -13,7 +13,19 @@ jobs:
13
13
  steps:
14
14
  - checkout
15
15
  - run: bundle install && bundle exec rspec
16
-
16
+ publish: &publish
17
+ docker:
18
+ - image: ruby:2.6
19
+ steps:
20
+ - checkout
21
+ - run: |
22
+ mkdir -p $HOME/.gem
23
+ touch $HOME/.gem/credentials
24
+ chmod 0600 $HOME/.gem/credentials
25
+ printf -- "---\n:rubygems_api_key: $RUBYGEM_PUBLISH_API_KEY\n" > $HOME/.gem/credentials
26
+ gem build *.gemspec
27
+ gem push *.gem
28
+
17
29
  workflows:
18
30
  version: 2
19
31
  tests:
@@ -22,11 +34,18 @@ workflows:
22
34
  matrix:
23
35
  parameters:
24
36
  faraday-version: ["0.9.2", "1.0"]
25
- ruby-version: ["2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7"]
37
+ ruby-version: ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "3.0"]
26
38
  exclude:
27
- - faraday-version: "1.0"
28
- ruby-version: "2.0"
29
39
  - faraday-version: "1.0"
30
40
  ruby-version: "2.1"
31
41
  - faraday-version: "1.0"
32
42
  ruby-version: "2.2"
43
+ - faraday-version: "0.9.2"
44
+ ruby-version: "3.0"
45
+ - publish:
46
+ filters:
47
+ branches:
48
+ only:
49
+ - master
50
+ requires:
51
+ - test
@@ -32,15 +32,30 @@ require_relative 'gocardless_pro/error/gocardless_error'
32
32
  require_relative 'gocardless_pro/error/invalid_api_usage_error'
33
33
  require_relative 'gocardless_pro/error/invalid_state_error'
34
34
  require_relative 'gocardless_pro/error/api_error'
35
+ require_relative 'gocardless_pro/error/permission_error'
36
+ require_relative 'gocardless_pro/error/authentication_error'
37
+ require_relative 'gocardless_pro/error/rate_limit_error'
35
38
  require_relative 'gocardless_pro/paginator'
36
39
  require_relative 'gocardless_pro/request'
37
40
  require_relative 'gocardless_pro/response'
38
41
  require_relative 'gocardless_pro/api_response'
39
42
  require_relative 'gocardless_pro/webhook'
40
43
 
44
+ require_relative 'gocardless_pro/resources/bank_authorisation'
45
+ require_relative 'gocardless_pro/services/bank_authorisations_service'
46
+
41
47
  require_relative 'gocardless_pro/resources/bank_details_lookup'
42
48
  require_relative 'gocardless_pro/services/bank_details_lookups_service'
43
49
 
50
+ require_relative 'gocardless_pro/resources/billing_request'
51
+ require_relative 'gocardless_pro/services/billing_requests_service'
52
+
53
+ require_relative 'gocardless_pro/resources/billing_request_flow'
54
+ require_relative 'gocardless_pro/services/billing_request_flows_service'
55
+
56
+ require_relative 'gocardless_pro/resources/billing_request_template'
57
+ require_relative 'gocardless_pro/services/billing_request_templates_service'
58
+
44
59
  require_relative 'gocardless_pro/resources/creditor'
45
60
  require_relative 'gocardless_pro/services/creditors_service'
46
61
 
@@ -65,6 +80,9 @@ require_relative 'gocardless_pro/services/events_service'
65
80
  require_relative 'gocardless_pro/resources/instalment_schedule'
66
81
  require_relative 'gocardless_pro/services/instalment_schedules_service'
67
82
 
83
+ require_relative 'gocardless_pro/resources/institution'
84
+ require_relative 'gocardless_pro/services/institutions_service'
85
+
68
86
  require_relative 'gocardless_pro/resources/mandate'
69
87
  require_relative 'gocardless_pro/services/mandates_service'
70
88
 
@@ -77,6 +95,9 @@ require_relative 'gocardless_pro/services/mandate_import_entries_service'
77
95
  require_relative 'gocardless_pro/resources/mandate_pdf'
78
96
  require_relative 'gocardless_pro/services/mandate_pdfs_service'
79
97
 
98
+ require_relative 'gocardless_pro/resources/payer_authorisation'
99
+ require_relative 'gocardless_pro/services/payer_authorisations_service'
100
+
80
101
  require_relative 'gocardless_pro/resources/payment'
81
102
  require_relative 'gocardless_pro/services/payments_service'
82
103
 
@@ -92,10 +113,16 @@ require_relative 'gocardless_pro/services/redirect_flows_service'
92
113
  require_relative 'gocardless_pro/resources/refund'
93
114
  require_relative 'gocardless_pro/services/refunds_service'
94
115
 
116
+ require_relative 'gocardless_pro/resources/scenario_simulator'
117
+ require_relative 'gocardless_pro/services/scenario_simulators_service'
118
+
95
119
  require_relative 'gocardless_pro/resources/subscription'
96
120
  require_relative 'gocardless_pro/services/subscriptions_service'
97
121
 
98
122
  require_relative 'gocardless_pro/resources/tax_rate'
99
123
  require_relative 'gocardless_pro/services/tax_rates_service'
100
124
 
125
+ require_relative 'gocardless_pro/resources/webhook'
126
+ require_relative 'gocardless_pro/services/webhooks_service'
127
+
101
128
  require_relative 'gocardless_pro/client.rb'
@@ -34,6 +34,10 @@ module GoCardlessPro
34
34
  @headers = options[:default_headers] || {}
35
35
  @headers['Authorization'] = "Bearer #{token}"
36
36
  @on_idempotency_conflict = options[:on_idempotency_conflict] || :fetch
37
+
38
+ unless %i[fetch raise].include?(@on_idempotency_conflict)
39
+ raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
40
+ end
37
41
  end
38
42
 
39
43
  # Make a request to the API
@@ -3,11 +3,31 @@ module GoCardlessPro
3
3
  class Client
4
4
  extend Forwardable
5
5
 
6
+ # Access to the service for bank_authorisation to make API calls
7
+ def bank_authorisations
8
+ @bank_authorisations ||= Services::BankAuthorisationsService.new(@api_service)
9
+ end
10
+
6
11
  # Access to the service for bank_details_lookup to make API calls
7
12
  def bank_details_lookups
8
13
  @bank_details_lookups ||= Services::BankDetailsLookupsService.new(@api_service)
9
14
  end
10
15
 
16
+ # Access to the service for billing_request to make API calls
17
+ def billing_requests
18
+ @billing_requests ||= Services::BillingRequestsService.new(@api_service)
19
+ end
20
+
21
+ # Access to the service for billing_request_flow to make API calls
22
+ def billing_request_flows
23
+ @billing_request_flows ||= Services::BillingRequestFlowsService.new(@api_service)
24
+ end
25
+
26
+ # Access to the service for billing_request_template to make API calls
27
+ def billing_request_templates
28
+ @billing_request_templates ||= Services::BillingRequestTemplatesService.new(@api_service)
29
+ end
30
+
11
31
  # Access to the service for creditor to make API calls
12
32
  def creditors
13
33
  @creditors ||= Services::CreditorsService.new(@api_service)
@@ -48,6 +68,11 @@ module GoCardlessPro
48
68
  @instalment_schedules ||= Services::InstalmentSchedulesService.new(@api_service)
49
69
  end
50
70
 
71
+ # Access to the service for institution to make API calls
72
+ def institutions
73
+ @institutions ||= Services::InstitutionsService.new(@api_service)
74
+ end
75
+
51
76
  # Access to the service for mandate to make API calls
52
77
  def mandates
53
78
  @mandates ||= Services::MandatesService.new(@api_service)
@@ -68,6 +93,11 @@ module GoCardlessPro
68
93
  @mandate_pdfs ||= Services::MandatePdfsService.new(@api_service)
69
94
  end
70
95
 
96
+ # Access to the service for payer_authorisation to make API calls
97
+ def payer_authorisations
98
+ @payer_authorisations ||= Services::PayerAuthorisationsService.new(@api_service)
99
+ end
100
+
71
101
  # Access to the service for payment to make API calls
72
102
  def payments
73
103
  @payments ||= Services::PaymentsService.new(@api_service)
@@ -93,6 +123,11 @@ module GoCardlessPro
93
123
  @refunds ||= Services::RefundsService.new(@api_service)
94
124
  end
95
125
 
126
+ # Access to the service for scenario_simulator to make API calls
127
+ def scenario_simulators
128
+ @scenario_simulators ||= Services::ScenarioSimulatorsService.new(@api_service)
129
+ end
130
+
96
131
  # Access to the service for subscription to make API calls
97
132
  def subscriptions
98
133
  @subscriptions ||= Services::SubscriptionsService.new(@api_service)
@@ -103,6 +138,11 @@ module GoCardlessPro
103
138
  @tax_rates ||= Services::TaxRatesService.new(@api_service)
104
139
  end
105
140
 
141
+ # Access to the service for webhook to make API calls
142
+ def webhooks
143
+ @webhooks ||= Services::WebhooksService.new(@api_service)
144
+ end
145
+
106
146
  # Get a Client configured to use HTTP Basic authentication with the GC Api
107
147
  #
108
148
  # @param options [Hash<Symbol,String>] configuration for creating the client
@@ -153,7 +193,7 @@ module GoCardlessPro
153
193
  'User-Agent' => user_agent.to_s,
154
194
  'Content-Type' => 'application/json',
155
195
  'GoCardless-Client-Library' => 'gocardless-pro-ruby',
156
- 'GoCardless-Client-Version' => '2.23.0',
196
+ 'GoCardless-Client-Version' => '2.28.0',
157
197
  },
158
198
  }
159
199
  end
@@ -0,0 +1,4 @@
1
+ module GoCardlessPro
2
+ class AuthenticationError < InvalidApiUsageError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module GoCardlessPro
2
+ class PermissionError < InvalidApiUsageError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module GoCardlessPro
2
+ class RateLimitError < InvalidApiUsageError
3
+ end
4
+ end
@@ -12,12 +12,23 @@ module GoCardlessPro
12
12
  if CLIENT_ERROR_STATUSES.include?(env.status)
13
13
  json_body ||= JSON.parse(env.body) unless env.body.empty?
14
14
  error_type = json_body['error']['type']
15
- raise(error_class_for_type(error_type), json_body['error'])
15
+
16
+ error_class = error_class_for_status(env.status) || error_class_for_type(error_type)
17
+
18
+ raise(error_class, json_body['error'])
16
19
  end
17
20
  end
18
21
 
19
22
  private
20
23
 
24
+ def error_class_for_status(code)
25
+ {
26
+ 401 => GoCardlessPro::AuthenticationError,
27
+ 403 => GoCardlessPro::PermissionError,
28
+ 429 => GoCardlessPro::RateLimitError,
29
+ }.fetch(code, nil)
30
+ end
31
+
21
32
  def error_class_for_type(type)
22
33
  {
23
34
  validation_failed: GoCardlessPro::ValidationError,
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+
3
+ #
4
+ # This client is automatically generated from a template and JSON schema definition.
5
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
6
+ #
7
+
8
+ require 'uri'
9
+
10
+ module GoCardlessPro
11
+ # A module containing classes for each of the resources in the GC Api
12
+ module Resources
13
+ # Represents an instance of a bank_authorisation resource returned from the API
14
+
15
+ # Bank Authorisations can be used to authorise Billing Requests.
16
+ # Authorisations
17
+ # are created against a specific bank, usually the bank that provides the
18
+ # payer's
19
+ # account.
20
+ #
21
+ # Creation of Bank Authorisations is only permitted from GoCardless hosted
22
+ # UIs
23
+ # (see Billing Request Flows) to ensure we meet regulatory requirements for
24
+ # checkout flows.
25
+ class BankAuthorisation
26
+ attr_reader :authorisation_type
27
+ attr_reader :authorised_at
28
+ attr_reader :created_at
29
+ attr_reader :expires_at
30
+ attr_reader :id
31
+ attr_reader :last_visited_at
32
+ attr_reader :redirect_uri
33
+ attr_reader :url
34
+
35
+ # Initialize a bank_authorisation resource instance
36
+ # @param object [Hash] an object returned from the API
37
+ def initialize(object, response = nil)
38
+ @object = object
39
+
40
+ @authorisation_type = object['authorisation_type']
41
+ @authorised_at = object['authorised_at']
42
+ @created_at = object['created_at']
43
+ @expires_at = object['expires_at']
44
+ @id = object['id']
45
+ @last_visited_at = object['last_visited_at']
46
+ @links = object['links']
47
+ @redirect_uri = object['redirect_uri']
48
+ @url = object['url']
49
+ @response = response
50
+ end
51
+
52
+ def api_response
53
+ ApiResponse.new(@response)
54
+ end
55
+
56
+ # Return the links that the resource has
57
+ def links
58
+ @bank_authorisation_links ||= Links.new(@links)
59
+ end
60
+
61
+ # Provides the bank_authorisation resource as a hash of all its readable attributes
62
+ def to_h
63
+ @object
64
+ end
65
+
66
+ class Links
67
+ def initialize(links)
68
+ @links = links || {}
69
+ end
70
+
71
+ def billing_request
72
+ @links['billing_request']
73
+ end
74
+
75
+ def institution
76
+ @links['institution']
77
+ end
78
+
79
+ def payment_request
80
+ @links['payment_request']
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,108 @@
1
+ # encoding: utf-8
2
+
3
+ #
4
+ # This client is automatically generated from a template and JSON schema definition.
5
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
6
+ #
7
+
8
+ require 'uri'
9
+
10
+ module GoCardlessPro
11
+ # A module containing classes for each of the resources in the GC Api
12
+ module Resources
13
+ # Represents an instance of a billing_request resource returned from the API
14
+
15
+ # Billing Requests help create resources that require input or action from a
16
+ # customer. An example of required input might be additional customer
17
+ # billing
18
+ # details, while an action would be asking a customer to authorise a payment
19
+ # using their mobile banking app.
20
+ #
21
+ # See [Billing Requests:
22
+ # Overview](https://developer.gocardless.com/getting-started/billing-requests/overview/)
23
+ # for how-to's, explanations and tutorials.
24
+ class BillingRequest
25
+ attr_reader :actions
26
+ attr_reader :created_at
27
+ attr_reader :id
28
+ attr_reader :mandate_request
29
+ attr_reader :metadata
30
+ attr_reader :payment_request
31
+ attr_reader :resources
32
+ attr_reader :status
33
+
34
+ # Initialize a billing_request resource instance
35
+ # @param object [Hash] an object returned from the API
36
+ def initialize(object, response = nil)
37
+ @object = object
38
+
39
+ @actions = object['actions']
40
+ @created_at = object['created_at']
41
+ @id = object['id']
42
+ @links = object['links']
43
+ @mandate_request = object['mandate_request']
44
+ @metadata = object['metadata']
45
+ @payment_request = object['payment_request']
46
+ @resources = object['resources']
47
+ @status = object['status']
48
+ @response = response
49
+ end
50
+
51
+ def api_response
52
+ ApiResponse.new(@response)
53
+ end
54
+
55
+ # Return the links that the resource has
56
+ def links
57
+ @billing_request_links ||= Links.new(@links)
58
+ end
59
+
60
+ # Provides the billing_request resource as a hash of all its readable attributes
61
+ def to_h
62
+ @object
63
+ end
64
+
65
+ class Links
66
+ def initialize(links)
67
+ @links = links || {}
68
+ end
69
+
70
+ def bank_authorisation
71
+ @links['bank_authorisation']
72
+ end
73
+
74
+ def creditor
75
+ @links['creditor']
76
+ end
77
+
78
+ def customer
79
+ @links['customer']
80
+ end
81
+
82
+ def customer_bank_account
83
+ @links['customer_bank_account']
84
+ end
85
+
86
+ def customer_billing_detail
87
+ @links['customer_billing_detail']
88
+ end
89
+
90
+ def mandate_request
91
+ @links['mandate_request']
92
+ end
93
+
94
+ def mandate_request_mandate
95
+ @links['mandate_request_mandate']
96
+ end
97
+
98
+ def payment_request
99
+ @links['payment_request']
100
+ end
101
+
102
+ def payment_request_payment
103
+ @links['payment_request_payment']
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end