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
@@ -10,12 +10,13 @@ module GoCardlessPro
10
10
  module Services
11
11
  # Service for making requests to the Payment endpoints
12
12
  class PaymentsService < BaseService
13
- # <a name="mandate_is_inactive"></a>Creates a new payment object.
13
+ # Creates a new payment object.
14
14
  #
15
- # This fails with a `mandate_is_inactive` error if the linked
16
- # [mandate](#core-endpoints-mandates) is cancelled or has failed. Payments can
17
- # be created against mandates with status of: `pending_customer_approval`,
18
- # `pending_submission`, `submitted`, and `active`.
15
+ # This fails with a `mandate_is_inactive` error if the linked mandate
16
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-mandates) is
17
+ # cancelled or has failed. Payments can be created against mandates with status
18
+ # of: `pending_customer_approval`, `pending_submission`, `submitted`, and
19
+ # `active`.
19
20
  # Example URL: /payments
20
21
  # @param options [Hash] parameters as a hash, under a params key.
21
22
  def create(options = {})
@@ -36,7 +37,7 @@ module GoCardlessPro
36
37
  if e.idempotent_creation_conflict?
37
38
  case @api_service.on_idempotency_conflict
38
39
  when :raise
39
- raise IdempotencyConflict, e.error
40
+ raise IdempotencyConflict.new(e.error)
40
41
  when :fetch
41
42
  return get(e.conflicting_resource_id)
42
43
  end
@@ -50,8 +51,9 @@ module GoCardlessPro
50
51
  Resources::Payment.new(unenvelope_body(response.body), response)
51
52
  end
52
53
 
53
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
54
- # payments.
54
+ # Returns a cursor-paginated
55
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
56
+ # list of your payments.
55
57
  # Example URL: /payments
56
58
  # @param options [Hash] parameters as a hash, under a params key.
57
59
  def list(options = {})
@@ -86,7 +88,7 @@ module GoCardlessPro
86
88
  # @param options [Hash] parameters as a hash, under a params key.
87
89
  def get(identity, options = {})
88
90
  path = sub_url('/payments/:identity', {
89
- 'identity' => identity
91
+ 'identity' => identity,
90
92
  })
91
93
 
92
94
  options[:retry_failures] = true
@@ -105,7 +107,7 @@ module GoCardlessPro
105
107
  # @param options [Hash] parameters as a hash, under a params key.
106
108
  def update(identity, options = {})
107
109
  path = sub_url('/payments/:identity', {
108
- 'identity' => identity
110
+ 'identity' => identity,
109
111
  })
110
112
 
111
113
  params = options.delete(:params) || {}
@@ -133,7 +135,7 @@ module GoCardlessPro
133
135
  # @param options [Hash] parameters as a hash, under a params key.
134
136
  def cancel(identity, options = {})
135
137
  path = sub_url('/payments/:identity/actions/cancel', {
136
- 'identity' => identity
138
+ 'identity' => identity,
137
139
  })
138
140
 
139
141
  params = options.delete(:params) || {}
@@ -151,7 +153,7 @@ module GoCardlessPro
151
153
  if e.idempotent_creation_conflict?
152
154
  case @api_service.on_idempotency_conflict
153
155
  when :raise
154
- raise IdempotencyConflict, e.error
156
+ raise IdempotencyConflict.new(e.error)
155
157
  when :fetch
156
158
  return get(e.conflicting_resource_id)
157
159
  end
@@ -165,12 +167,12 @@ module GoCardlessPro
165
167
  Resources::Payment.new(unenvelope_body(response.body), response)
166
168
  end
167
169
 
168
- # <a name="retry_failed"></a>Retries a failed payment if the underlying mandate
169
- # is active. You will receive a `resubmission_requested` webhook, but after that
170
- # retrying the payment follows the same process as its initial creation, so you
171
- # will receive a `submitted` webhook, followed by a `confirmed` or `failed`
172
- # event. Any metadata supplied to this endpoint will be stored against the
173
- # payment submission event it causes.
170
+ # Retries a failed payment if the underlying mandate is active. You will receive
171
+ # a `resubmission_requested` webhook, but after that retrying the payment
172
+ # follows the same process as its initial creation, so you will receive a
173
+ # `submitted` webhook, followed by a `confirmed` or `failed` event. Any metadata
174
+ # supplied to this endpoint will be stored against the payment submission event
175
+ # it causes.
174
176
  #
175
177
  # This will return a `retry_failed` error if the payment has not failed.
176
178
  #
@@ -181,7 +183,7 @@ module GoCardlessPro
181
183
  # @param options [Hash] parameters as a hash, under a params key.
182
184
  def retry(identity, options = {})
183
185
  path = sub_url('/payments/:identity/actions/retry', {
184
- 'identity' => identity
186
+ 'identity' => identity,
185
187
  })
186
188
 
187
189
  params = options.delete(:params) || {}
@@ -199,7 +201,7 @@ module GoCardlessPro
199
201
  if e.idempotent_creation_conflict?
200
202
  case @api_service.on_idempotency_conflict
201
203
  when :raise
202
- raise IdempotencyConflict, e.error
204
+ raise IdempotencyConflict.new(e.error)
203
205
  when :fetch
204
206
  return get(e.conflicting_resource_id)
205
207
  end
@@ -219,7 +221,13 @@ module GoCardlessPro
219
221
  #
220
222
  # @param body [Hash]
221
223
  def unenvelope_body(body)
222
- body[envelope_key] || body['data']
224
+ if body.key?(envelope_key)
225
+ body[envelope_key]
226
+ elsif body.key?('data')
227
+ body['data']
228
+ else
229
+ body
230
+ end
223
231
  end
224
232
 
225
233
  # return the key which API responses will envelope data under
@@ -10,13 +10,12 @@ module GoCardlessPro
10
10
  module Services
11
11
  # Service for making requests to the PayoutItem endpoints
12
12
  class PayoutItemsService < BaseService
13
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of items in
14
- # the payout.
15
- #
16
- # <strong>This endpoint only serves requests for payouts created in the last 6
17
- # months. Requests for older payouts will return an HTTP status <code>410
18
- # Gone</code>.</strong>
13
+ # Returns a cursor-paginated
14
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
15
+ # list of items in the payout.
19
16
  #
17
+ # This endpoint only serves requests for payouts created in the last 6 months.
18
+ # Requests for older payouts will return an HTTP status 410 Gone.
20
19
  # Example URL: /payout_items
21
20
  # @param options [Hash] parameters as a hash, under a params key.
22
21
  def list(options = {})
@@ -50,7 +49,13 @@ module GoCardlessPro
50
49
  #
51
50
  # @param body [Hash]
52
51
  def unenvelope_body(body)
53
- body[envelope_key] || body['data']
52
+ if body.key?(envelope_key)
53
+ body[envelope_key]
54
+ elsif body.key?('data')
55
+ body['data']
56
+ else
57
+ body
58
+ end
54
59
  end
55
60
 
56
61
  # 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 Payout endpoints
12
12
  class PayoutsService < BaseService
13
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
14
- # payouts.
13
+ # Returns a cursor-paginated
14
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
15
+ # list of your payouts.
15
16
  # Example URL: /payouts
16
17
  # @param options [Hash] parameters as a hash, under a params key.
17
18
  def list(options = {})
@@ -40,15 +41,15 @@ module GoCardlessPro
40
41
  end
41
42
 
42
43
  # Retrieves the details of a single payout. For an example of how to reconcile
43
- # the transactions in a payout, see [this
44
- # guide](#events-reconciling-payouts-with-events).
44
+ # the transactions in a payout, see this guide
45
+ # (https://developer.gocardless.com/api-reference/#events-reconciling-payouts-with-events).
45
46
  # Example URL: /payouts/:identity
46
47
  #
47
48
  # @param identity # Unique identifier, beginning with "PO".
48
49
  # @param options [Hash] parameters as a hash, under a params key.
49
50
  def get(identity, options = {})
50
51
  path = sub_url('/payouts/:identity', {
51
- 'identity' => identity
52
+ 'identity' => identity,
52
53
  })
53
54
 
54
55
  options[:retry_failures] = true
@@ -67,7 +68,7 @@ module GoCardlessPro
67
68
  # @param options [Hash] parameters as a hash, under a params key.
68
69
  def update(identity, options = {})
69
70
  path = sub_url('/payouts/:identity', {
70
- 'identity' => identity
71
+ 'identity' => identity,
71
72
  })
72
73
 
73
74
  params = options.delete(:params) || {}
@@ -89,7 +90,13 @@ module GoCardlessPro
89
90
  #
90
91
  # @param body [Hash]
91
92
  def unenvelope_body(body)
92
- body[envelope_key] || body['data']
93
+ if body.key?(envelope_key)
94
+ body[envelope_key]
95
+ elsif body.key?('data')
96
+ body['data']
97
+ else
98
+ body
99
+ end
93
100
  end
94
101
 
95
102
  # return the key which API responses will envelope data under
@@ -32,7 +32,7 @@ module GoCardlessPro
32
32
  if e.idempotent_creation_conflict?
33
33
  case @api_service.on_idempotency_conflict
34
34
  when :raise
35
- raise IdempotencyConflict, e.error
35
+ raise IdempotencyConflict.new(e.error)
36
36
  when :fetch
37
37
  return get(e.conflicting_resource_id)
38
38
  end
@@ -53,7 +53,7 @@ module GoCardlessPro
53
53
  # @param options [Hash] parameters as a hash, under a params key.
54
54
  def get(identity, options = {})
55
55
  path = sub_url('/redirect_flows/:identity', {
56
- 'identity' => identity
56
+ 'identity' => identity,
57
57
  })
58
58
 
59
59
  options[:retry_failures] = true
@@ -65,10 +65,14 @@ module GoCardlessPro
65
65
  Resources::RedirectFlow.new(unenvelope_body(response.body), response)
66
66
  end
67
67
 
68
- # This creates a [customer](#core-endpoints-customers), [customer bank
69
- # account](#core-endpoints-customer-bank-accounts), and
70
- # [mandate](#core-endpoints-mandates) using the details supplied by your
71
- # customer and returns the ID of the created mandate.
68
+ # This creates a customer
69
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-customers),
70
+ # customer bank account
71
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-customer-bank-accounts),
72
+ # and mandate
73
+ # (https://developer.gocardless.com/api-reference/#core-endpoints-mandates)
74
+ # using the details supplied by your customer and returns the ID of the created
75
+ # mandate.
72
76
  #
73
77
  # This will return a `redirect_flow_incomplete` error if your customer has not
74
78
  # yet been redirected back to your site, and a `redirect_flow_already_completed`
@@ -81,7 +85,7 @@ module GoCardlessPro
81
85
  # @param options [Hash] parameters as a hash, under a params key.
82
86
  def complete(identity, options = {})
83
87
  path = sub_url('/redirect_flows/:identity/actions/complete', {
84
- 'identity' => identity
88
+ 'identity' => identity,
85
89
  })
86
90
 
87
91
  params = options.delete(:params) || {}
@@ -99,7 +103,7 @@ module GoCardlessPro
99
103
  if e.idempotent_creation_conflict?
100
104
  case @api_service.on_idempotency_conflict
101
105
  when :raise
102
- raise IdempotencyConflict, e.error
106
+ raise IdempotencyConflict.new(e.error)
103
107
  when :fetch
104
108
  return get(e.conflicting_resource_id)
105
109
  end
@@ -119,7 +123,13 @@ module GoCardlessPro
119
123
  #
120
124
  # @param body [Hash]
121
125
  def unenvelope_body(body)
122
- body[envelope_key] || body['data']
126
+ if body.key?(envelope_key)
127
+ body[envelope_key]
128
+ elsif body.key?('data')
129
+ body['data']
130
+ else
131
+ body
132
+ end
123
133
  end
124
134
 
125
135
  # return the key which API responses will envelope data under
@@ -12,18 +12,16 @@ module GoCardlessPro
12
12
  class RefundsService < BaseService
13
13
  # Creates a new refund object.
14
14
  #
15
- # This fails with:<a name="total_amount_confirmation_invalid"></a><a
16
- # name="number_of_refunds_exceeded"></a><a
17
- # name="available_refund_amount_insufficient"></a>
15
+ # This fails with:
18
16
  #
19
- # - `total_amount_confirmation_invalid` if the confirmation amount doesn't match
17
+ # -
18
+ # `total_amount_confirmation_invalid` if the confirmation amount doesn't match
20
19
  # the total amount refunded for the payment. This safeguard is there to prevent
21
20
  # two processes from creating refunds without awareness of each other.
22
- #
23
- # - `available_refund_amount_insufficient` if the creditor does not have
21
+ # -
22
+ # `available_refund_amount_insufficient` if the creditor does not have
24
23
  # sufficient balance for refunds available to cover the cost of the requested
25
24
  # refund.
26
- #
27
25
  # Example URL: /refunds
28
26
  # @param options [Hash] parameters as a hash, under a params key.
29
27
  def create(options = {})
@@ -44,7 +42,7 @@ module GoCardlessPro
44
42
  if e.idempotent_creation_conflict?
45
43
  case @api_service.on_idempotency_conflict
46
44
  when :raise
47
- raise IdempotencyConflict, e.error
45
+ raise IdempotencyConflict.new(e.error)
48
46
  when :fetch
49
47
  return get(e.conflicting_resource_id)
50
48
  end
@@ -58,8 +56,9 @@ module GoCardlessPro
58
56
  Resources::Refund.new(unenvelope_body(response.body), response)
59
57
  end
60
58
 
61
- # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
62
- # refunds.
59
+ # Returns a cursor-paginated
60
+ # (https://developer.gocardless.com/api-reference/#api-usage-cursor-pagination)
61
+ # list of your refunds.
63
62
  # Example URL: /refunds
64
63
  # @param options [Hash] parameters as a hash, under a params key.
65
64
  def list(options = {})
@@ -94,7 +93,7 @@ module GoCardlessPro
94
93
  # @param options [Hash] parameters as a hash, under a params key.
95
94
  def get(identity, options = {})
96
95
  path = sub_url('/refunds/:identity', {
97
- 'identity' => identity
96
+ 'identity' => identity,
98
97
  })
99
98
 
100
99
  options[:retry_failures] = true
@@ -113,7 +112,7 @@ module GoCardlessPro
113
112
  # @param options [Hash] parameters as a hash, under a params key.
114
113
  def update(identity, options = {})
115
114
  path = sub_url('/refunds/:identity', {
116
- 'identity' => identity
115
+ 'identity' => identity,
117
116
  })
118
117
 
119
118
  params = options.delete(:params) || {}
@@ -135,7 +134,13 @@ module GoCardlessPro
135
134
  #
136
135
  # @param body [Hash]
137
136
  def unenvelope_body(body)
138
- body[envelope_key] || body['data']
137
+ if body.key?(envelope_key)
138
+ body[envelope_key]
139
+ elsif body.key?('data')
140
+ body['data']
141
+ else
142
+ body
143
+ end
139
144
  end
140
145
 
141
146
  # return the key which API responses will envelope data under
@@ -15,133 +15,136 @@ module GoCardlessPro
15
15
  #
16
16
  # @param identity # The unique identifier of the simulator, used to initiate simulations.
17
17
  # One of:
18
- # <ul>
19
- # <li>`creditor_verification_status_action_required`: Sets a creditor's
18
+ #
19
+ # - `creditor_verification_status_action_required`: Sets a creditor's
20
20
  # `verification status` to `action required`, meaning that the creditor
21
21
  # must provide further information to GoCardless in order to verify their
22
- # account to receive payouts.</li>
23
- # <li>`creditor_verification_status_in_review`: Sets a creditor's
22
+ # account to receive payouts.
23
+ # - `creditor_verification_status_in_review`: Sets a creditor's
24
24
  # `verification status` to `in review`, meaning that the creditor has
25
25
  # provided all of the information requested by GoCardless to verify their
26
- # account, and is now awaiting review.</li>
27
- # <li>`creditor_verification_status_successful`: Sets a creditor's
26
+ # account, and is now awaiting review.
27
+ # - `creditor_verification_status_successful`: Sets a creditor's
28
28
  # `verification status` to `successful`, meaning that the creditor is
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>
35
- # <li>`payment_paid_out`: Transitions a payment through to `paid_out`,
29
+ # fully verified and can receive payouts.
30
+ # - `payment_confirmed`: Transitions a payment through to `confirmed`. It
31
+ # must start in the `pending_submission` state, and its mandate must be in
32
+ # the `activated` state (unless it is a payment for ACH, BECS, BECS_NZ or
33
+ # SEPA, in which cases the mandate may be `pending_submission`, since
34
+ # their mandates are submitted with their first payment).
35
+ # - `payment_paid_out`: Transitions a payment through to `paid_out`,
36
36
  # having been collected successfully and paid out to you. It must start in
37
37
  # the `pending_submission` state, and its mandate must be in the
38
38
  # `activated` state (unless it is a payment for ACH, BECS, BECS_NZ or
39
39
  # SEPA, in which cases the mandate may be `pending_submission`, since
40
- # their mandates are submitted with their first payment).</li>
41
- # <li>`payment_failed`: Transitions a payment through to `failed`. It must
40
+ # their mandates are submitted with their first payment).
41
+ # - `payment_failed`: Transitions a payment through to `failed`. It must
42
42
  # start in the `pending_submission` state, and its mandate must be in the
43
43
  # `activated` state (unless it is a payment for ACH, BECS, BECS_NZ or
44
44
  # SEPA, in which cases the mandate may be `pending_submission`, since
45
- # their mandates are submitted with their first payment).</li>
46
- # <li>`payment_charged_back`: Behaves the same as the `payout_paid_out`
45
+ # their mandates are submitted with their first payment).
46
+ # - `payment_charged_back`: Behaves the same as the `payout_paid_out`
47
47
  # simulator, except that the payment is transitioned to `charged_back`
48
- # after it is paid out, having been charged back by the customer.</li>
49
- # <li>`payment_chargeback_settled`: Behaves the same as the
48
+ # after it is paid out, having been charged back by the customer.
49
+ # - `payment_chargeback_settled`: Behaves the same as the
50
50
  # `payment_charged_back` simulator, except that the charged back payment
51
51
  # is additionally included as a debit item in a payout, thereby settling
52
- # the charged back payment.</li>
53
- # <li>`payment_late_failure`: Transitions a payment through to
52
+ # the charged back payment.
53
+ # - `payment_late_failure`: Transitions a payment through to
54
54
  # `late_failure`, having been apparently collected successfully
55
55
  # beforehand. It must start in either the `pending_submission` or
56
56
  # `paid_out` state, and its mandate must be in the `activated` state
57
57
  # (unless it is a payment for ACH, BECS, BECS_NZ or SEPA, in which cases
58
58
  # the mandate may be `pending_submission`, since their mandates are
59
59
  # submitted with their first payment). Not compatible with Autogiro
60
- # mandates.</li>
61
- # <li>`payment_late_failure_settled`: Behaves the same as the
60
+ # mandates.
61
+ # - `payment_late_failure_settled`: Behaves the same as the
62
62
  # `payment_late_failure` simulator, except that the late failure is
63
63
  # additionally included as a debit item in a payout, thereby settling the
64
- # late failure.</li>
65
- # <li>`payment_submitted`: Transitions a payment to `submitted`, without
66
- # proceeding any further. It must start in the `pending_submission`
67
- # state.</li>
68
- # <li>`mandate_activated`: Transitions a mandate through to `activated`,
64
+ # late failure.
65
+ # - `payment_submitted`: Transitions a payment to `submitted`, without
66
+ # proceeding any further. It must start in the `pending_submission` state.
67
+ # - `mandate_activated`: Transitions a mandate through to `activated`,
69
68
  # having been submitted to the banks and set up successfully. It must
70
69
  # start in the `pending_submission` state. Not compatible with ACH, BECS,
71
70
  # BECS_NZ and SEPA mandates, which are submitted and activated with their
72
- # first payment.</li>
73
- # <li>`mandate_customer_approval_granted`: Transitions a mandate through
74
- # to `pending_submission`, as if the customer approved the mandate
75
- # creation. It must start in the `pending_customer_approval` state.
76
- # Compatible only with Bacs and SEPA mandates, which support customer
77
- # signatures on the mandate. All payments associated with the mandate will
78
- # be transitioned to `pending_submission`. All subscriptions associated
79
- # with the mandate will become `active`.</li>
80
- # <li>`mandate_customer_approval_skipped`: Transitions a mandate through
81
- # to `pending_submission`, as if the customer skipped the mandate approval
71
+ # first payment.
72
+ # - `mandate_customer_approval_granted`: Transitions a mandate through to
73
+ # `pending_submission`, as if the customer approved the mandate creation.
74
+ # It must start in the `pending_customer_approval` state. Compatible only
75
+ # with Bacs and SEPA mandates, which support customer signatures on the
76
+ # mandate. All payments associated with the mandate will be transitioned
77
+ # to `pending_submission`. All subscriptions associated with the mandate
78
+ # will become `active`.
79
+ # - `mandate_customer_approval_skipped`: Transitions a mandate through to
80
+ # `pending_submission`, as if the customer skipped the mandate approval
82
81
  # during the mandate creation process. It must start in the
83
82
  # `pending_customer_approval` state. Compatible only with Bacs and SEPA
84
83
  # mandates, which support customer signatures on the mandate. All payments
85
84
  # associated with the mandate will be transitioned to
86
85
  # `pending_submission`. All subscriptions associated with the mandate will
87
- # become `active`.</li>
88
- # <li>`mandate_failed`: Transitions a mandate through to `failed`, having
86
+ # become `active`.
87
+ # - `mandate_failed`: Transitions a mandate through to `failed`, having
89
88
  # been submitted to the banks but found to be invalid (for example due to
90
89
  # invalid bank details). It must start in the `pending_submission` or
91
90
  # `submitted` states. Not compatible with SEPA mandates, which are
92
- # submitted with their first payment.</li>
93
- # <li>`mandate_expired`: Transitions a mandate through to `expired`,
94
- # having been submitted to the banks, set up successfully and then expired
91
+ # submitted with their first payment.
92
+ # - `mandate_expired`: Transitions a mandate through to `expired`, having
93
+ # been submitted to the banks, set up successfully and then expired
95
94
  # because no collection attempts were made against it for longer than the
96
95
  # scheme's dormancy period (13 months for Bacs, 3 years for SEPA, 15
97
96
  # months for ACH, Betalingsservice, and BECS). It must start in the
98
97
  # `pending_submission` state. Not compatible with Autogiro, BECS NZ, and
99
- # PAD mandates, which do not expire.</li>
100
- # <li>`mandate_transferred`: Transitions a mandate through to
101
- # `transferred`, having been submitted to the banks, set up successfully
102
- # and then moved to a new bank account due to the customer using the UK's
103
- # Current Account Switching Service (CASS). It must start in the
104
- # `pending_submission` state. Only compatible with Bacs mandates.</li>
105
- # <li>`mandate_transferred_with_resubmission`: Transitions a mandate
106
- # through `transferred` and resubmits it to the banks, can be caused be
107
- # the UK's Current Account Switching Service (CASS) or when a customer
108
- # contacts GoCardless to change their bank details. It must start in the
109
- # `pending_submission` state. Only compatible with Bacs mandates.</li>
110
- # <li>`mandate_suspended_by_payer`: Transitions a mandate to
98
+ # PAD mandates, which do not expire.
99
+ # - `mandate_transferred`: Transitions a mandate through to `transferred`,
100
+ # having been submitted to the banks, set up successfully and then moved
101
+ # to a new bank account due. It must start in the `pending_submission`
102
+ # state. Only compatible with Bacs and SEPA mandates.
103
+ # - `mandate_transferred_with_resubmission`: Transitions a mandate through
104
+ # `transferred` and resubmits it to the banks, can be caused be the UK's
105
+ # Current Account Switching Service (CASS) or when a customer contacts
106
+ # GoCardless to change their bank details. It must start in the
107
+ # `pending_submission` state. Only compatible with Bacs mandates.
108
+ # - `mandate_suspended_by_payer`: Transitions a mandate to
111
109
  # `suspended_by_payer`, as if payer has suspended the mandate after it has
112
110
  # been setup successfully. It must start in the `activated` state. Only
113
- # compatible with PAY_TO mandates.</li>
114
- # <li>`refund_paid`: Transitions a refund to `paid`. It must start in
115
- # either the `pending_submission` or `submitted` state.</li>
116
- # <li>`refund_settled`: Transitions a refund to `paid`, if it's not
117
- # already, then generates a payout that includes the refund, thereby
118
- # settling the funds. It must start in one of `pending_submission`,
119
- # `submitted` or `paid` states.</li>
120
- # <li>`refund_bounced`: Transitions a refund to `bounced`. It must start
121
- # in either the `pending_submission`, `submitted`, or `paid` state.</li>
122
- # <li>`refund_returned`: Transitions a refund to `refund_returned`. The
123
- # refund must start in `pending_submission`.</li>
124
- # <li>`payout_bounced`: Transitions a payout to `bounced`. It must start
125
- # in the `paid` state.</li>
126
- # <li>`billing_request_fulfilled`: Authorises the billing request, and
127
- # then fulfils it. The billing request must be in the `pending` state,
128
- # with all actions completed except for `bank_authorisation`. Only billing
129
- # requests with a `payment_request` are supported.</li>
130
- # <li>`billing_request_fulfilled_and_payment_failed`: Authorises the
131
- # billing request, fulfils it, and moves the associated payment to
132
- # `failed`. The billing request must be in the `pending` state, with all
111
+ # compatible with PAY_TO mandates.
112
+ # - `refund_paid`: Transitions a refund to `paid`. It must start in either
113
+ # the `pending_submission` or `submitted` state.
114
+ # - `refund_settled`: Transitions a refund to `paid`, if it's not already,
115
+ # then generates a payout that includes the refund, thereby settling the
116
+ # funds. It must start in one of `pending_submission`, `submitted` or
117
+ # `paid` states.
118
+ # - `refund_bounced`: Transitions a refund to `bounced`. It must start in
119
+ # either the `pending_submission`, `submitted`, or `paid` state.
120
+ # - `refund_returned`: Transitions a refund to `refund_returned`. The
121
+ # refund must start in `pending_submission`.
122
+ # - `payout_bounced`: Transitions a payout to `bounced`. It must start in
123
+ # the `paid` state.
124
+ # - `billing_request_fulfilled`: Authorises the billing request, and then
125
+ # fulfils it. The billing request must be in the `pending` state, with all
133
126
  # actions completed except for `bank_authorisation`. Only billing requests
134
- # with a `payment_request` are supported.</li>
135
- # <li>`billing_request_fulfilled_and_payment_paid_out`: Authorises the
127
+ # with a `payment_request` are supported.
128
+ # - `billing_request_fulfilled_and_payment_failed`: Authorises the billing
129
+ # request, fulfils it, and moves the associated payment to `failed`. The
130
+ # billing request must be in the `pending` state, with all actions
131
+ # completed except for `bank_authorisation`. Only billing requests with a
132
+ # `payment_request` are supported.
133
+ # - `billing_request_fulfilled_and_payment_confirmed_to_failed`:
134
+ # Authorises the billing request, fulfils it, moves the associated payment
135
+ # to `confirmed` and then moves it to `failed`. The billing request must
136
+ # be in the `pending` state, with all actions completed except for
137
+ # `bank_authorisation`. Only billing requests with a `payment_request` are
138
+ # supported.
139
+ # - `billing_request_fulfilled_and_payment_paid_out`: Authorises the
136
140
  # billing request, fulfils it, and moves the associated payment to
137
141
  # `paid_out`. The billing request must be in the `pending` state, with all
138
142
  # actions completed except for `bank_authorisation`. Only billing requests
139
- # with a `payment_request` are supported.</li>
140
- # </ul>
143
+ # with a `payment_request` are supported.
141
144
  # @param options [Hash] parameters as a hash, under a params key.
142
145
  def run(identity, options = {})
143
146
  path = sub_url('/scenario_simulators/:identity/actions/run', {
144
- 'identity' => identity
147
+ 'identity' => identity,
145
148
  })
146
149
 
147
150
  params = options.delete(:params) || {}
@@ -163,7 +166,13 @@ module GoCardlessPro
163
166
  #
164
167
  # @param body [Hash]
165
168
  def unenvelope_body(body)
166
- body[envelope_key] || body['data']
169
+ if body.key?(envelope_key)
170
+ body[envelope_key]
171
+ elsif body.key?('data')
172
+ body['data']
173
+ else
174
+ body
175
+ end
167
176
  end
168
177
 
169
178
  # return the key which API responses will envelope data under