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
@@ -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
@@ -45,8 +45,9 @@ module GoCardlessPro
45
45
  Resources::Customer.new(unenvelope_body(response.body), response)
46
46
  end
47
47
 
48
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
49
- # customers.
48
+ # Returns a cursor-paginated
49
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
50
+ # list of your customers.
50
51
  # Example URL: /customers
51
52
  # @param options [Hash] parameters as a hash, under a params key.
52
53
  def list(options = {})
@@ -81,7 +82,7 @@ module GoCardlessPro
81
82
  # @param options [Hash] parameters as a hash, under a params key.
82
83
  def get(identity, options = {})
83
84
  path = sub_url('/customers/:identity', {
84
- 'identity' => identity
85
+ 'identity' => identity,
85
86
  })
86
87
 
87
88
  options[:retry_failures] = true
@@ -101,7 +102,7 @@ module GoCardlessPro
101
102
  # @param options [Hash] parameters as a hash, under a params key.
102
103
  def update(identity, options = {})
103
104
  path = sub_url('/customers/:identity', {
104
- 'identity' => identity
105
+ 'identity' => identity,
105
106
  })
106
107
 
107
108
  params = options.delete(:params) || {}
@@ -123,15 +124,14 @@ module GoCardlessPro
123
124
  # customer by
124
125
  # ID.
125
126
  #
126
- # <p class="restricted-notice"><strong>The action of removing a customer cannot
127
- # be reversed, so please use with care.</strong></p>
127
+ # The action of removing a customer cannot be reversed, so please use with care.
128
128
  # Example URL: /customers/:identity
129
129
  #
130
130
  # @param identity # Unique identifier, beginning with "CU".
131
131
  # @param options [Hash] parameters as a hash, under a params key.
132
132
  def remove(identity, options = {})
133
133
  path = sub_url('/customers/:identity', {
134
- 'identity' => identity
134
+ 'identity' => identity,
135
135
  })
136
136
 
137
137
  options[:retry_failures] = false
@@ -149,7 +149,13 @@ module GoCardlessPro
149
149
  #
150
150
  # @param body [Hash]
151
151
  def unenvelope_body(body)
152
- body[envelope_key] || body['data']
152
+ if body.key?(envelope_key)
153
+ body[envelope_key]
154
+ elsif body.key?('data')
155
+ body['data']
156
+ else
157
+ body
158
+ end
153
159
  end
154
160
 
155
161
  # return the key which API responses will envelope data under
@@ -10,8 +10,14 @@ module GoCardlessPro
10
10
  module Services
11
11
  # Service for making requests to the Event endpoints
12
12
  class EventsService < BaseService
13
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
14
- # events.
13
+ # Returns a cursor-paginated
14
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
15
+ # list of your events.
16
+ #
17
+ # Important: This endpoint will no longer return events older than 18 months,
18
+ # including when filtering by resource. This takes effect no sooner than 1
19
+ # August 2026 in sandbox environments, and no sooner than 1 October 2026 in live
20
+ # environments.
15
21
  # Example URL: /events
16
22
  # @param options [Hash] parameters as a hash, under a params key.
17
23
  def list(options = {})
@@ -46,7 +52,7 @@ module GoCardlessPro
46
52
  # @param options [Hash] parameters as a hash, under a params key.
47
53
  def get(identity, options = {})
48
54
  path = sub_url('/events/:identity', {
49
- 'identity' => identity
55
+ 'identity' => identity,
50
56
  })
51
57
 
52
58
  options[:retry_failures] = true
@@ -64,7 +70,13 @@ module GoCardlessPro
64
70
  #
65
71
  # @param body [Hash]
66
72
  def unenvelope_body(body)
67
- body[envelope_key] || body['data']
73
+ if body.key?(envelope_key)
74
+ body[envelope_key]
75
+ elsif body.key?('data')
76
+ body['data']
77
+ else
78
+ body
79
+ end
68
80
  end
69
81
 
70
82
  # return the key which API responses will envelope data under
@@ -17,7 +17,7 @@ module GoCardlessPro
17
17
  # @param options [Hash] parameters as a hash, under a params key.
18
18
  def get(identity, options = {})
19
19
  path = sub_url('/exports/:identity', {
20
- 'identity' => identity
20
+ 'identity' => identity,
21
21
  })
22
22
 
23
23
  options[:retry_failures] = true
@@ -63,7 +63,13 @@ module GoCardlessPro
63
63
  #
64
64
  # @param body [Hash]
65
65
  def unenvelope_body(body)
66
- body[envelope_key] || body['data']
66
+ if body.key?(envelope_key)
67
+ body[envelope_key]
68
+ elsif body.key?('data')
69
+ body['data']
70
+ else
71
+ body
72
+ end
67
73
  end
68
74
 
69
75
  # return the key which API responses will envelope data under
@@ -0,0 +1,56 @@
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 FundsAvailability endpoints
12
+ class FundsAvailabilitiesService < BaseService
13
+ # Checks if the payer's current balance is sufficient to cover the amount
14
+ # the merchant wants to charge within the consent parameters defined on the
15
+ # mandate.
16
+ # Example URL: /funds_availability/:identity
17
+ #
18
+ # @param identity # Unique identifier, beginning with "MD". Note that this prefix may not
19
+ # apply to mandates created before 2016.
20
+ # @param options [Hash] parameters as a hash, under a params key.
21
+ def check(identity, options = {})
22
+ path = sub_url('/funds_availability/:identity', {
23
+ 'identity' => identity,
24
+ })
25
+
26
+ options[:retry_failures] = false
27
+
28
+ response = make_request(:get, path, options)
29
+
30
+ return if response.body.nil?
31
+
32
+ Resources::FundsAvailability.new(unenvelope_body(response.body), response)
33
+ end
34
+
35
+ private
36
+
37
+ # Unenvelope the response of the body using the service's `envelope_key`
38
+ #
39
+ # @param body [Hash]
40
+ def unenvelope_body(body)
41
+ if body.key?(envelope_key)
42
+ body[envelope_key]
43
+ elsif body.key?('data')
44
+ body['data']
45
+ else
46
+ body
47
+ end
48
+ end
49
+
50
+ # return the key which API responses will envelope data under
51
+ def envelope_key
52
+ 'funds_availability'
53
+ end
54
+ end
55
+ end
56
+ end
@@ -14,8 +14,8 @@ module GoCardlessPro
14
14
  # This
15
15
  # API is recommended if you know the specific dates you wish to charge.
16
16
  # Otherwise,
17
- # please check out the [scheduling
18
- # version](#instalment-schedules-create-with-schedule).
17
+ # please check out the scheduling version
18
+ # (https://developer.gocardless.com/api-reference/#instalment-schedules-create-with-schedule).
19
19
  #
20
20
  # The `instalments` property is an array of payment properties (`amount` and
21
21
  # `charge_date`).
@@ -49,7 +49,7 @@ module GoCardlessPro
49
49
  if e.idempotent_creation_conflict?
50
50
  case @api_service.on_idempotency_conflict
51
51
  when :raise
52
- raise IdempotencyConflict, e.error
52
+ raise IdempotencyConflict.new(e.error)
53
53
  when :fetch
54
54
  return get(e.conflicting_resource_id)
55
55
  end
@@ -67,8 +67,9 @@ module GoCardlessPro
67
67
  # This
68
68
  # API is recommended if you wish to use the GoCardless scheduling logic. For
69
69
  # finer
70
- # control over the individual dates, please check out the [alternative
71
- # version](#instalment-schedules-create-with-dates).
70
+ # control over the individual dates, please check out the alternative
71
+ # version
72
+ # (https://developer.gocardless.com/api-reference/#instalment-schedules-create-with-dates).
72
73
  #
73
74
  # It can take quite a while to create the associated payments, so the API will
74
75
  # return
@@ -97,7 +98,7 @@ module GoCardlessPro
97
98
  if e.idempotent_creation_conflict?
98
99
  case @api_service.on_idempotency_conflict
99
100
  when :raise
100
- raise IdempotencyConflict, e.error
101
+ raise IdempotencyConflict.new(e.error)
101
102
  when :fetch
102
103
  return get(e.conflicting_resource_id)
103
104
  end
@@ -111,8 +112,9 @@ module GoCardlessPro
111
112
  Resources::InstalmentSchedule.new(unenvelope_body(response.body), response)
112
113
  end
113
114
 
114
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
115
- # instalment schedules.
115
+ # Returns a cursor-paginated
116
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
117
+ # list of your instalment schedules.
116
118
  # Example URL: /instalment_schedules
117
119
  # @param options [Hash] parameters as a hash, under a params key.
118
120
  def list(options = {})
@@ -147,7 +149,7 @@ module GoCardlessPro
147
149
  # @param options [Hash] parameters as a hash, under a params key.
148
150
  def get(identity, options = {})
149
151
  path = sub_url('/instalment_schedules/:identity', {
150
- 'identity' => identity
152
+ 'identity' => identity,
151
153
  })
152
154
 
153
155
  options[:retry_failures] = true
@@ -166,7 +168,7 @@ module GoCardlessPro
166
168
  # @param options [Hash] parameters as a hash, under a params key.
167
169
  def update(identity, options = {})
168
170
  path = sub_url('/instalment_schedules/:identity', {
169
- 'identity' => identity
171
+ 'identity' => identity,
170
172
  })
171
173
 
172
174
  params = options.delete(:params) || {}
@@ -193,7 +195,7 @@ module GoCardlessPro
193
195
  # @param options [Hash] parameters as a hash, under a params key.
194
196
  def cancel(identity, options = {})
195
197
  path = sub_url('/instalment_schedules/:identity/actions/cancel', {
196
- 'identity' => identity
198
+ 'identity' => identity,
197
199
  })
198
200
 
199
201
  params = options.delete(:params) || {}
@@ -211,7 +213,7 @@ module GoCardlessPro
211
213
  if e.idempotent_creation_conflict?
212
214
  case @api_service.on_idempotency_conflict
213
215
  when :raise
214
- raise IdempotencyConflict, e.error
216
+ raise IdempotencyConflict.new(e.error)
215
217
  when :fetch
216
218
  return get(e.conflicting_resource_id)
217
219
  end
@@ -231,7 +233,13 @@ module GoCardlessPro
231
233
  #
232
234
  # @param body [Hash]
233
235
  def unenvelope_body(body)
234
- body[envelope_key] || body['data']
236
+ if body.key?(envelope_key)
237
+ body[envelope_key]
238
+ elsif body.key?('data')
239
+ body['data']
240
+ else
241
+ body
242
+ end
235
243
  end
236
244
 
237
245
  # return the key which API responses will envelope data under
@@ -47,7 +47,7 @@ module GoCardlessPro
47
47
  # @param options [Hash] parameters as a hash, under a params key.
48
48
  def list_for_billing_request(identity, options = {})
49
49
  path = sub_url('/billing_requests/:identity/institutions', {
50
- 'identity' => identity
50
+ 'identity' => identity,
51
51
  })
52
52
 
53
53
  options[:retry_failures] = false
@@ -67,7 +67,13 @@ module GoCardlessPro
67
67
  #
68
68
  # @param body [Hash]
69
69
  def unenvelope_body(body)
70
- body[envelope_key] || body['data']
70
+ if body.key?(envelope_key)
71
+ body[envelope_key]
72
+ elsif body.key?('data')
73
+ body['data']
74
+ else
75
+ body
76
+ end
71
77
  end
72
78
 
73
79
  # return the key which API responses will envelope data under
@@ -15,8 +15,8 @@ module GoCardlessPro
15
15
  #
16
16
  # We support JPG and PNG formats. Your logo will be scaled to a maximum of 300px
17
17
  # by 40px. For more guidance on how to upload logos that will look
18
- # great across your customer payment page and notification emails see
19
- # [here](https://developer.gocardless.com/gc-embed/setting-up-branding#tips_for_uploading_your_logo).
18
+ # great across your customer payment page and notification emails see here
19
+ # (https://developer.gocardless.com/gc-embed/setting-up-branding#tips_for_uploading_your_logo).
20
20
  # Example URL: /branding/logos
21
21
  # @param options [Hash] parameters as a hash, under a params key.
22
22
  def create_for_creditor(options = {})
@@ -41,7 +41,13 @@ module GoCardlessPro
41
41
  #
42
42
  # @param body [Hash]
43
43
  def unenvelope_body(body)
44
- body[envelope_key] || body['data']
44
+ if body.key?(envelope_key)
45
+ body[envelope_key]
46
+ elsif body.key?('data')
47
+ body['data']
48
+ else
49
+ body
50
+ end
45
51
  end
46
52
 
47
53
  # return the key which API responses will envelope data under
@@ -10,8 +10,9 @@ module GoCardlessPro
10
10
  module Services
11
11
  # Service for making requests to the MandateImportEntry endpoints
12
12
  class MandateImportEntriesService < BaseService
13
- # For an existing [mandate import](#core-endpoints-mandate-imports), this
14
- # endpoint can
13
+ # For an existing mandate import
14
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-mandate-imports),
15
+ # this endpoint can
15
16
  # be used to add individual mandates to be imported into GoCardless.
16
17
  #
17
18
  # You can add no more than 30,000 rows to a single mandate import.
@@ -43,7 +44,6 @@ module GoCardlessPro
43
44
  # in your system (using the `record_identifier` that you provided when creating
44
45
  # the
45
46
  # mandate import).
46
- #
47
47
  # Example URL: /mandate_import_entries
48
48
  # @param options [Hash] parameters as a hash, under a params key.
49
49
  def list(options = {})
@@ -77,7 +77,13 @@ module GoCardlessPro
77
77
  #
78
78
  # @param body [Hash]
79
79
  def unenvelope_body(body)
80
- body[envelope_key] || body['data']
80
+ if body.key?(envelope_key)
81
+ body[envelope_key]
82
+ elsif body.key?('data')
83
+ body['data']
84
+ else
85
+ body
86
+ end
81
87
  end
82
88
 
83
89
  # return the key which API responses will envelope data under
@@ -14,7 +14,9 @@ module GoCardlessPro
14
14
  # this endpoint merely signals the start of the import process. Once you've
15
15
  # finished
16
16
  # adding entries to an import, you should
17
- # [submit](#mandate-imports-submit-a-mandate-import) it.
17
+ # submit
18
+ # (https://developer.gocardless.com/api-reference/#mandate-imports-submit-a-mandate-import)
19
+ # it.
18
20
  # Example URL: /mandate_imports
19
21
  # @param options [Hash] parameters as a hash, under a params key.
20
22
  def create(options = {})
@@ -35,7 +37,7 @@ module GoCardlessPro
35
37
  if e.idempotent_creation_conflict?
36
38
  case @api_service.on_idempotency_conflict
37
39
  when :raise
38
- raise IdempotencyConflict, e.error
40
+ raise IdempotencyConflict.new(e.error)
39
41
  when :fetch
40
42
  return get(e.conflicting_resource_id)
41
43
  end
@@ -56,7 +58,7 @@ module GoCardlessPro
56
58
  # @param options [Hash] parameters as a hash, under a params key.
57
59
  def get(identity, options = {})
58
60
  path = sub_url('/mandate_imports/:identity', {
59
- 'identity' => identity
61
+ 'identity' => identity,
60
62
  })
61
63
 
62
64
  options[:retry_failures] = true
@@ -85,7 +87,7 @@ module GoCardlessPro
85
87
  # @param options [Hash] parameters as a hash, under a params key.
86
88
  def submit(identity, options = {})
87
89
  path = sub_url('/mandate_imports/:identity/actions/submit', {
88
- 'identity' => identity
90
+ 'identity' => identity,
89
91
  })
90
92
 
91
93
  params = options.delete(:params) || {}
@@ -103,7 +105,7 @@ module GoCardlessPro
103
105
  if e.idempotent_creation_conflict?
104
106
  case @api_service.on_idempotency_conflict
105
107
  when :raise
106
- raise IdempotencyConflict, e.error
108
+ raise IdempotencyConflict.new(e.error)
107
109
  when :fetch
108
110
  return get(e.conflicting_resource_id)
109
111
  end
@@ -130,7 +132,7 @@ module GoCardlessPro
130
132
  # @param options [Hash] parameters as a hash, under a params key.
131
133
  def cancel(identity, options = {})
132
134
  path = sub_url('/mandate_imports/:identity/actions/cancel', {
133
- 'identity' => identity
135
+ 'identity' => identity,
134
136
  })
135
137
 
136
138
  params = options.delete(:params) || {}
@@ -148,7 +150,7 @@ module GoCardlessPro
148
150
  if e.idempotent_creation_conflict?
149
151
  case @api_service.on_idempotency_conflict
150
152
  when :raise
151
- raise IdempotencyConflict, e.error
153
+ raise IdempotencyConflict.new(e.error)
152
154
  when :fetch
153
155
  return get(e.conflicting_resource_id)
154
156
  end
@@ -168,7 +170,13 @@ module GoCardlessPro
168
170
  #
169
171
  # @param body [Hash]
170
172
  def unenvelope_body(body)
171
- body[envelope_key] || body['data']
173
+ if body.key?(envelope_key)
174
+ body[envelope_key]
175
+ elsif body.key?('data')
176
+ body['data']
177
+ else
178
+ body
179
+ end
172
180
  end
173
181
 
174
182
  # return the key which API responses will envelope data under
@@ -13,14 +13,14 @@ module GoCardlessPro
13
13
  # Generates a PDF mandate and returns its temporary URL.
14
14
  #
15
15
  # Customer and bank account details can be left blank (for a blank mandate),
16
- # provided manually, or inferred from the ID of an existing
17
- # [mandate](#core-endpoints-mandates).
16
+ # provided manually, or inferred from the ID of an existing mandate
17
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-mandates).
18
18
  #
19
19
  # By default, we'll generate PDF mandates in English.
20
20
  #
21
21
  # To generate a PDF mandate in another language, set the `Accept-Language`
22
- # header when creating the PDF mandate to the relevant [ISO
23
- # 639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code
22
+ # header when creating the PDF mandate to the relevant ISO 639-1
23
+ # (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code
24
24
  # supported for the scheme.
25
25
  #
26
26
  # | Scheme | Supported languages
@@ -77,7 +77,13 @@ module GoCardlessPro
77
77
  #
78
78
  # @param body [Hash]
79
79
  def unenvelope_body(body)
80
- body[envelope_key] || body['data']
80
+ if body.key?(envelope_key)
81
+ body[envelope_key]
82
+ elsif body.key?('data')
83
+ body['data']
84
+ else
85
+ body
86
+ end
81
87
  end
82
88
 
83
89
  # return the key which API responses will envelope data under
@@ -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
@@ -45,8 +45,9 @@ module GoCardlessPro
45
45
  Resources::Mandate.new(unenvelope_body(response.body), response)
46
46
  end
47
47
 
48
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
49
- # mandates.
48
+ # Returns a cursor-paginated
49
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
50
+ # list of your mandates.
50
51
  # Example URL: /mandates
51
52
  # @param options [Hash] parameters as a hash, under a params key.
52
53
  def list(options = {})
@@ -82,7 +83,7 @@ module GoCardlessPro
82
83
  # @param options [Hash] parameters as a hash, under a params key.
83
84
  def get(identity, options = {})
84
85
  path = sub_url('/mandates/:identity', {
85
- 'identity' => identity
86
+ 'identity' => identity,
86
87
  })
87
88
 
88
89
  options[:retry_failures] = true
@@ -102,7 +103,7 @@ module GoCardlessPro
102
103
  # @param options [Hash] parameters as a hash, under a params key.
103
104
  def update(identity, options = {})
104
105
  path = sub_url('/mandates/:identity', {
105
- 'identity' => identity
106
+ 'identity' => identity,
106
107
  })
107
108
 
108
109
  params = options.delete(:params) || {}
@@ -131,7 +132,7 @@ module GoCardlessPro
131
132
  # @param options [Hash] parameters as a hash, under a params key.
132
133
  def cancel(identity, options = {})
133
134
  path = sub_url('/mandates/:identity/actions/cancel', {
134
- 'identity' => identity
135
+ 'identity' => identity,
135
136
  })
136
137
 
137
138
  params = options.delete(:params) || {}
@@ -149,7 +150,7 @@ module GoCardlessPro
149
150
  if e.idempotent_creation_conflict?
150
151
  case @api_service.on_idempotency_conflict
151
152
  when :raise
152
- raise IdempotencyConflict, e.error
153
+ raise IdempotencyConflict.new(e.error)
153
154
  when :fetch
154
155
  return get(e.conflicting_resource_id)
155
156
  end
@@ -163,12 +164,12 @@ module GoCardlessPro
163
164
  Resources::Mandate.new(unenvelope_body(response.body), response)
164
165
  end
165
166
 
166
- # <a name="mandate_not_inactive"></a>Reinstates a cancelled or expired mandate
167
- # to the banks. You will receive a `resubmission_requested` webhook, but after
168
- # that reinstating the mandate follows the same process as its initial creation,
169
- # so you will receive a `submitted` webhook, followed by a `reinstated` or
170
- # `failed` webhook up to two working days later. Any metadata supplied to this
171
- # endpoint will be stored on the `resubmission_requested` event it causes.
167
+ # Reinstates a cancelled or expired mandate to the banks. You will receive a
168
+ # `resubmission_requested` webhook, but after that reinstating the mandate
169
+ # follows the same process as its initial creation, so you will receive a
170
+ # `submitted` webhook, followed by a `reinstated` or `failed` webhook up to two
171
+ # working days later. Any metadata supplied to this endpoint will be stored on
172
+ # the `resubmission_requested` event it causes.
172
173
  #
173
174
  # This will fail with a `mandate_not_inactive` error if the mandate is already
174
175
  # being submitted, or is active.
@@ -181,7 +182,7 @@ module GoCardlessPro
181
182
  # @param options [Hash] parameters as a hash, under a params key.
182
183
  def reinstate(identity, options = {})
183
184
  path = sub_url('/mandates/:identity/actions/reinstate', {
184
- 'identity' => identity
185
+ 'identity' => identity,
185
186
  })
186
187
 
187
188
  params = options.delete(:params) || {}
@@ -199,7 +200,7 @@ module GoCardlessPro
199
200
  if e.idempotent_creation_conflict?
200
201
  case @api_service.on_idempotency_conflict
201
202
  when :raise
202
- raise IdempotencyConflict, e.error
203
+ raise IdempotencyConflict.new(e.error)
203
204
  when :fetch
204
205
  return get(e.conflicting_resource_id)
205
206
  end
@@ -219,7 +220,13 @@ module GoCardlessPro
219
220
  #
220
221
  # @param body [Hash]
221
222
  def unenvelope_body(body)
222
- body[envelope_key] || body['data']
223
+ if body.key?(envelope_key)
224
+ body[envelope_key]
225
+ elsif body.key?('data')
226
+ body['data']
227
+ else
228
+ body
229
+ end
223
230
  end
224
231
 
225
232
  # return the key which API responses will envelope data under
@@ -10,8 +10,9 @@ module GoCardlessPro
10
10
  module Services
11
11
  # Service for making requests to the NegativeBalanceLimit endpoints
12
12
  class NegativeBalanceLimitsService < BaseService
13
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of negative
14
- # balance limits.
13
+ # Returns a cursor-paginated
14
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
15
+ # list of negative balance limits.
15
16
  # Example URL: /negative_balance_limits
16
17
  # @param options [Hash] parameters as a hash, under a params key.
17
18
  def list(options = {})
@@ -45,7 +46,13 @@ module GoCardlessPro
45
46
  #
46
47
  # @param body [Hash]
47
48
  def unenvelope_body(body)
48
- body[envelope_key] || body['data']
49
+ if body.key?(envelope_key)
50
+ body[envelope_key]
51
+ elsif body.key?('data')
52
+ body['data']
53
+ else
54
+ body
55
+ end
49
56
  end
50
57
 
51
58
  # return the key which API responses will envelope data under