gocardless_pro 2.24.0 → 2.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -4
  3. data/lib/gocardless_pro/api_service.rb +4 -0
  4. data/lib/gocardless_pro/client.rb +46 -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 +81 -0
  10. data/lib/gocardless_pro/resources/billing_request.rb +108 -0
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +72 -0
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  13. data/lib/gocardless_pro/resources/block.rb +66 -0
  14. data/lib/gocardless_pro/resources/creditor.rb +2 -3
  15. data/lib/gocardless_pro/resources/event.rb +20 -0
  16. data/lib/gocardless_pro/resources/institution.rb +47 -0
  17. data/lib/gocardless_pro/resources/payer_authorisation.rb +131 -0
  18. data/lib/gocardless_pro/resources/payout_item.rb +4 -0
  19. data/lib/gocardless_pro/resources/redirect_flow.rb +2 -0
  20. data/lib/gocardless_pro/resources/scenario_simulator.rb +42 -0
  21. data/lib/gocardless_pro/resources/webhook.rb +62 -0
  22. data/lib/gocardless_pro/services/bank_authorisations_service.rb +80 -0
  23. data/lib/gocardless_pro/services/billing_request_flows_service.rb +70 -0
  24. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  25. data/lib/gocardless_pro/services/billing_requests_service.rb +352 -0
  26. data/lib/gocardless_pro/services/blocks_service.rb +223 -0
  27. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +1 -5
  28. data/lib/gocardless_pro/services/creditors_service.rb +1 -3
  29. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +1 -1
  30. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +1 -5
  31. data/lib/gocardless_pro/services/customers_service.rb +1 -3
  32. data/lib/gocardless_pro/services/events_service.rb +1 -1
  33. data/lib/gocardless_pro/services/instalment_schedules_service.rb +1 -7
  34. data/lib/gocardless_pro/services/institutions_service.rb +56 -0
  35. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +1 -1
  36. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  37. data/lib/gocardless_pro/services/mandates_service.rb +1 -7
  38. data/lib/gocardless_pro/services/payer_authorisations_service.rb +202 -0
  39. data/lib/gocardless_pro/services/payments_service.rb +1 -7
  40. data/lib/gocardless_pro/services/payout_items_service.rb +1 -1
  41. data/lib/gocardless_pro/services/payouts_service.rb +1 -1
  42. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  43. data/lib/gocardless_pro/services/refunds_service.rb +1 -3
  44. data/lib/gocardless_pro/services/scenario_simulators_service.rb +170 -0
  45. data/lib/gocardless_pro/services/subscriptions_service.rb +10 -13
  46. data/lib/gocardless_pro/services/tax_rates_service.rb +1 -1
  47. data/lib/gocardless_pro/services/webhooks_service.rb +111 -0
  48. data/lib/gocardless_pro/version.rb +1 -1
  49. data/lib/gocardless_pro.rb +30 -0
  50. data/spec/api_service_spec.rb +12 -1
  51. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  52. data/spec/resources/bank_authorisation_spec.rb +259 -0
  53. data/spec/resources/billing_request_flow_spec.rb +219 -0
  54. data/spec/resources/billing_request_spec.rb +782 -0
  55. data/spec/resources/billing_request_template_spec.rb +502 -0
  56. data/spec/resources/block_spec.rb +560 -0
  57. data/spec/resources/institution_spec.rb +108 -0
  58. data/spec/resources/payer_authorisation_spec.rb +418 -0
  59. data/spec/resources/redirect_flow_spec.rb +9 -0
  60. data/spec/resources/scenario_simulator_spec.rb +63 -0
  61. data/spec/resources/webhook_spec.rb +323 -0
  62. data/spec/services/bank_authorisations_service_spec.rb +353 -0
  63. data/spec/services/billing_request_flows_service_spec.rb +253 -0
  64. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  65. data/spec/services/billing_requests_service_spec.rb +1082 -0
  66. data/spec/services/blocks_service_spec.rb +823 -0
  67. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -13
  68. data/spec/services/creditors_service_spec.rb +0 -13
  69. data/spec/services/customer_bank_accounts_service_spec.rb +0 -13
  70. data/spec/services/customers_service_spec.rb +0 -13
  71. data/spec/services/instalment_schedules_service_spec.rb +0 -26
  72. data/spec/services/institutions_service_spec.rb +232 -0
  73. data/spec/services/mandate_imports_service_spec.rb +0 -13
  74. data/spec/services/mandates_service_spec.rb +0 -13
  75. data/spec/services/payer_authorisations_service_spec.rb +559 -0
  76. data/spec/services/payments_service_spec.rb +0 -13
  77. data/spec/services/redirect_flows_service_spec.rb +9 -13
  78. data/spec/services/refunds_service_spec.rb +0 -13
  79. data/spec/services/scenario_simulators_service_spec.rb +74 -0
  80. data/spec/services/subscriptions_service_spec.rb +0 -13
  81. data/spec/services/webhooks_service_spec.rb +545 -0
  82. metadata +64 -7
@@ -0,0 +1,47 @@
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 institution resource returned from the API
14
+
15
+ # Institutions that are supported when creating [Bank
16
+ # Authorisations](#billing-requests-bank-authorisations).
17
+ class Institution
18
+ attr_reader :country_code
19
+ attr_reader :icon_url
20
+ attr_reader :id
21
+ attr_reader :logo_url
22
+ attr_reader :name
23
+
24
+ # Initialize a institution resource instance
25
+ # @param object [Hash] an object returned from the API
26
+ def initialize(object, response = nil)
27
+ @object = object
28
+
29
+ @country_code = object['country_code']
30
+ @icon_url = object['icon_url']
31
+ @id = object['id']
32
+ @logo_url = object['logo_url']
33
+ @name = object['name']
34
+ @response = response
35
+ end
36
+
37
+ def api_response
38
+ ApiResponse.new(@response)
39
+ end
40
+
41
+ # Provides the institution resource as a hash of all its readable attributes
42
+ def to_h
43
+ @object
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,131 @@
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 payer_authorisation resource returned from the API
14
+
15
+ # <p class="restricted-notice">
16
+ # Payer Authorisations is deprecated in favour of
17
+ # <a
18
+ # href="https://developer.gocardless.com/getting-started/billing-requests/overview/">
19
+ # Billing Requests</a>. Please consider using Billing Requests to build
20
+ # any
21
+ # future integrations.
22
+ # </p>
23
+ #
24
+ # Payer Authorisation resource acts as a wrapper for creating customer, bank
25
+ # account and mandate details in a single request.
26
+ # PayerAuthorisation API enables the integrators to build their own custom
27
+ # payment pages.
28
+ #
29
+ # The process to use the Payer Authorisation API is as follows:
30
+ #
31
+ # 1. Create a Payer Authorisation, either empty or with already available
32
+ # information
33
+ # 2. Update the authorisation with additional information or fix any
34
+ # mistakes
35
+ # 3. Submit the authorisation, after the payer has reviewed their
36
+ # information
37
+ # 4. [coming soon] Redirect the payer to the verification mechanisms from
38
+ # the response of the Submit request (this will be introduced as a
39
+ # non-breaking change)
40
+ # 5. Confirm the authorisation to indicate that the resources can be
41
+ # created
42
+ #
43
+ # After the Payer Authorisation is confirmed, resources will eventually be
44
+ # created as it's an asynchronous process.
45
+ #
46
+ # To retrieve the status and ID of the linked resources you can do one of
47
+ # the following:
48
+ # <ol>
49
+ # <li> Listen to <code> payer_authorisation_completed </code> <a
50
+ # href="#appendix-webhooks"> webhook</a> (recommended)</li>
51
+ # <li> Poll the GET <a
52
+ # href="#payer-authorisations-get-a-single-payer-authorisation">
53
+ # endpoint</a></li>
54
+ # <li> Poll the GET events API
55
+ # <code>https://api.gocardless.com/events?payer_authorisation={id}&action=completed</code>
56
+ # </li>
57
+ # </ol>
58
+ #
59
+ # <p class="notice">
60
+ # Note that the `create` and `update` endpoints behave differently than
61
+ # other existing `create` and `update` endpoints. The Payer Authorisation
62
+ # is still saved if incomplete data is provided.
63
+ # We return the list of incomplete data in the `incomplete_fields` along
64
+ # with the resources in the body of the response.
65
+ # The bank account details(account_number, bank_code & branch_code) must
66
+ # be sent together rather than splitting across different request for both
67
+ # `create` and `update` endpoints.
68
+ # <br><br>
69
+ # The API is designed to be flexible and allows you to collect information
70
+ # in multiple steps without storing any sensitive data in the browser or in
71
+ # your servers.
72
+ # </p>
73
+ class PayerAuthorisation
74
+ attr_reader :bank_account
75
+ attr_reader :created_at
76
+ attr_reader :customer
77
+ attr_reader :id
78
+ attr_reader :incomplete_fields
79
+ attr_reader :mandate
80
+ attr_reader :status
81
+
82
+ # Initialize a payer_authorisation resource instance
83
+ # @param object [Hash] an object returned from the API
84
+ def initialize(object, response = nil)
85
+ @object = object
86
+
87
+ @bank_account = object['bank_account']
88
+ @created_at = object['created_at']
89
+ @customer = object['customer']
90
+ @id = object['id']
91
+ @incomplete_fields = object['incomplete_fields']
92
+ @links = object['links']
93
+ @mandate = object['mandate']
94
+ @status = object['status']
95
+ @response = response
96
+ end
97
+
98
+ def api_response
99
+ ApiResponse.new(@response)
100
+ end
101
+
102
+ # Return the links that the resource has
103
+ def links
104
+ @payer_authorisation_links ||= Links.new(@links)
105
+ end
106
+
107
+ # Provides the payer_authorisation resource as a hash of all its readable attributes
108
+ def to_h
109
+ @object
110
+ end
111
+
112
+ class Links
113
+ def initialize(links)
114
+ @links = links || {}
115
+ end
116
+
117
+ def bank_account
118
+ @links['bank_account']
119
+ end
120
+
121
+ def customer
122
+ @links['customer']
123
+ end
124
+
125
+ def mandate
126
+ @links['mandate']
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -73,6 +73,10 @@ module GoCardlessPro
73
73
  def payment
74
74
  @links['payment']
75
75
  end
76
+
77
+ def refund
78
+ @links['refund']
79
+ end
76
80
  end
77
81
  end
78
82
  end
@@ -49,6 +49,7 @@ module GoCardlessPro
49
49
  attr_reader :created_at
50
50
  attr_reader :description
51
51
  attr_reader :id
52
+ attr_reader :mandate_reference
52
53
  attr_reader :metadata
53
54
  attr_reader :redirect_url
54
55
  attr_reader :scheme
@@ -65,6 +66,7 @@ module GoCardlessPro
65
66
  @description = object['description']
66
67
  @id = object['id']
67
68
  @links = object['links']
69
+ @mandate_reference = object['mandate_reference']
68
70
  @metadata = object['metadata']
69
71
  @redirect_url = object['redirect_url']
70
72
  @scheme = object['scheme']
@@ -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,80 @@
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
+ end
55
+ end
56
+
57
+ raise e
58
+ end
59
+
60
+ return if response.body.nil?
61
+
62
+ Resources::BankAuthorisation.new(unenvelope_body(response.body), response)
63
+ end
64
+
65
+ private
66
+
67
+ # Unenvelope the response of the body using the service's `envelope_key`
68
+ #
69
+ # @param body [Hash]
70
+ def unenvelope_body(body)
71
+ body[envelope_key] || body['data']
72
+ end
73
+
74
+ # return the key which API responses will envelope data under
75
+ def envelope_key
76
+ 'bank_authorisations'
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,70 @@
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
+ # Returns the flow having generated a fresh session token which can be used to
33
+ # power
34
+ # integrations that manipulate the flow.
35
+ # Example URL: /billing_request_flows/:identity/actions/initialise
36
+ #
37
+ # @param identity # Unique identifier, beginning with "BRQ".
38
+ # @param options [Hash] parameters as a hash, under a params key.
39
+ def initialise(identity, options = {})
40
+ path = sub_url('/billing_request_flows/:identity/actions/initialise', 'identity' => identity)
41
+
42
+ params = options.delete(:params) || {}
43
+ options[:params] = {}
44
+ options[:params]['data'] = params
45
+
46
+ options[:retry_failures] = false
47
+
48
+ response = make_request(:post, path, options)
49
+
50
+ return if response.body.nil?
51
+
52
+ Resources::BillingRequestFlow.new(unenvelope_body(response.body), response)
53
+ end
54
+
55
+ private
56
+
57
+ # Unenvelope the response of the body using the service's `envelope_key`
58
+ #
59
+ # @param body [Hash]
60
+ def unenvelope_body(body)
61
+ body[envelope_key] || body['data']
62
+ end
63
+
64
+ # return the key which API responses will envelope data under
65
+ def envelope_key
66
+ 'billing_request_flows'
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,131 @@
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 BillingRequestTemplate endpoints
12
+ class BillingRequestTemplatesService < BaseService
13
+ # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
14
+ # Billing Request Templates.
15
+ # Example URL: /billing_request_templates
16
+ # @param options [Hash] parameters as a hash, under a params key.
17
+ def list(options = {})
18
+ path = '/billing_request_templates'
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::BillingRequestTemplate
28
+ )
29
+ end
30
+
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
+ #
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
+ # Fetches a Billing Request Template
43
+ # Example URL: /billing_request_templates/:identity
44
+ #
45
+ # @param identity # Unique identifier, beginning with "BRT".
46
+ # @param options [Hash] parameters as a hash, under a params key.
47
+ def get(identity, options = {})
48
+ path = sub_url('/billing_request_templates/:identity', 'identity' => identity)
49
+
50
+ options[:retry_failures] = true
51
+
52
+ response = make_request(:get, path, options)
53
+
54
+ return if response.body.nil?
55
+
56
+ Resources::BillingRequestTemplate.new(unenvelope_body(response.body), response)
57
+ end
58
+
59
+ #
60
+ # Example URL: /billing_request_templates
61
+ # @param options [Hash] parameters as a hash, under a params key.
62
+ def create(options = {})
63
+ path = '/billing_request_templates'
64
+
65
+ params = options.delete(:params) || {}
66
+ options[:params] = {}
67
+ options[:params][envelope_key] = params
68
+
69
+ options[:retry_failures] = true
70
+
71
+ begin
72
+ response = make_request(:post, path, options)
73
+
74
+ # Response doesn't raise any errors until #body is called
75
+ response.tap(&:body)
76
+ rescue InvalidStateError => e
77
+ if e.idempotent_creation_conflict?
78
+ case @api_service.on_idempotency_conflict
79
+ when :raise
80
+ raise IdempotencyConflict, e.error
81
+ when :fetch
82
+ return get(e.conflicting_resource_id)
83
+ end
84
+ end
85
+
86
+ raise e
87
+ end
88
+
89
+ return if response.body.nil?
90
+
91
+ Resources::BillingRequestTemplate.new(unenvelope_body(response.body), response)
92
+ end
93
+
94
+ # Updates a Billing Request Template, which will affect all future Billing
95
+ # Requests created by this template.
96
+ # Example URL: /billing_request_templates/:identity
97
+ #
98
+ # @param identity # Unique identifier, beginning with "BRQ".
99
+ # @param options [Hash] parameters as a hash, under a params key.
100
+ def update(identity, options = {})
101
+ path = sub_url('/billing_request_templates/:identity', 'identity' => identity)
102
+
103
+ params = options.delete(:params) || {}
104
+ options[:params] = {}
105
+ options[:params][envelope_key] = params
106
+
107
+ options[:retry_failures] = true
108
+
109
+ response = make_request(:put, path, options)
110
+
111
+ return if response.body.nil?
112
+
113
+ Resources::BillingRequestTemplate.new(unenvelope_body(response.body), response)
114
+ end
115
+
116
+ private
117
+
118
+ # Unenvelope the response of the body using the service's `envelope_key`
119
+ #
120
+ # @param body [Hash]
121
+ def unenvelope_body(body)
122
+ body[envelope_key] || body['data']
123
+ end
124
+
125
+ # return the key which API responses will envelope data under
126
+ def envelope_key
127
+ 'billing_request_templates'
128
+ end
129
+ end
130
+ end
131
+ end