gocardless_pro 4.2.0 → 4.4.1

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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -12
  3. data/lib/gocardless_pro/client.rb +33 -3
  4. data/lib/gocardless_pro/error.rb +3 -3
  5. data/lib/gocardless_pro/list_response.rb +2 -2
  6. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +11 -3
  7. data/lib/gocardless_pro/paginator.rb +3 -2
  8. data/lib/gocardless_pro/resources/balance.rb +4 -1
  9. data/lib/gocardless_pro/resources/bank_account_detail.rb +5 -1
  10. data/lib/gocardless_pro/resources/bank_account_holder_verification.rb +44 -0
  11. data/lib/gocardless_pro/resources/bank_authorisation.rb +9 -2
  12. data/lib/gocardless_pro/resources/bank_details_lookup.rb +3 -1
  13. data/lib/gocardless_pro/resources/billing_request.rb +24 -10
  14. data/lib/gocardless_pro/resources/billing_request_flow.rb +18 -2
  15. data/lib/gocardless_pro/resources/billing_request_template.rb +18 -2
  16. data/lib/gocardless_pro/resources/billing_request_with_action.rb +6 -5
  17. data/lib/gocardless_pro/resources/block.rb +12 -8
  18. data/lib/gocardless_pro/resources/creditor.rb +26 -6
  19. data/lib/gocardless_pro/resources/creditor_bank_account.rb +17 -7
  20. data/lib/gocardless_pro/resources/currency_exchange_rate.rb +4 -1
  21. data/lib/gocardless_pro/resources/customer.rb +22 -5
  22. data/lib/gocardless_pro/resources/customer_bank_account.rb +24 -10
  23. data/lib/gocardless_pro/resources/customer_notification.rb +8 -5
  24. data/lib/gocardless_pro/resources/event.rb +31 -4
  25. data/lib/gocardless_pro/resources/export.rb +7 -1
  26. data/lib/gocardless_pro/resources/funds_availability.rb +38 -0
  27. data/lib/gocardless_pro/resources/instalment_schedule.rb +8 -2
  28. data/lib/gocardless_pro/resources/institution.rb +11 -4
  29. data/lib/gocardless_pro/resources/logo.rb +2 -1
  30. data/lib/gocardless_pro/resources/mandate.rb +21 -6
  31. data/lib/gocardless_pro/resources/mandate_import.rb +29 -22
  32. data/lib/gocardless_pro/resources/mandate_import_entry.rb +16 -17
  33. data/lib/gocardless_pro/resources/mandate_pdf.rb +5 -4
  34. data/lib/gocardless_pro/resources/negative_balance_limit.rb +4 -2
  35. data/lib/gocardless_pro/resources/outbound_payment.rb +33 -12
  36. data/lib/gocardless_pro/resources/outbound_payment_import.rb +81 -0
  37. data/lib/gocardless_pro/resources/outbound_payment_import_entry.rb +77 -0
  38. data/lib/gocardless_pro/resources/payer_authorisation.rb +34 -32
  39. data/lib/gocardless_pro/resources/payment.rb +24 -8
  40. data/lib/gocardless_pro/resources/payment_account.rb +64 -0
  41. data/lib/gocardless_pro/resources/payment_account_transaction.rb +79 -0
  42. data/lib/gocardless_pro/resources/payout.rb +19 -8
  43. data/lib/gocardless_pro/resources/payout_item.rb +4 -3
  44. data/lib/gocardless_pro/resources/redirect_flow.rb +44 -25
  45. data/lib/gocardless_pro/resources/refund.rb +16 -7
  46. data/lib/gocardless_pro/resources/scheme_identifier.rb +18 -3
  47. data/lib/gocardless_pro/resources/subscription.rb +37 -16
  48. data/lib/gocardless_pro/resources/tax_rate.rb +8 -3
  49. data/lib/gocardless_pro/resources/transferred_mandate.rb +3 -1
  50. data/lib/gocardless_pro/resources/verification_detail.rb +19 -8
  51. data/lib/gocardless_pro/resources/webhook.rb +13 -2
  52. data/lib/gocardless_pro/services/balances_service.rb +11 -3
  53. data/lib/gocardless_pro/services/bank_account_details_service.rb +14 -3
  54. data/lib/gocardless_pro/services/bank_account_holder_verifications_service.rb +92 -0
  55. data/lib/gocardless_pro/services/bank_authorisations_service.rb +9 -3
  56. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +14 -6
  57. data/lib/gocardless_pro/services/billing_request_flows_service.rb +8 -2
  58. data/lib/gocardless_pro/services/billing_request_templates_service.rb +14 -7
  59. data/lib/gocardless_pro/services/billing_request_with_actions_service.rb +7 -1
  60. data/lib/gocardless_pro/services/billing_requests_service.rb +38 -33
  61. data/lib/gocardless_pro/services/blocks_service.rb +17 -10
  62. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +14 -7
  63. data/lib/gocardless_pro/services/creditors_service.rb +13 -6
  64. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +10 -3
  65. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +25 -15
  66. data/lib/gocardless_pro/services/customer_notifications_service.rb +8 -3
  67. data/lib/gocardless_pro/services/customers_service.rb +15 -9
  68. data/lib/gocardless_pro/services/events_service.rb +16 -4
  69. data/lib/gocardless_pro/services/exports_service.rb +8 -2
  70. data/lib/gocardless_pro/services/funds_availabilities_service.rb +56 -0
  71. data/lib/gocardless_pro/services/instalment_schedules_service.rb +21 -13
  72. data/lib/gocardless_pro/services/institutions_service.rb +8 -2
  73. data/lib/gocardless_pro/services/logos_service.rb +9 -3
  74. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +10 -4
  75. data/lib/gocardless_pro/services/mandate_imports_service.rb +16 -8
  76. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +11 -5
  77. data/lib/gocardless_pro/services/mandates_service.rb +23 -16
  78. data/lib/gocardless_pro/services/negative_balance_limits_service.rb +10 -3
  79. data/lib/gocardless_pro/services/outbound_payment_import_entries_service.rb +64 -0
  80. data/lib/gocardless_pro/services/outbound_payment_imports_service.rb +118 -0
  81. data/lib/gocardless_pro/services/outbound_payments_service.rb +34 -12
  82. data/lib/gocardless_pro/services/payer_authorisations_service.rb +18 -15
  83. data/lib/gocardless_pro/services/payer_themes_service.rb +7 -1
  84. data/lib/gocardless_pro/services/payment_account_transactions_service.rb +93 -0
  85. data/lib/gocardless_pro/services/payment_accounts_service.rb +83 -0
  86. data/lib/gocardless_pro/services/payments_service.rb +29 -21
  87. data/lib/gocardless_pro/services/payout_items_service.rb +12 -7
  88. data/lib/gocardless_pro/services/payouts_service.rb +14 -7
  89. data/lib/gocardless_pro/services/redirect_flows_service.rb +19 -9
  90. data/lib/gocardless_pro/services/refunds_service.rb +18 -13
  91. data/lib/gocardless_pro/services/scenario_simulators_service.rb +90 -81
  92. data/lib/gocardless_pro/services/scheme_identifiers_service.rb +15 -9
  93. data/lib/gocardless_pro/services/subscriptions_service.rb +57 -47
  94. data/lib/gocardless_pro/services/tax_rates_service.rb +11 -4
  95. data/lib/gocardless_pro/services/transferred_mandates_service.rb +8 -2
  96. data/lib/gocardless_pro/services/verification_details_service.rb +7 -1
  97. data/lib/gocardless_pro/services/webhooks_service.rb +13 -6
  98. data/lib/gocardless_pro/version.rb +1 -1
  99. data/lib/gocardless_pro/webhook.rb +45 -0
  100. data/lib/gocardless_pro.rb +18 -0
  101. metadata +38 -16
@@ -0,0 +1,64 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # This client is automatically generated from a template and JSON schema definition.
6
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
7
+ #
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the OutboundPaymentImportEntry endpoints
12
+ class OutboundPaymentImportEntriesService < BaseService
13
+ # Returns a cursor-paginated
14
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
15
+ # list of the entries for a given outbound payment import.
16
+ # Example URL: /outbound_payment_import_entries
17
+ # @param options [Hash] parameters as a hash, under a params key.
18
+ def list(options = {})
19
+ path = '/outbound_payment_import_entries'
20
+
21
+ options[:retry_failures] = true
22
+
23
+ response = make_request(:get, path, options)
24
+
25
+ ListResponse.new(
26
+ response: response,
27
+ unenveloped_body: unenvelope_body(response.body),
28
+ resource_class: Resources::OutboundPaymentImportEntry
29
+ )
30
+ end
31
+
32
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
33
+ #
34
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
35
+ # Otherwise they will be the body of the request.
36
+ def all(options = {})
37
+ Paginator.new(
38
+ service: self,
39
+ options: options
40
+ ).enumerator
41
+ end
42
+
43
+ private
44
+
45
+ # Unenvelope the response of the body using the service's `envelope_key`
46
+ #
47
+ # @param body [Hash]
48
+ def unenvelope_body(body)
49
+ if body.key?(envelope_key)
50
+ body[envelope_key]
51
+ elsif body.key?('data')
52
+ body['data']
53
+ else
54
+ body
55
+ end
56
+ end
57
+
58
+ # return the key which API responses will envelope data under
59
+ def envelope_key
60
+ 'outbound_payment_import_entries'
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,118 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # This client is automatically generated from a template and JSON schema definition.
6
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
7
+ #
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the OutboundPaymentImport endpoints
12
+ class OutboundPaymentImportsService < BaseService
13
+ #
14
+ # Example URL: /outbound_payment_imports
15
+ # @param options [Hash] parameters as a hash, under a params key.
16
+ def create(options = {})
17
+ path = '/outbound_payment_imports'
18
+
19
+ params = options.delete(:params) || {}
20
+ options[:params] = {}
21
+ options[:params][envelope_key] = params
22
+
23
+ options[:retry_failures] = true
24
+
25
+ begin
26
+ response = make_request(:post, path, options)
27
+
28
+ # Response doesn't raise any errors until #body is called
29
+ response.tap(&:body)
30
+ rescue InvalidStateError => e
31
+ if e.idempotent_creation_conflict?
32
+ case @api_service.on_idempotency_conflict
33
+ when :raise
34
+ raise IdempotencyConflict.new(e.error)
35
+ when :fetch
36
+ return get(e.conflicting_resource_id)
37
+ end
38
+ end
39
+
40
+ raise e
41
+ end
42
+
43
+ return if response.body.nil?
44
+
45
+ Resources::OutboundPaymentImport.new(unenvelope_body(response.body), response)
46
+ end
47
+
48
+ # Returns a single outbound payment import.
49
+ # Example URL: /outbound_payment_imports/:identity
50
+ #
51
+ # @param identity # Unique identifier, beginning with "IM".
52
+ # @param options [Hash] parameters as a hash, under a params key.
53
+ def get(identity, options = {})
54
+ path = sub_url('/outbound_payment_imports/:identity', {
55
+ 'identity' => identity,
56
+ })
57
+
58
+ options[:retry_failures] = true
59
+
60
+ response = make_request(:get, path, options)
61
+
62
+ return if response.body.nil?
63
+
64
+ Resources::OutboundPaymentImport.new(unenvelope_body(response.body), response)
65
+ end
66
+
67
+ # Returns a cursor-paginated
68
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
69
+ # list of your outbound payment imports.
70
+ # Example URL: /outbound_payment_imports
71
+ # @param options [Hash] parameters as a hash, under a params key.
72
+ def list(options = {})
73
+ path = '/outbound_payment_imports'
74
+
75
+ options[:retry_failures] = true
76
+
77
+ response = make_request(:get, path, options)
78
+
79
+ ListResponse.new(
80
+ response: response,
81
+ unenveloped_body: unenvelope_body(response.body),
82
+ resource_class: Resources::OutboundPaymentImport
83
+ )
84
+ end
85
+
86
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
87
+ #
88
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
89
+ # Otherwise they will be the body of the request.
90
+ def all(options = {})
91
+ Paginator.new(
92
+ service: self,
93
+ options: options
94
+ ).enumerator
95
+ end
96
+
97
+ private
98
+
99
+ # Unenvelope the response of the body using the service's `envelope_key`
100
+ #
101
+ # @param body [Hash]
102
+ def unenvelope_body(body)
103
+ if body.key?(envelope_key)
104
+ body[envelope_key]
105
+ elsif body.key?('data')
106
+ body['data']
107
+ else
108
+ body
109
+ end
110
+ end
111
+
112
+ # return the key which API responses will envelope data under
113
+ def envelope_key
114
+ 'outbound_payment_imports'
115
+ end
116
+ end
117
+ end
118
+ end
@@ -31,7 +31,7 @@ module GoCardlessPro
31
31
  if e.idempotent_creation_conflict?
32
32
  case @api_service.on_idempotency_conflict
33
33
  when :raise
34
- raise IdempotencyConflict, e.error
34
+ raise IdempotencyConflict.new(e.error)
35
35
  when :fetch
36
36
  return get(e.conflicting_resource_id)
37
37
  end
@@ -67,7 +67,7 @@ module GoCardlessPro
67
67
  if e.idempotent_creation_conflict?
68
68
  case @api_service.on_idempotency_conflict
69
69
  when :raise
70
- raise IdempotencyConflict, e.error
70
+ raise IdempotencyConflict.new(e.error)
71
71
  when :fetch
72
72
  return get(e.conflicting_resource_id)
73
73
  end
@@ -91,7 +91,7 @@ module GoCardlessPro
91
91
  # @param options [Hash] parameters as a hash, under a params key.
92
92
  def cancel(identity, options = {})
93
93
  path = sub_url('/outbound_payments/:identity/actions/cancel', {
94
- 'identity' => identity
94
+ 'identity' => identity,
95
95
  })
96
96
 
97
97
  params = options.delete(:params) || {}
@@ -109,7 +109,7 @@ module GoCardlessPro
109
109
  if e.idempotent_creation_conflict?
110
110
  case @api_service.on_idempotency_conflict
111
111
  when :raise
112
- raise IdempotencyConflict, e.error
112
+ raise IdempotencyConflict.new(e.error)
113
113
  when :fetch
114
114
  return get(e.conflicting_resource_id)
115
115
  end
@@ -124,14 +124,14 @@ module GoCardlessPro
124
124
  end
125
125
 
126
126
  # Approves an outbound payment. Only outbound payments with the
127
- # pending_approval status can be approved.
127
+ # "pending_approval" status can be approved.
128
128
  # Example URL: /outbound_payments/:identity/actions/approve
129
129
  #
130
130
  # @param identity # Unique identifier of the outbound payment.
131
131
  # @param options [Hash] parameters as a hash, under a params key.
132
132
  def approve(identity, options = {})
133
133
  path = sub_url('/outbound_payments/:identity/actions/approve', {
134
- 'identity' => identity
134
+ 'identity' => identity,
135
135
  })
136
136
 
137
137
  params = options.delete(:params) || {}
@@ -149,7 +149,7 @@ module GoCardlessPro
149
149
  if e.idempotent_creation_conflict?
150
150
  case @api_service.on_idempotency_conflict
151
151
  when :raise
152
- raise IdempotencyConflict, e.error
152
+ raise IdempotencyConflict.new(e.error)
153
153
  when :fetch
154
154
  return get(e.conflicting_resource_id)
155
155
  end
@@ -170,7 +170,7 @@ module GoCardlessPro
170
170
  # @param options [Hash] parameters as a hash, under a params key.
171
171
  def get(identity, options = {})
172
172
  path = sub_url('/outbound_payments/:identity', {
173
- 'identity' => identity
173
+ 'identity' => identity,
174
174
  })
175
175
 
176
176
  options[:retry_failures] = true
@@ -182,8 +182,9 @@ module GoCardlessPro
182
182
  Resources::OutboundPayment.new(unenvelope_body(response.body), response)
183
183
  end
184
184
 
185
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of outbound
186
- # payments.
185
+ # Returns a cursor-paginated
186
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
187
+ # list of outbound payments.
187
188
  # Example URL: /outbound_payments
188
189
  # @param options [Hash] parameters as a hash, under a params key.
189
190
  def list(options = {})
@@ -218,7 +219,7 @@ module GoCardlessPro
218
219
  # @param options [Hash] parameters as a hash, under a params key.
219
220
  def update(identity, options = {})
220
221
  path = sub_url('/outbound_payments/:identity', {
221
- 'identity' => identity
222
+ 'identity' => identity,
222
223
  })
223
224
 
224
225
  params = options.delete(:params) || {}
@@ -234,13 +235,34 @@ module GoCardlessPro
234
235
  Resources::OutboundPayment.new(unenvelope_body(response.body), response)
235
236
  end
236
237
 
238
+ # Retrieve aggregate statistics on outbound payments.
239
+ # Example URL: /outbound_payments/stats
240
+ # @param options [Hash] parameters as a hash, under a params key.
241
+ def stats(options = {})
242
+ path = '/outbound_payments/stats'
243
+
244
+ options[:retry_failures] = false
245
+
246
+ response = make_request(:get, path, options)
247
+
248
+ return if response.body.nil?
249
+
250
+ Resources::OutboundPayment.new(unenvelope_body(response.body), response)
251
+ end
252
+
237
253
  private
238
254
 
239
255
  # Unenvelope the response of the body using the service's `envelope_key`
240
256
  #
241
257
  # @param body [Hash]
242
258
  def unenvelope_body(body)
243
- body[envelope_key] || body['data']
259
+ if body.key?(envelope_key)
260
+ body[envelope_key]
261
+ elsif body.key?('data')
262
+ body['data']
263
+ else
264
+ body
265
+ end
244
266
  end
245
267
 
246
268
  # return the key which API responses will envelope data under
@@ -18,7 +18,7 @@ module GoCardlessPro
18
18
  # @param options [Hash] parameters as a hash, under a params key.
19
19
  def get(identity, options = {})
20
20
  path = sub_url('/payer_authorisations/:identity', {
21
- 'identity' => identity
21
+ 'identity' => identity,
22
22
  })
23
23
 
24
24
  options[:retry_failures] = true
@@ -56,7 +56,7 @@ module GoCardlessPro
56
56
  if e.idempotent_creation_conflict?
57
57
  case @api_service.on_idempotency_conflict
58
58
  when :raise
59
- raise IdempotencyConflict, e.error
59
+ raise IdempotencyConflict.new(e.error)
60
60
  when :fetch
61
61
  return get(e.conflicting_resource_id)
62
62
  end
@@ -75,17 +75,16 @@ module GoCardlessPro
75
75
  # the request will be modified. An empty array of incomplete_fields means that
76
76
  # the resource is valid. This endpoint has been designed this way so you do not
77
77
  # need to save any payer data on your servers or the browser while still being
78
- # able to implement a progressive solution, such a multi-step form. <p
79
- # class="notice"> Note that in order to update the `metadata` attribute values
80
- # it must be sent completely as it overrides the previously existing values.
81
- # </p>
78
+ # able to implement a progressive solution, such a multi-step form. Note that
79
+ # in order to update the `metadata` attribute values it must be sent completely
80
+ # as it overrides the previously existing values.
82
81
  # Example URL: /payer_authorisations/:identity
83
82
  #
84
83
  # @param identity # Unique identifier, beginning with "PA".
85
84
  # @param options [Hash] parameters as a hash, under a params key.
86
85
  def update(identity, options = {})
87
86
  path = sub_url('/payer_authorisations/:identity', {
88
- 'identity' => identity
87
+ 'identity' => identity,
89
88
  })
90
89
 
91
90
  params = options.delete(:params) || {}
@@ -111,7 +110,7 @@ module GoCardlessPro
111
110
  # @param options [Hash] parameters as a hash, under a params key.
112
111
  def submit(identity, options = {})
113
112
  path = sub_url('/payer_authorisations/:identity/actions/submit', {
114
- 'identity' => identity
113
+ 'identity' => identity,
115
114
  })
116
115
 
117
116
  params = options.delete(:params) || {}
@@ -129,7 +128,7 @@ module GoCardlessPro
129
128
  if e.idempotent_creation_conflict?
130
129
  case @api_service.on_idempotency_conflict
131
130
  when :raise
132
- raise IdempotencyConflict, e.error
131
+ raise IdempotencyConflict.new(e.error)
133
132
  when :fetch
134
133
  return get(e.conflicting_resource_id)
135
134
  end
@@ -147,20 +146,18 @@ module GoCardlessPro
147
146
  # be created.
148
147
  # A Payer Authorisation cannot be confirmed if it hasn't been submitted yet.
149
148
  #
150
- # <p class="notice">
151
149
  # The main use of the confirm endpoint is to enable integrators to acknowledge
152
150
  # the end of the setup process.
153
- # They might want to make the payers go through some other steps after they go
151
+ # They might want to make the payers go through some other steps after they go
154
152
  # through our flow or make them go through the necessary verification mechanism
155
153
  # (upcoming feature).
156
- # </p>
157
154
  # Example URL: /payer_authorisations/:identity/actions/confirm
158
155
  #
159
156
  # @param identity # Unique identifier, beginning with "PA".
160
157
  # @param options [Hash] parameters as a hash, under a params key.
161
158
  def confirm(identity, options = {})
162
159
  path = sub_url('/payer_authorisations/:identity/actions/confirm', {
163
- 'identity' => identity
160
+ 'identity' => identity,
164
161
  })
165
162
 
166
163
  params = options.delete(:params) || {}
@@ -178,7 +175,7 @@ module GoCardlessPro
178
175
  if e.idempotent_creation_conflict?
179
176
  case @api_service.on_idempotency_conflict
180
177
  when :raise
181
- raise IdempotencyConflict, e.error
178
+ raise IdempotencyConflict.new(e.error)
182
179
  when :fetch
183
180
  return get(e.conflicting_resource_id)
184
181
  end
@@ -198,7 +195,13 @@ module GoCardlessPro
198
195
  #
199
196
  # @param body [Hash]
200
197
  def unenvelope_body(body)
201
- body[envelope_key] || body['data']
198
+ if body.key?(envelope_key)
199
+ body[envelope_key]
200
+ elsif body.key?('data')
201
+ body['data']
202
+ else
203
+ body
204
+ end
202
205
  end
203
206
 
204
207
  # return the key which API responses will envelope data under
@@ -37,7 +37,13 @@ module GoCardlessPro
37
37
  #
38
38
  # @param body [Hash]
39
39
  def unenvelope_body(body)
40
- body[envelope_key] || body['data']
40
+ if body.key?(envelope_key)
41
+ body[envelope_key]
42
+ elsif body.key?('data')
43
+ body['data']
44
+ else
45
+ body
46
+ end
41
47
  end
42
48
 
43
49
  # return the key which API responses will envelope data under
@@ -0,0 +1,93 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # This client is automatically generated from a template and JSON schema definition.
6
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
7
+ #
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the PaymentAccountTransaction endpoints
12
+ class PaymentAccountTransactionsService < BaseService
13
+ # Retrieves the details of an existing payment account transaction.
14
+ # Example URL: /payment_account_transactions/:identity
15
+ #
16
+ # @param identity # The unique ID of the bank account
17
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-creditor-bank-accounts)
18
+ # which happens to be the payment account.
19
+ # @param options [Hash] parameters as a hash, under a params key.
20
+ def get(identity, options = {})
21
+ path = sub_url('/payment_account_transactions/:identity', {
22
+ 'identity' => identity,
23
+ })
24
+
25
+ options[:retry_failures] = true
26
+
27
+ response = make_request(:get, path, options)
28
+
29
+ return if response.body.nil?
30
+
31
+ Resources::PaymentAccountTransaction.new(unenvelope_body(response.body), response)
32
+ end
33
+
34
+ # List transactions for a given payment account.
35
+ # Example URL: /payment_accounts/:identity/transactions
36
+ #
37
+ # @param identity # The unique ID of the bank account
38
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-creditor-bank-accounts)
39
+ # which happens to be the payment account.
40
+ # @param options [Hash] parameters as a hash, under a params key.
41
+ def list(identity, options = {})
42
+ path = sub_url('/payment_accounts/:identity/transactions', {
43
+ 'identity' => identity,
44
+ })
45
+
46
+ options[:retry_failures] = true
47
+
48
+ response = make_request(:get, path, options)
49
+
50
+ ListResponse.new(
51
+ response: response,
52
+ unenveloped_body: unenvelope_body(response.body),
53
+ resource_class: Resources::PaymentAccountTransaction
54
+ )
55
+ end
56
+
57
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
58
+ #
59
+ # @param identity # The unique ID of the bank account
60
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-creditor-bank-accounts)
61
+ # which happens to be the payment account.
62
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
63
+ # Otherwise they will be the body of the request.
64
+ def all(identity, options = {})
65
+ Paginator.new(
66
+ service: self,
67
+ options: options,
68
+ identity: identity
69
+ ).enumerator
70
+ end
71
+
72
+ private
73
+
74
+ # Unenvelope the response of the body using the service's `envelope_key`
75
+ #
76
+ # @param body [Hash]
77
+ def unenvelope_body(body)
78
+ if body.key?(envelope_key)
79
+ body[envelope_key]
80
+ elsif body.key?('data')
81
+ body['data']
82
+ else
83
+ body
84
+ end
85
+ end
86
+
87
+ # return the key which API responses will envelope data under
88
+ def envelope_key
89
+ 'payment_account_transactions'
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,83 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # This client is automatically generated from a template and JSON schema definition.
6
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
7
+ #
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the PaymentAccount endpoints
12
+ class PaymentAccountsService < BaseService
13
+ # Retrieves the details of an existing payment account.
14
+ # Example URL: /payment_accounts/:identity
15
+ #
16
+ # @param identity # Unique identifier, beginning with "BA".
17
+ # @param options [Hash] parameters as a hash, under a params key.
18
+ def get(identity, options = {})
19
+ path = sub_url('/payment_accounts/:identity', {
20
+ 'identity' => identity,
21
+ })
22
+
23
+ options[:retry_failures] = true
24
+
25
+ response = make_request(:get, path, options)
26
+
27
+ return if response.body.nil?
28
+
29
+ Resources::PaymentAccount.new(unenvelope_body(response.body), response)
30
+ end
31
+
32
+ # Returns a cursor-paginated
33
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
34
+ # list of your payment accounts.
35
+ # Example URL: /payment_accounts
36
+ # @param options [Hash] parameters as a hash, under a params key.
37
+ def list(options = {})
38
+ path = '/payment_accounts'
39
+
40
+ options[:retry_failures] = true
41
+
42
+ response = make_request(:get, path, options)
43
+
44
+ ListResponse.new(
45
+ response: response,
46
+ unenveloped_body: unenvelope_body(response.body),
47
+ resource_class: Resources::PaymentAccount
48
+ )
49
+ end
50
+
51
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
52
+ #
53
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
54
+ # Otherwise they will be the body of the request.
55
+ def all(options = {})
56
+ Paginator.new(
57
+ service: self,
58
+ options: options
59
+ ).enumerator
60
+ end
61
+
62
+ private
63
+
64
+ # Unenvelope the response of the body using the service's `envelope_key`
65
+ #
66
+ # @param body [Hash]
67
+ def unenvelope_body(body)
68
+ if body.key?(envelope_key)
69
+ body[envelope_key]
70
+ elsif body.key?('data')
71
+ body['data']
72
+ else
73
+ body
74
+ end
75
+ end
76
+
77
+ # return the key which API responses will envelope data under
78
+ def envelope_key
79
+ 'payment_accounts'
80
+ end
81
+ end
82
+ end
83
+ end