gocardless_pro 2.27.0 → 2.30.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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +20 -1
  3. data/lib/gocardless_pro/api_service.rb +4 -0
  4. data/lib/gocardless_pro/client.rb +11 -1
  5. data/lib/gocardless_pro/error/authentication_error.rb +4 -0
  6. data/lib/gocardless_pro/error/permission_error.rb +4 -0
  7. data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
  8. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
  9. data/lib/gocardless_pro/resources/bank_authorisation.rb +3 -9
  10. data/lib/gocardless_pro/resources/billing_request.rb +31 -7
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +14 -0
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  13. data/lib/gocardless_pro/resources/block.rb +76 -0
  14. data/lib/gocardless_pro/resources/event.rb +20 -0
  15. data/lib/gocardless_pro/resources/institution.rb +7 -1
  16. data/lib/gocardless_pro/resources/payer_authorisation.rb +9 -0
  17. data/lib/gocardless_pro/resources/redirect_flow.rb +6 -0
  18. data/lib/gocardless_pro/services/bank_authorisations_service.rb +0 -2
  19. data/lib/gocardless_pro/services/billing_request_flows_service.rb +23 -0
  20. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  21. data/lib/gocardless_pro/services/billing_requests_service.rb +89 -24
  22. data/lib/gocardless_pro/services/blocks_service.rb +223 -0
  23. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +1 -5
  24. data/lib/gocardless_pro/services/creditors_service.rb +1 -3
  25. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +1 -1
  26. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +1 -5
  27. data/lib/gocardless_pro/services/customers_service.rb +1 -3
  28. data/lib/gocardless_pro/services/events_service.rb +1 -1
  29. data/lib/gocardless_pro/services/instalment_schedules_service.rb +1 -7
  30. data/lib/gocardless_pro/services/institutions_service.rb +2 -2
  31. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +1 -1
  32. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  33. data/lib/gocardless_pro/services/mandates_service.rb +1 -7
  34. data/lib/gocardless_pro/services/payer_authorisations_service.rb +0 -6
  35. data/lib/gocardless_pro/services/payments_service.rb +1 -7
  36. data/lib/gocardless_pro/services/payout_items_service.rb +1 -1
  37. data/lib/gocardless_pro/services/payouts_service.rb +1 -1
  38. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  39. data/lib/gocardless_pro/services/refunds_service.rb +1 -3
  40. data/lib/gocardless_pro/services/scenario_simulators_service.rb +28 -6
  41. data/lib/gocardless_pro/services/subscriptions_service.rb +3 -11
  42. data/lib/gocardless_pro/services/tax_rates_service.rb +1 -1
  43. data/lib/gocardless_pro/services/webhooks_service.rb +1 -3
  44. data/lib/gocardless_pro/version.rb +1 -1
  45. data/lib/gocardless_pro.rb +9 -0
  46. data/spec/api_service_spec.rb +12 -1
  47. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  48. data/spec/resources/bank_authorisation_spec.rb +7 -7
  49. data/spec/resources/billing_request_flow_spec.rb +104 -0
  50. data/spec/resources/billing_request_spec.rb +183 -29
  51. data/spec/resources/billing_request_template_spec.rb +502 -0
  52. data/spec/resources/block_spec.rb +577 -0
  53. data/spec/resources/creditor_bank_account_spec.rb +2 -0
  54. data/spec/resources/customer_bank_account_spec.rb +2 -0
  55. data/spec/resources/customer_notification_spec.rb +2 -0
  56. data/spec/resources/customer_spec.rb +2 -0
  57. data/spec/resources/instalment_schedule_spec.rb +2 -0
  58. data/spec/resources/institution_spec.rb +5 -0
  59. data/spec/resources/mandate_import_spec.rb +4 -0
  60. data/spec/resources/mandate_spec.rb +4 -0
  61. data/spec/resources/payer_authorisation_spec.rb +4 -0
  62. data/spec/resources/payment_spec.rb +4 -0
  63. data/spec/resources/redirect_flow_spec.rb +11 -0
  64. data/spec/resources/scenario_simulator_spec.rb +2 -0
  65. data/spec/resources/subscription_spec.rb +6 -0
  66. data/spec/resources/webhook_spec.rb +2 -0
  67. data/spec/services/bank_authorisations_service_spec.rb +7 -20
  68. data/spec/services/billing_request_flows_service_spec.rb +115 -0
  69. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  70. data/spec/services/billing_requests_service_spec.rb +210 -47
  71. data/spec/services/blocks_service_spec.rb +840 -0
  72. data/spec/services/creditor_bank_accounts_service_spec.rb +2 -13
  73. data/spec/services/creditors_service_spec.rb +0 -13
  74. data/spec/services/customer_bank_accounts_service_spec.rb +2 -13
  75. data/spec/services/customer_notifications_service_spec.rb +2 -0
  76. data/spec/services/customers_service_spec.rb +2 -13
  77. data/spec/services/instalment_schedules_service_spec.rb +2 -26
  78. data/spec/services/institutions_service_spec.rb +9 -0
  79. data/spec/services/mandate_imports_service_spec.rb +4 -13
  80. data/spec/services/mandates_service_spec.rb +4 -13
  81. data/spec/services/payer_authorisations_service_spec.rb +4 -13
  82. data/spec/services/payments_service_spec.rb +4 -13
  83. data/spec/services/redirect_flows_service_spec.rb +11 -13
  84. data/spec/services/refunds_service_spec.rb +0 -13
  85. data/spec/services/scenario_simulators_service_spec.rb +2 -0
  86. data/spec/services/subscriptions_service_spec.rb +6 -13
  87. data/spec/services/webhooks_service_spec.rb +2 -0
  88. metadata +18 -3
@@ -52,8 +52,6 @@ module GoCardlessPro
52
52
  raise IdempotencyConflict, e.error
53
53
  when :fetch
54
54
  return get(e.conflicting_resource_id)
55
- else
56
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
57
55
  end
58
56
  end
59
57
 
@@ -102,8 +100,6 @@ module GoCardlessPro
102
100
  raise IdempotencyConflict, e.error
103
101
  when :fetch
104
102
  return get(e.conflicting_resource_id)
105
- else
106
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
107
103
  end
108
104
  end
109
105
 
@@ -133,7 +129,7 @@ module GoCardlessPro
133
129
  )
134
130
  end
135
131
 
136
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
132
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
137
133
  #
138
134
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
139
135
  # Otherwise they will be the body of the request.
@@ -212,8 +208,6 @@ module GoCardlessPro
212
208
  raise IdempotencyConflict, e.error
213
209
  when :fetch
214
210
  return get(e.conflicting_resource_id)
215
- else
216
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
217
211
  end
218
212
  end
219
213
 
@@ -10,7 +10,7 @@ module GoCardlessPro
10
10
  module Services
11
11
  # Service for making requests to the Institution endpoints
12
12
  class InstitutionsService < BaseService
13
- # Returns a list of all supported institutions.
13
+ # Returns a list of supported institutions.
14
14
  # Example URL: /institutions
15
15
  # @param options [Hash] parameters as a hash, under a params key.
16
16
  def list(options = {})
@@ -27,7 +27,7 @@ module GoCardlessPro
27
27
  )
28
28
  end
29
29
 
30
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
30
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
31
31
  #
32
32
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
33
33
  # Otherwise they will be the body of the request.
@@ -60,7 +60,7 @@ module GoCardlessPro
60
60
  )
61
61
  end
62
62
 
63
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
63
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
64
64
  #
65
65
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
66
66
  # Otherwise they will be the body of the request.
@@ -38,8 +38,6 @@ module GoCardlessPro
38
38
  raise IdempotencyConflict, e.error
39
39
  when :fetch
40
40
  return get(e.conflicting_resource_id)
41
- else
42
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
43
41
  end
44
42
  end
45
43
 
@@ -104,8 +102,6 @@ module GoCardlessPro
104
102
  raise IdempotencyConflict, e.error
105
103
  when :fetch
106
104
  return get(e.conflicting_resource_id)
107
- else
108
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
109
105
  end
110
106
  end
111
107
 
@@ -149,8 +145,6 @@ module GoCardlessPro
149
145
  raise IdempotencyConflict, e.error
150
146
  when :fetch
151
147
  return get(e.conflicting_resource_id)
152
- else
153
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
154
148
  end
155
149
  end
156
150
 
@@ -34,8 +34,6 @@ module GoCardlessPro
34
34
  raise IdempotencyConflict, e.error
35
35
  when :fetch
36
36
  return get(e.conflicting_resource_id)
37
- else
38
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
39
37
  end
40
38
  end
41
39
 
@@ -65,7 +63,7 @@ module GoCardlessPro
65
63
  )
66
64
  end
67
65
 
68
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
66
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
69
67
  #
70
68
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
71
69
  # Otherwise they will be the body of the request.
@@ -148,8 +146,6 @@ module GoCardlessPro
148
146
  raise IdempotencyConflict, e.error
149
147
  when :fetch
150
148
  return get(e.conflicting_resource_id)
151
- else
152
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
153
149
  end
154
150
  end
155
151
 
@@ -198,8 +194,6 @@ module GoCardlessPro
198
194
  raise IdempotencyConflict, e.error
199
195
  when :fetch
200
196
  return get(e.conflicting_resource_id)
201
- else
202
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
203
197
  end
204
198
  end
205
199
 
@@ -57,8 +57,6 @@ module GoCardlessPro
57
57
  raise IdempotencyConflict, e.error
58
58
  when :fetch
59
59
  return get(e.conflicting_resource_id)
60
- else
61
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
62
60
  end
63
61
  end
64
62
 
@@ -128,8 +126,6 @@ module GoCardlessPro
128
126
  raise IdempotencyConflict, e.error
129
127
  when :fetch
130
128
  return get(e.conflicting_resource_id)
131
- else
132
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
133
129
  end
134
130
  end
135
131
 
@@ -177,8 +173,6 @@ module GoCardlessPro
177
173
  raise IdempotencyConflict, e.error
178
174
  when :fetch
179
175
  return get(e.conflicting_resource_id)
180
- else
181
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
182
176
  end
183
177
  end
184
178
 
@@ -39,8 +39,6 @@ module GoCardlessPro
39
39
  raise IdempotencyConflict, e.error
40
40
  when :fetch
41
41
  return get(e.conflicting_resource_id)
42
- else
43
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
44
42
  end
45
43
  end
46
44
 
@@ -70,7 +68,7 @@ module GoCardlessPro
70
68
  )
71
69
  end
72
70
 
73
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
71
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
74
72
  #
75
73
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
76
74
  # Otherwise they will be the body of the request.
@@ -150,8 +148,6 @@ module GoCardlessPro
150
148
  raise IdempotencyConflict, e.error
151
149
  when :fetch
152
150
  return get(e.conflicting_resource_id)
153
- else
154
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
155
151
  end
156
152
  end
157
153
 
@@ -198,8 +194,6 @@ module GoCardlessPro
198
194
  raise IdempotencyConflict, e.error
199
195
  when :fetch
200
196
  return get(e.conflicting_resource_id)
201
- else
202
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
203
197
  end
204
198
  end
205
199
 
@@ -29,7 +29,7 @@ module GoCardlessPro
29
29
  )
30
30
  end
31
31
 
32
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
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
33
  #
34
34
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
35
35
  # Otherwise they will be the body of the request.
@@ -28,7 +28,7 @@ module GoCardlessPro
28
28
  )
29
29
  end
30
30
 
31
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
31
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
32
32
  #
33
33
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
34
34
  # Otherwise they will be the body of the request.
@@ -35,8 +35,6 @@ module GoCardlessPro
35
35
  raise IdempotencyConflict, e.error
36
36
  when :fetch
37
37
  return get(e.conflicting_resource_id)
38
- else
39
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
40
38
  end
41
39
  end
42
40
 
@@ -100,8 +98,6 @@ module GoCardlessPro
100
98
  raise IdempotencyConflict, e.error
101
99
  when :fetch
102
100
  return get(e.conflicting_resource_id)
103
- else
104
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
105
101
  end
106
102
  end
107
103
 
@@ -50,8 +50,6 @@ module GoCardlessPro
50
50
  raise IdempotencyConflict, e.error
51
51
  when :fetch
52
52
  return get(e.conflicting_resource_id)
53
- else
54
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
55
53
  end
56
54
  end
57
55
 
@@ -81,7 +79,7 @@ module GoCardlessPro
81
79
  )
82
80
  end
83
81
 
84
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
82
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
85
83
  #
86
84
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
87
85
  # Otherwise they will be the body of the request.
@@ -27,6 +27,11 @@ module GoCardlessPro
27
27
  # <li>`creditor_verification_status_successful`: Sets a creditor's
28
28
  # `verification status` to `successful`, meaning that the creditor is
29
29
  # fully verified and can receive payouts.</li>
30
+ # <li>`payment_confirmed`: Transitions a payment through to `confirmed`.
31
+ # It must start in the `pending_submission` state, and its mandate must be
32
+ # in the `activated` state (unless it is a payment for ACH, BECS, BECS_NZ
33
+ # or SEPA, in which cases the mandate may be `pending_submission`, since
34
+ # their mandates are submitted with their first payment).</li>
30
35
  # <li>`payment_paid_out`: Transitions a payment through to `paid_out`,
31
36
  # having been collected successfully and paid out to you. It must start in
32
37
  # the `pending_submission` state, and its mandate must be in the
@@ -82,8 +87,8 @@ module GoCardlessPro
82
87
  # <li>`mandate_failed`: Transitions a mandate through to `failed`, having
83
88
  # been submitted to the banks but found to be invalid (for example due to
84
89
  # invalid bank details). It must start in the `pending_submission` or
85
- # `submitted` states. Not compatible with ACH, BECS, BECS_NZ and SEPA
86
- # mandates, which are submitted with their first payment.</li>
90
+ # `submitted` states. Not compatible with SEPA mandates, which are
91
+ # submitted with their first payment.</li>
87
92
  # <li>`mandate_expired`: Transitions a mandate through to `expired`,
88
93
  # having been submitted to the banks, set up successfully and then expired
89
94
  # because no collection attempts were made against it for longer than the
@@ -104,14 +109,31 @@ module GoCardlessPro
104
109
  # mandates.</li>
105
110
  # <li>`refund_paid`: Transitions a refund to `paid`. It must start in
106
111
  # either the `pending_submission` or `submitted` state.</li>
112
+ # <li>`refund_settled`: Transitions a refund to `paid`, if it's not
113
+ # already, then generates a payout that includes the refund, thereby
114
+ # settling the funds. It must start in one of `pending_submission`,
115
+ # `submitted` or `paid` states.</li>
107
116
  # <li>`refund_bounced`: Transitions a refund to `bounced`. It must start
108
117
  # in either the `pending_submission`, `submitted`, or `paid` state.</li>
118
+ # <li>`refund_returned`: Transitions a refund to `refund_returned`. The
119
+ # refund must start in `pending_submission`.</li>
109
120
  # <li>`payout_bounced`: Transitions a payout to `bounced`. It must start
110
121
  # in the `paid` state.</li>
111
- # <li>`payout_create`: Creates a payout containing payments in
112
- # `confirmed`, `failed` & `charged_back` states; refunds in `submitted` &
113
- # `bounced`; and all related fees. Can only be used with a positive total
114
- # payout balance and when some eligible items exist.</li>
122
+ # <li>`billing_request_fulfilled`: Authorises the billing request, fulfils
123
+ # it, and moves the associated payment to `failed`. The billing request
124
+ # must be in the `pending` state, with all actions completed except for
125
+ # `bank_authorisation`. Only billing requests with a `payment_request` are
126
+ # supported.</li>
127
+ # <li>`billing_request_fulfilled_and_payment_failed`: Authorises the
128
+ # billing request, fulfils it, and moves the associated payment to
129
+ # `failed`. The billing request must be in the `pending` state, with all
130
+ # actions completed except for `bank_authorisation`. Only billing requests
131
+ # with a `payment_request` are supported.</li>
132
+ # <li>`billing_request_fulfilled_and_payment_paid_out`: Authorises the
133
+ # billing request, fulfils it, and moves the associated payment to
134
+ # `paid_out`. The billing request must be in the `pending` state, with all
135
+ # actions completed except for `bank_authorisation`. Only billing requests
136
+ # with a `payment_request` are supported.</li>
115
137
  # </ul>
116
138
  # @param options [Hash] parameters as a hash, under a params key.
117
139
  def run(identity, options = {})
@@ -34,8 +34,6 @@ module GoCardlessPro
34
34
  raise IdempotencyConflict, e.error
35
35
  when :fetch
36
36
  return get(e.conflicting_resource_id)
37
- else
38
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
39
37
  end
40
38
  end
41
39
 
@@ -65,7 +63,7 @@ module GoCardlessPro
65
63
  )
66
64
  end
67
65
 
68
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
66
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
69
67
  #
70
68
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
71
69
  # Otherwise they will be the body of the request.
@@ -140,10 +138,10 @@ module GoCardlessPro
140
138
  # Pause a subscription object.
141
139
  # No payments will be created until it is resumed.
142
140
  #
143
- # This can only be used when a subscription collecting a fixed number of
141
+ # This can only be used when a subscription is collecting a fixed number of
144
142
  # payments (created using `count`),
145
143
  # when they continue forever (created without `count` or `end_date`) or
146
- # the subscription is paused for a number of cycles.
144
+ # the subscription is already paused for a number of cycles.
147
145
  #
148
146
  # When `pause_cycles` is omitted the subscription is paused until the [resume
149
147
  # endpoint](#subscriptions-resume-a-subscription) is called.
@@ -203,8 +201,6 @@ module GoCardlessPro
203
201
  raise IdempotencyConflict, e.error
204
202
  when :fetch
205
203
  return get(e.conflicting_resource_id)
206
- else
207
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
208
204
  end
209
205
  end
210
206
 
@@ -258,8 +254,6 @@ module GoCardlessPro
258
254
  raise IdempotencyConflict, e.error
259
255
  when :fetch
260
256
  return get(e.conflicting_resource_id)
261
- else
262
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
263
257
  end
264
258
  end
265
259
 
@@ -302,8 +296,6 @@ module GoCardlessPro
302
296
  raise IdempotencyConflict, e.error
303
297
  when :fetch
304
298
  return get(e.conflicting_resource_id)
305
- else
306
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
307
299
  end
308
300
  end
309
301
 
@@ -28,7 +28,7 @@ module GoCardlessPro
28
28
  )
29
29
  end
30
30
 
31
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
31
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
32
32
  #
33
33
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
34
34
  # Otherwise they will be the body of the request.
@@ -28,7 +28,7 @@ module GoCardlessPro
28
28
  )
29
29
  end
30
30
 
31
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
31
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
32
32
  #
33
33
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
34
34
  # Otherwise they will be the body of the request.
@@ -82,8 +82,6 @@ module GoCardlessPro
82
82
  raise IdempotencyConflict, e.error
83
83
  when :fetch
84
84
  return get(e.conflicting_resource_id)
85
- else
86
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
87
85
  end
88
86
  end
89
87
 
@@ -4,5 +4,5 @@ end
4
4
 
5
5
  module GoCardlessPro
6
6
  # Current version of the GC gem
7
- VERSION = '2.27.0'.freeze
7
+ VERSION = '2.30.0'.freeze
8
8
  end
@@ -32,6 +32,9 @@ 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'
@@ -50,6 +53,12 @@ require_relative 'gocardless_pro/services/billing_requests_service'
50
53
  require_relative 'gocardless_pro/resources/billing_request_flow'
51
54
  require_relative 'gocardless_pro/services/billing_request_flows_service'
52
55
 
56
+ require_relative 'gocardless_pro/resources/billing_request_template'
57
+ require_relative 'gocardless_pro/services/billing_request_templates_service'
58
+
59
+ require_relative 'gocardless_pro/resources/block'
60
+ require_relative 'gocardless_pro/services/blocks_service'
61
+
53
62
  require_relative 'gocardless_pro/resources/creditor'
54
63
  require_relative 'gocardless_pro/services/creditors_service'
55
64
 
@@ -1,8 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GoCardlessPro::ApiService do
4
- subject(:service) { described_class.new('https://api.example.com', 'secret_token') }
4
+ subject(:service) do
5
+ described_class.new('https://api.example.com', 'secret_token', options)
6
+ end
5
7
 
8
+ let(:options) { {} }
6
9
  let(:default_response) do
7
10
  {
8
11
  status: 200,
@@ -174,4 +177,12 @@ describe GoCardlessPro::ApiService do
174
177
  expect(stub).to have_been_requested
175
178
  end
176
179
  end
180
+
181
+ describe 'when passing an invalid :on_idempotency_conflict' do
182
+ let(:options) { { on_idempotency_conflict: :junk } }
183
+
184
+ it 'raises an error' do
185
+ expect { service }.to raise_error(ArgumentError)
186
+ end
187
+ end
177
188
  end
@@ -74,6 +74,36 @@ describe GoCardlessPro::Middlewares::RaiseGoCardlessErrors do
74
74
  end
75
75
  end
76
76
 
77
+ context 'for a Permission error' do
78
+ let(:status) { 403 }
79
+ let(:body) { { error: { type: 'invalid_api_usage' } }.to_json }
80
+
81
+ it 'raises a GoCardlessError' do
82
+ expect { connection.post('https://api.gocardless.com/widgets') }.
83
+ to raise_error(GoCardlessPro::PermissionError)
84
+ end
85
+ end
86
+
87
+ context 'for a RateLimit error' do
88
+ let(:status) { 429 }
89
+ let(:body) { { error: { type: 'invalid_api_usage' } }.to_json }
90
+
91
+ it 'raises a GoCardlessError' do
92
+ expect { connection.post('https://api.gocardless.com/widgets') }.
93
+ to raise_error(GoCardlessPro::RateLimitError)
94
+ end
95
+ end
96
+
97
+ context 'for a Authentication error' do
98
+ let(:status) { 401 }
99
+ let(:body) { { error: { type: 'invalid_api_usage' } }.to_json }
100
+
101
+ it 'raises a GoCardlessError' do
102
+ expect { connection.post('https://api.gocardless.com/widgets') }.
103
+ to raise_error(GoCardlessPro::AuthenticationError)
104
+ end
105
+ end
106
+
77
107
  context 'for an invalid API usage error' do
78
108
  let(:status) { 400 }
79
109
  let(:body) { { error: { type: 'invalid_api_usage' } }.to_json }
@@ -24,13 +24,13 @@ describe GoCardlessPro::Resources::BankAuthorisation do
24
24
  'bank_authorisations' => {
25
25
 
26
26
  'authorisation_type' => 'authorisation_type-input',
27
+ 'authorised_at' => 'authorised_at-input',
27
28
  'created_at' => 'created_at-input',
28
29
  'expires_at' => 'expires_at-input',
29
30
  'id' => 'id-input',
30
31
  'last_visited_at' => 'last_visited_at-input',
31
32
  'links' => 'links-input',
32
33
  'redirect_uri' => 'redirect_uri-input',
33
- 'short_url' => 'short_url-input',
34
34
  'url' => 'url-input',
35
35
  },
36
36
  }.to_json,
@@ -58,13 +58,13 @@ describe GoCardlessPro::Resources::BankAuthorisation do
58
58
  'bank_authorisations' => {
59
59
 
60
60
  'authorisation_type' => 'authorisation_type-input',
61
+ 'authorised_at' => 'authorised_at-input',
61
62
  'created_at' => 'created_at-input',
62
63
  'expires_at' => 'expires_at-input',
63
64
  'id' => 'id-input',
64
65
  'last_visited_at' => 'last_visited_at-input',
65
66
  'links' => 'links-input',
66
67
  'redirect_uri' => 'redirect_uri-input',
67
- 'short_url' => 'short_url-input',
68
68
  'url' => 'url-input',
69
69
  },
70
70
  }.to_json,
@@ -107,13 +107,13 @@ describe GoCardlessPro::Resources::BankAuthorisation do
107
107
  {
108
108
 
109
109
  'authorisation_type' => 'authorisation_type-input',
110
+ 'authorised_at' => 'authorised_at-input',
110
111
  'created_at' => 'created_at-input',
111
112
  'expires_at' => 'expires_at-input',
112
113
  'id' => 'id-input',
113
114
  'last_visited_at' => 'last_visited_at-input',
114
115
  'links' => 'links-input',
115
116
  'redirect_uri' => 'redirect_uri-input',
116
- 'short_url' => 'short_url-input',
117
117
  'url' => 'url-input',
118
118
  }
119
119
  end
@@ -125,13 +125,13 @@ describe GoCardlessPro::Resources::BankAuthorisation do
125
125
  'bank_authorisations' => {
126
126
 
127
127
  'authorisation_type' => 'authorisation_type-input',
128
+ 'authorised_at' => 'authorised_at-input',
128
129
  'created_at' => 'created_at-input',
129
130
  'expires_at' => 'expires_at-input',
130
131
  'id' => 'id-input',
131
132
  'last_visited_at' => 'last_visited_at-input',
132
133
  'links' => 'links-input',
133
134
  'redirect_uri' => 'redirect_uri-input',
134
- 'short_url' => 'short_url-input',
135
135
  'url' => 'url-input',
136
136
  },
137
137
  }
@@ -143,13 +143,13 @@ describe GoCardlessPro::Resources::BankAuthorisation do
143
143
  {
144
144
 
145
145
  'authorisation_type' => 'authorisation_type-input',
146
+ 'authorised_at' => 'authorised_at-input',
146
147
  'created_at' => 'created_at-input',
147
148
  'expires_at' => 'expires_at-input',
148
149
  'id' => 'id-input',
149
150
  'last_visited_at' => 'last_visited_at-input',
150
151
  'links' => 'links-input',
151
152
  'redirect_uri' => 'redirect_uri-input',
152
- 'short_url' => 'short_url-input',
153
153
  'url' => 'url-input',
154
154
  },
155
155
 
@@ -194,13 +194,13 @@ describe GoCardlessPro::Resources::BankAuthorisation do
194
194
  {
195
195
 
196
196
  'authorisation_type' => 'authorisation_type-input',
197
+ 'authorised_at' => 'authorised_at-input',
197
198
  'created_at' => 'created_at-input',
198
199
  'expires_at' => 'expires_at-input',
199
200
  'id' => 'id-input',
200
201
  'last_visited_at' => 'last_visited_at-input',
201
202
  'links' => 'links-input',
202
203
  'redirect_uri' => 'redirect_uri-input',
203
- 'short_url' => 'short_url-input',
204
204
  'url' => 'url-input',
205
205
  }
206
206
  end
@@ -235,13 +235,13 @@ describe GoCardlessPro::Resources::BankAuthorisation do
235
235
  'bank_authorisations' => {
236
236
 
237
237
  'authorisation_type' => 'authorisation_type-input',
238
+ 'authorised_at' => 'authorised_at-input',
238
239
  'created_at' => 'created_at-input',
239
240
  'expires_at' => 'expires_at-input',
240
241
  'id' => 'id-input',
241
242
  'last_visited_at' => 'last_visited_at-input',
242
243
  'links' => 'links-input',
243
244
  'redirect_uri' => 'redirect_uri-input',
244
- 'short_url' => 'short_url-input',
245
245
  'url' => 'url-input',
246
246
  },
247
247
  }.to_json,