gocardless_pro 2.25.0 → 2.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -3
- data/lib/gocardless_pro.rb +18 -0
- data/lib/gocardless_pro/client.rb +31 -1
- data/lib/gocardless_pro/resources/bank_authorisation.rb +87 -0
- data/lib/gocardless_pro/resources/billing_request.rb +86 -0
- data/lib/gocardless_pro/resources/billing_request_flow.rb +62 -0
- data/lib/gocardless_pro/resources/creditor.rb +2 -3
- data/lib/gocardless_pro/resources/institution.rb +45 -0
- data/lib/gocardless_pro/resources/payer_authorisation.rb +3 -0
- data/lib/gocardless_pro/resources/scenario_simulator.rb +42 -0
- data/lib/gocardless_pro/resources/webhook.rb +62 -0
- data/lib/gocardless_pro/services/bank_authorisations_service.rb +82 -0
- data/lib/gocardless_pro/services/billing_request_flows_service.rb +47 -0
- data/lib/gocardless_pro/services/billing_requests_service.rb +325 -0
- data/lib/gocardless_pro/services/institutions_service.rb +56 -0
- data/lib/gocardless_pro/services/payer_authorisations_service.rb +5 -5
- data/lib/gocardless_pro/services/scenario_simulators_service.rb +148 -0
- data/lib/gocardless_pro/services/subscriptions_service.rb +8 -3
- data/lib/gocardless_pro/services/webhooks_service.rb +113 -0
- data/lib/gocardless_pro/version.rb +1 -1
- data/spec/resources/bank_authorisation_spec.rb +259 -0
- data/spec/resources/billing_request_flow_spec.rb +129 -0
- data/spec/resources/billing_request_spec.rb +736 -0
- data/spec/resources/institution_spec.rb +103 -0
- data/spec/resources/scenario_simulator_spec.rb +63 -0
- data/spec/resources/webhook_spec.rb +323 -0
- data/spec/services/bank_authorisations_service_spec.rb +366 -0
- data/spec/services/billing_request_flows_service_spec.rb +152 -0
- data/spec/services/billing_requests_service_spec.rb +1042 -0
- data/spec/services/institutions_service_spec.rb +223 -0
- data/spec/services/scenario_simulators_service_spec.rb +74 -0
- data/spec/services/webhooks_service_spec.rb +545 -0
- metadata +39 -3
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#
|
4
|
+
# This client is automatically generated from a template and JSON schema definition.
|
5
|
+
# See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'uri'
|
9
|
+
|
10
|
+
module GoCardlessPro
|
11
|
+
# A module containing classes for each of the resources in the GC Api
|
12
|
+
module Resources
|
13
|
+
# Represents an instance of a scenario_simulator resource returned from the API
|
14
|
+
|
15
|
+
# Scenario Simulators allow you to manually trigger and test certain paths
|
16
|
+
# that your
|
17
|
+
# integration will encounter in the real world. These endpoints are only
|
18
|
+
# active in the
|
19
|
+
# sandbox environment.
|
20
|
+
class ScenarioSimulator
|
21
|
+
attr_reader :id
|
22
|
+
|
23
|
+
# Initialize a scenario_simulator resource instance
|
24
|
+
# @param object [Hash] an object returned from the API
|
25
|
+
def initialize(object, response = nil)
|
26
|
+
@object = object
|
27
|
+
|
28
|
+
@id = object['id']
|
29
|
+
@response = response
|
30
|
+
end
|
31
|
+
|
32
|
+
def api_response
|
33
|
+
ApiResponse.new(@response)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Provides the scenario_simulator resource as a hash of all its readable attributes
|
37
|
+
def to_h
|
38
|
+
@object
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#
|
4
|
+
# This client is automatically generated from a template and JSON schema definition.
|
5
|
+
# See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'uri'
|
9
|
+
|
10
|
+
module GoCardlessPro
|
11
|
+
# A module containing classes for each of the resources in the GC Api
|
12
|
+
module Resources
|
13
|
+
# Represents an instance of a webhook resource returned from the API
|
14
|
+
|
15
|
+
# Basic description of a webhook
|
16
|
+
class Webhook
|
17
|
+
attr_reader :created_at
|
18
|
+
attr_reader :id
|
19
|
+
attr_reader :is_test
|
20
|
+
attr_reader :request_body
|
21
|
+
attr_reader :request_headers
|
22
|
+
attr_reader :response_body
|
23
|
+
attr_reader :response_body_truncated
|
24
|
+
attr_reader :response_code
|
25
|
+
attr_reader :response_headers
|
26
|
+
attr_reader :response_headers_content_truncated
|
27
|
+
attr_reader :response_headers_count_truncated
|
28
|
+
attr_reader :successful
|
29
|
+
attr_reader :url
|
30
|
+
|
31
|
+
# Initialize a webhook resource instance
|
32
|
+
# @param object [Hash] an object returned from the API
|
33
|
+
def initialize(object, response = nil)
|
34
|
+
@object = object
|
35
|
+
|
36
|
+
@created_at = object['created_at']
|
37
|
+
@id = object['id']
|
38
|
+
@is_test = object['is_test']
|
39
|
+
@request_body = object['request_body']
|
40
|
+
@request_headers = object['request_headers']
|
41
|
+
@response_body = object['response_body']
|
42
|
+
@response_body_truncated = object['response_body_truncated']
|
43
|
+
@response_code = object['response_code']
|
44
|
+
@response_headers = object['response_headers']
|
45
|
+
@response_headers_content_truncated = object['response_headers_content_truncated']
|
46
|
+
@response_headers_count_truncated = object['response_headers_count_truncated']
|
47
|
+
@successful = object['successful']
|
48
|
+
@url = object['url']
|
49
|
+
@response = response
|
50
|
+
end
|
51
|
+
|
52
|
+
def api_response
|
53
|
+
ApiResponse.new(@response)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Provides the webhook resource as a hash of all its readable attributes
|
57
|
+
def to_h
|
58
|
+
@object
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,82 @@
|
|
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 BankAuthorisation endpoints
|
12
|
+
class BankAuthorisationsService < BaseService
|
13
|
+
# Fetches a bank authorisation
|
14
|
+
# Example URL: /bank_authorisations/:identity
|
15
|
+
#
|
16
|
+
# @param identity # Unique identifier, beginning with "BAU".
|
17
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
18
|
+
def get(identity, options = {})
|
19
|
+
path = sub_url('/bank_authorisations/:identity', 'identity' => identity)
|
20
|
+
|
21
|
+
options[:retry_failures] = true
|
22
|
+
|
23
|
+
response = make_request(:get, path, options)
|
24
|
+
|
25
|
+
return if response.body.nil?
|
26
|
+
|
27
|
+
Resources::BankAuthorisation.new(unenvelope_body(response.body), response)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create a Bank Authorisation.
|
31
|
+
# Example URL: /bank_authorisations
|
32
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
33
|
+
def create(options = {})
|
34
|
+
path = '/bank_authorisations'
|
35
|
+
|
36
|
+
params = options.delete(:params) || {}
|
37
|
+
options[:params] = {}
|
38
|
+
options[:params][envelope_key] = params
|
39
|
+
|
40
|
+
options[:retry_failures] = true
|
41
|
+
|
42
|
+
begin
|
43
|
+
response = make_request(:post, path, options)
|
44
|
+
|
45
|
+
# Response doesn't raise any errors until #body is called
|
46
|
+
response.tap(&:body)
|
47
|
+
rescue InvalidStateError => e
|
48
|
+
if e.idempotent_creation_conflict?
|
49
|
+
case @api_service.on_idempotency_conflict
|
50
|
+
when :raise
|
51
|
+
raise IdempotencyConflict, e.error
|
52
|
+
when :fetch
|
53
|
+
return get(e.conflicting_resource_id)
|
54
|
+
else
|
55
|
+
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
raise e
|
60
|
+
end
|
61
|
+
|
62
|
+
return if response.body.nil?
|
63
|
+
|
64
|
+
Resources::BankAuthorisation.new(unenvelope_body(response.body), response)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
# Unenvelope the response of the body using the service's `envelope_key`
|
70
|
+
#
|
71
|
+
# @param body [Hash]
|
72
|
+
def unenvelope_body(body)
|
73
|
+
body[envelope_key] || body['data']
|
74
|
+
end
|
75
|
+
|
76
|
+
# return the key which API responses will envelope data under
|
77
|
+
def envelope_key
|
78
|
+
'bank_authorisations'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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 BillingRequestFlow endpoints
|
12
|
+
class BillingRequestFlowsService < BaseService
|
13
|
+
# Creates a new billing request flow.
|
14
|
+
# Example URL: /billing_request_flows
|
15
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
16
|
+
def create(options = {})
|
17
|
+
path = '/billing_request_flows'
|
18
|
+
|
19
|
+
params = options.delete(:params) || {}
|
20
|
+
options[:params] = {}
|
21
|
+
options[:params][envelope_key] = params
|
22
|
+
|
23
|
+
options[:retry_failures] = true
|
24
|
+
|
25
|
+
response = make_request(:post, path, options)
|
26
|
+
|
27
|
+
return if response.body.nil?
|
28
|
+
|
29
|
+
Resources::BillingRequestFlow.new(unenvelope_body(response.body), response)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Unenvelope the response of the body using the service's `envelope_key`
|
35
|
+
#
|
36
|
+
# @param body [Hash]
|
37
|
+
def unenvelope_body(body)
|
38
|
+
body[envelope_key] || body['data']
|
39
|
+
end
|
40
|
+
|
41
|
+
# return the key which API responses will envelope data under
|
42
|
+
def envelope_key
|
43
|
+
'billing_request_flows'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,325 @@
|
|
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 BillingRequest endpoints
|
12
|
+
class BillingRequestsService < BaseService
|
13
|
+
# Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
|
14
|
+
# billing_requests.
|
15
|
+
# Example URL: /billing_requests
|
16
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
17
|
+
def list(options = {})
|
18
|
+
path = '/billing_requests'
|
19
|
+
|
20
|
+
options[:retry_failures] = true
|
21
|
+
|
22
|
+
response = make_request(:get, path, options)
|
23
|
+
|
24
|
+
ListResponse.new(
|
25
|
+
response: response,
|
26
|
+
unenveloped_body: unenvelope_body(response.body),
|
27
|
+
resource_class: Resources::BillingRequest
|
28
|
+
)
|
29
|
+
end
|
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.
|
32
|
+
#
|
33
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
34
|
+
# Otherwise they will be the body of the request.
|
35
|
+
def all(options = {})
|
36
|
+
Paginator.new(
|
37
|
+
service: self,
|
38
|
+
options: options
|
39
|
+
).enumerator
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Example URL: /billing_requests
|
44
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
45
|
+
def create(options = {})
|
46
|
+
path = '/billing_requests'
|
47
|
+
|
48
|
+
params = options.delete(:params) || {}
|
49
|
+
options[:params] = {}
|
50
|
+
options[:params][envelope_key] = params
|
51
|
+
|
52
|
+
options[:retry_failures] = true
|
53
|
+
|
54
|
+
begin
|
55
|
+
response = make_request(:post, path, options)
|
56
|
+
|
57
|
+
# Response doesn't raise any errors until #body is called
|
58
|
+
response.tap(&:body)
|
59
|
+
rescue InvalidStateError => e
|
60
|
+
if e.idempotent_creation_conflict?
|
61
|
+
case @api_service.on_idempotency_conflict
|
62
|
+
when :raise
|
63
|
+
raise IdempotencyConflict, e.error
|
64
|
+
when :fetch
|
65
|
+
return get(e.conflicting_resource_id)
|
66
|
+
else
|
67
|
+
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
raise e
|
72
|
+
end
|
73
|
+
|
74
|
+
return if response.body.nil?
|
75
|
+
|
76
|
+
Resources::BillingRequest.new(unenvelope_body(response.body), response)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Fetches a billing request
|
80
|
+
# Example URL: /billing_requests/:identity
|
81
|
+
#
|
82
|
+
# @param identity # Unique identifier, beginning with "PY".
|
83
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
84
|
+
def get(identity, options = {})
|
85
|
+
path = sub_url('/billing_requests/:identity', 'identity' => identity)
|
86
|
+
|
87
|
+
options[:retry_failures] = true
|
88
|
+
|
89
|
+
response = make_request(:get, path, options)
|
90
|
+
|
91
|
+
return if response.body.nil?
|
92
|
+
|
93
|
+
Resources::BillingRequest.new(unenvelope_body(response.body), response)
|
94
|
+
end
|
95
|
+
|
96
|
+
# If the billing request has a pending <code>collect_customer_details</code>
|
97
|
+
# action, this endpoint can be used to collect the details in order to
|
98
|
+
# complete it.
|
99
|
+
#
|
100
|
+
# The endpoint takes the same payload as Customers, but checks that the
|
101
|
+
# customer fields are populated correctly for the billing request scheme.
|
102
|
+
#
|
103
|
+
# Whatever is provided to this endpoint is used to update the referenced
|
104
|
+
# customer, and will take effect immediately after the request is
|
105
|
+
# successful.
|
106
|
+
# Example URL: /billing_requests/:identity/actions/collect_customer_details
|
107
|
+
#
|
108
|
+
# @param identity # Unique identifier, beginning with "PY".
|
109
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
110
|
+
def collect_customer_details(identity, options = {})
|
111
|
+
path = sub_url('/billing_requests/:identity/actions/collect_customer_details', 'identity' => identity)
|
112
|
+
|
113
|
+
params = options.delete(:params) || {}
|
114
|
+
options[:params] = {}
|
115
|
+
options[:params]['data'] = params
|
116
|
+
|
117
|
+
options[:retry_failures] = false
|
118
|
+
|
119
|
+
begin
|
120
|
+
response = make_request(:post, path, options)
|
121
|
+
|
122
|
+
# Response doesn't raise any errors until #body is called
|
123
|
+
response.tap(&:body)
|
124
|
+
rescue InvalidStateError => e
|
125
|
+
if e.idempotent_creation_conflict?
|
126
|
+
case @api_service.on_idempotency_conflict
|
127
|
+
when :raise
|
128
|
+
raise IdempotencyConflict, e.error
|
129
|
+
when :fetch
|
130
|
+
return get(e.conflicting_resource_id)
|
131
|
+
else
|
132
|
+
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
raise e
|
137
|
+
end
|
138
|
+
|
139
|
+
return if response.body.nil?
|
140
|
+
|
141
|
+
Resources::BillingRequest.new(unenvelope_body(response.body), response)
|
142
|
+
end
|
143
|
+
|
144
|
+
# If the billing request has a pending
|
145
|
+
# <code>collect_bank_account_details</code> action, this endpoint can be
|
146
|
+
# used to collect the details in order to complete it.
|
147
|
+
#
|
148
|
+
# The endpoint takes the same payload as Customer Bank Accounts, but check
|
149
|
+
# the bank account is valid for the billing request scheme before creating
|
150
|
+
# and attaching it.
|
151
|
+
# Example URL: /billing_requests/:identity/actions/collect_bank_account_details
|
152
|
+
#
|
153
|
+
# @param identity # Unique identifier, beginning with "PY".
|
154
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
155
|
+
def collect_bank_account_details(identity, options = {})
|
156
|
+
path = sub_url('/billing_requests/:identity/actions/collect_bank_account_details', 'identity' => identity)
|
157
|
+
|
158
|
+
params = options.delete(:params) || {}
|
159
|
+
options[:params] = {}
|
160
|
+
options[:params]['data'] = params
|
161
|
+
|
162
|
+
options[:retry_failures] = false
|
163
|
+
|
164
|
+
begin
|
165
|
+
response = make_request(:post, path, options)
|
166
|
+
|
167
|
+
# Response doesn't raise any errors until #body is called
|
168
|
+
response.tap(&:body)
|
169
|
+
rescue InvalidStateError => e
|
170
|
+
if e.idempotent_creation_conflict?
|
171
|
+
case @api_service.on_idempotency_conflict
|
172
|
+
when :raise
|
173
|
+
raise IdempotencyConflict, e.error
|
174
|
+
when :fetch
|
175
|
+
return get(e.conflicting_resource_id)
|
176
|
+
else
|
177
|
+
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
raise e
|
182
|
+
end
|
183
|
+
|
184
|
+
return if response.body.nil?
|
185
|
+
|
186
|
+
Resources::BillingRequest.new(unenvelope_body(response.body), response)
|
187
|
+
end
|
188
|
+
|
189
|
+
# If a billing request is ready to be fulfilled, call this endpoint to cause
|
190
|
+
# it to fulfil, executing the payment.
|
191
|
+
# Example URL: /billing_requests/:identity/actions/fulfil
|
192
|
+
#
|
193
|
+
# @param identity # Unique identifier, beginning with "PY".
|
194
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
195
|
+
def fulfil(identity, options = {})
|
196
|
+
path = sub_url('/billing_requests/:identity/actions/fulfil', 'identity' => identity)
|
197
|
+
|
198
|
+
params = options.delete(:params) || {}
|
199
|
+
options[:params] = {}
|
200
|
+
options[:params]['data'] = params
|
201
|
+
|
202
|
+
options[:retry_failures] = false
|
203
|
+
|
204
|
+
begin
|
205
|
+
response = make_request(:post, path, options)
|
206
|
+
|
207
|
+
# Response doesn't raise any errors until #body is called
|
208
|
+
response.tap(&:body)
|
209
|
+
rescue InvalidStateError => e
|
210
|
+
if e.idempotent_creation_conflict?
|
211
|
+
case @api_service.on_idempotency_conflict
|
212
|
+
when :raise
|
213
|
+
raise IdempotencyConflict, e.error
|
214
|
+
when :fetch
|
215
|
+
return get(e.conflicting_resource_id)
|
216
|
+
else
|
217
|
+
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
raise e
|
222
|
+
end
|
223
|
+
|
224
|
+
return if response.body.nil?
|
225
|
+
|
226
|
+
Resources::BillingRequest.new(unenvelope_body(response.body), response)
|
227
|
+
end
|
228
|
+
|
229
|
+
# Immediately cancels a billing request, causing all billing request flows
|
230
|
+
# to expire.
|
231
|
+
# Example URL: /billing_requests/:identity/actions/cancel
|
232
|
+
#
|
233
|
+
# @param identity # Unique identifier, beginning with "PY".
|
234
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
235
|
+
def cancel(identity, options = {})
|
236
|
+
path = sub_url('/billing_requests/:identity/actions/cancel', 'identity' => identity)
|
237
|
+
|
238
|
+
params = options.delete(:params) || {}
|
239
|
+
options[:params] = {}
|
240
|
+
options[:params]['data'] = params
|
241
|
+
|
242
|
+
options[:retry_failures] = false
|
243
|
+
|
244
|
+
begin
|
245
|
+
response = make_request(:post, path, options)
|
246
|
+
|
247
|
+
# Response doesn't raise any errors until #body is called
|
248
|
+
response.tap(&:body)
|
249
|
+
rescue InvalidStateError => e
|
250
|
+
if e.idempotent_creation_conflict?
|
251
|
+
case @api_service.on_idempotency_conflict
|
252
|
+
when :raise
|
253
|
+
raise IdempotencyConflict, e.error
|
254
|
+
when :fetch
|
255
|
+
return get(e.conflicting_resource_id)
|
256
|
+
else
|
257
|
+
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
raise e
|
262
|
+
end
|
263
|
+
|
264
|
+
return if response.body.nil?
|
265
|
+
|
266
|
+
Resources::BillingRequest.new(unenvelope_body(response.body), response)
|
267
|
+
end
|
268
|
+
|
269
|
+
# Notifies the customer linked to the billing request, asking them to authorise
|
270
|
+
# it.
|
271
|
+
# Currently, the customer can only be notified by email.
|
272
|
+
# Example URL: /billing_requests/:identity/actions/notify
|
273
|
+
#
|
274
|
+
# @param identity # Unique identifier, beginning with "PY".
|
275
|
+
# @param options [Hash] parameters as a hash, under a params key.
|
276
|
+
def notify(identity, options = {})
|
277
|
+
path = sub_url('/billing_requests/:identity/actions/notify', 'identity' => identity)
|
278
|
+
|
279
|
+
params = options.delete(:params) || {}
|
280
|
+
options[:params] = {}
|
281
|
+
options[:params]['data'] = params
|
282
|
+
|
283
|
+
options[:retry_failures] = false
|
284
|
+
|
285
|
+
begin
|
286
|
+
response = make_request(:post, path, options)
|
287
|
+
|
288
|
+
# Response doesn't raise any errors until #body is called
|
289
|
+
response.tap(&:body)
|
290
|
+
rescue InvalidStateError => e
|
291
|
+
if e.idempotent_creation_conflict?
|
292
|
+
case @api_service.on_idempotency_conflict
|
293
|
+
when :raise
|
294
|
+
raise IdempotencyConflict, e.error
|
295
|
+
when :fetch
|
296
|
+
return get(e.conflicting_resource_id)
|
297
|
+
else
|
298
|
+
raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
raise e
|
303
|
+
end
|
304
|
+
|
305
|
+
return if response.body.nil?
|
306
|
+
|
307
|
+
Resources::BillingRequest.new(unenvelope_body(response.body), response)
|
308
|
+
end
|
309
|
+
|
310
|
+
private
|
311
|
+
|
312
|
+
# Unenvelope the response of the body using the service's `envelope_key`
|
313
|
+
#
|
314
|
+
# @param body [Hash]
|
315
|
+
def unenvelope_body(body)
|
316
|
+
body[envelope_key] || body['data']
|
317
|
+
end
|
318
|
+
|
319
|
+
# return the key which API responses will envelope data under
|
320
|
+
def envelope_key
|
321
|
+
'billing_requests'
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|