gocardless_pro 2.22.1 → 2.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -3
  3. data/lib/gocardless_pro.rb +24 -0
  4. data/lib/gocardless_pro/client.rb +41 -1
  5. data/lib/gocardless_pro/resources/bank_authorisation.rb +87 -0
  6. data/lib/gocardless_pro/resources/billing_request.rb +86 -0
  7. data/lib/gocardless_pro/resources/billing_request_flow.rb +62 -0
  8. data/lib/gocardless_pro/resources/creditor.rb +2 -3
  9. data/lib/gocardless_pro/resources/event.rb +12 -0
  10. data/lib/gocardless_pro/resources/institution.rb +45 -0
  11. data/lib/gocardless_pro/resources/payer_authorisation.rb +122 -0
  12. data/lib/gocardless_pro/resources/payout.rb +2 -0
  13. data/lib/gocardless_pro/resources/payout_item.rb +6 -0
  14. data/lib/gocardless_pro/resources/scenario_simulator.rb +42 -0
  15. data/lib/gocardless_pro/resources/tax_rate.rb +51 -0
  16. data/lib/gocardless_pro/resources/webhook.rb +62 -0
  17. data/lib/gocardless_pro/services/bank_authorisations_service.rb +82 -0
  18. data/lib/gocardless_pro/services/billing_request_flows_service.rb +47 -0
  19. data/lib/gocardless_pro/services/billing_requests_service.rb +325 -0
  20. data/lib/gocardless_pro/services/institutions_service.rb +56 -0
  21. data/lib/gocardless_pro/services/payer_authorisations_service.rb +208 -0
  22. data/lib/gocardless_pro/services/scenario_simulators_service.rb +148 -0
  23. data/lib/gocardless_pro/services/subscriptions_service.rb +9 -4
  24. data/lib/gocardless_pro/services/tax_rates_service.rb +74 -0
  25. data/lib/gocardless_pro/services/webhooks_service.rb +113 -0
  26. data/lib/gocardless_pro/version.rb +1 -1
  27. data/spec/resources/bank_authorisation_spec.rb +259 -0
  28. data/spec/resources/billing_request_flow_spec.rb +129 -0
  29. data/spec/resources/billing_request_spec.rb +736 -0
  30. data/spec/resources/institution_spec.rb +103 -0
  31. data/spec/resources/payer_authorisation_spec.rb +418 -0
  32. data/spec/resources/payout_item_spec.rb +5 -0
  33. data/spec/resources/payout_spec.rb +8 -0
  34. data/spec/resources/scenario_simulator_spec.rb +63 -0
  35. data/spec/resources/tax_rate_spec.rb +198 -0
  36. data/spec/resources/webhook_spec.rb +323 -0
  37. data/spec/services/bank_authorisations_service_spec.rb +366 -0
  38. data/spec/services/billing_request_flows_service_spec.rb +152 -0
  39. data/spec/services/billing_requests_service_spec.rb +1042 -0
  40. data/spec/services/institutions_service_spec.rb +223 -0
  41. data/spec/services/payer_authorisations_service_spec.rb +572 -0
  42. data/spec/services/payout_items_service_spec.rb +9 -0
  43. data/spec/services/payouts_service_spec.rb +12 -0
  44. data/spec/services/scenario_simulators_service_spec.rb +74 -0
  45. data/spec/services/tax_rates_service_spec.rb +381 -0
  46. data/spec/services/webhooks_service_spec.rb +545 -0
  47. metadata +51 -3
@@ -0,0 +1,45 @@
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 :icon_url
19
+ attr_reader :id
20
+ attr_reader :logo_url
21
+ attr_reader :name
22
+
23
+ # Initialize a institution resource instance
24
+ # @param object [Hash] an object returned from the API
25
+ def initialize(object, response = nil)
26
+ @object = object
27
+
28
+ @icon_url = object['icon_url']
29
+ @id = object['id']
30
+ @logo_url = object['logo_url']
31
+ @name = object['name']
32
+ @response = response
33
+ end
34
+
35
+ def api_response
36
+ ApiResponse.new(@response)
37
+ end
38
+
39
+ # Provides the institution resource as a hash of all its readable attributes
40
+ def to_h
41
+ @object
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,122 @@
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
+ # Payer Authorisation resource acts as a wrapper for creating customer, bank
16
+ # account and mandate details in a single request.
17
+ # PayerAuthorisation API enables the integrators to build their own custom
18
+ # payment pages.
19
+ #
20
+ # The process to use the Payer Authorisation API is as follows:
21
+ #
22
+ # 1. Create a Payer Authorisation, either empty or with already available
23
+ # information
24
+ # 2. Update the authorisation with additional information or fix any
25
+ # mistakes
26
+ # 3. Submit the authorisation, after the payer has reviewed their
27
+ # information
28
+ # 4. [coming soon] Redirect the payer to the verification mechanisms from
29
+ # the response of the Submit request (this will be introduced as a
30
+ # non-breaking change)
31
+ # 5. Confirm the authorisation to indicate that the resources can be
32
+ # created
33
+ #
34
+ # After the Payer Authorisation is confirmed, resources will eventually be
35
+ # created as it's an asynchronous process.
36
+ #
37
+ # To retrieve the status and ID of the linked resources you can do one of
38
+ # the following:
39
+ # <ol>
40
+ # <li> Listen to <code> payer_authorisation_completed </code> <a
41
+ # href="#appendix-webhooks"> webhook</a> (recommended)</li>
42
+ # <li> Poll the GET <a
43
+ # href="#payer-authorisations-get-a-single-payer-authorisation">
44
+ # endpoint</a></li>
45
+ # <li> Poll the GET events API
46
+ # <code>https://api.gocardless.com/events?payer_authorisation={id}&action=completed</code>
47
+ # </li>
48
+ # </ol>
49
+ #
50
+ # <p class="notice">
51
+ # Note that the `create` and `update` endpoints behave differently than
52
+ # other existing `create` and `update` endpoints. The Payer Authorisation
53
+ # is still saved if incomplete data is provided.
54
+ # We return the list of incomplete data in the `incomplete_fields` along
55
+ # with the resources in the body of the response.
56
+ # The bank account details(account_number, bank_code & branch_code) must
57
+ # be sent together rather than splitting across different request for both
58
+ # `create` and `update` endpoints.
59
+ # <br><br>
60
+ # The API is designed to be flexible and allows you to collect information
61
+ # in multiple steps without storing any sensitive data in the browser or in
62
+ # your servers.
63
+ # </p>
64
+ class PayerAuthorisation
65
+ attr_reader :bank_account
66
+ attr_reader :created_at
67
+ attr_reader :customer
68
+ attr_reader :id
69
+ attr_reader :incomplete_fields
70
+ attr_reader :mandate
71
+ attr_reader :status
72
+
73
+ # Initialize a payer_authorisation resource instance
74
+ # @param object [Hash] an object returned from the API
75
+ def initialize(object, response = nil)
76
+ @object = object
77
+
78
+ @bank_account = object['bank_account']
79
+ @created_at = object['created_at']
80
+ @customer = object['customer']
81
+ @id = object['id']
82
+ @incomplete_fields = object['incomplete_fields']
83
+ @links = object['links']
84
+ @mandate = object['mandate']
85
+ @status = object['status']
86
+ @response = response
87
+ end
88
+
89
+ def api_response
90
+ ApiResponse.new(@response)
91
+ end
92
+
93
+ # Return the links that the resource has
94
+ def links
95
+ @payer_authorisation_links ||= Links.new(@links)
96
+ end
97
+
98
+ # Provides the payer_authorisation resource as a hash of all its readable attributes
99
+ def to_h
100
+ @object
101
+ end
102
+
103
+ class Links
104
+ def initialize(links)
105
+ @links = links || {}
106
+ end
107
+
108
+ def bank_account
109
+ @links['bank_account']
110
+ end
111
+
112
+ def customer
113
+ @links['customer']
114
+ end
115
+
116
+ def mandate
117
+ @links['mandate']
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -30,6 +30,7 @@ module GoCardlessPro
30
30
  attr_reader :payout_type
31
31
  attr_reader :reference
32
32
  attr_reader :status
33
+ attr_reader :tax_currency
33
34
 
34
35
  # Initialize a payout resource instance
35
36
  # @param object [Hash] an object returned from the API
@@ -48,6 +49,7 @@ module GoCardlessPro
48
49
  @payout_type = object['payout_type']
49
50
  @reference = object['reference']
50
51
  @status = object['status']
52
+ @tax_currency = object['tax_currency']
51
53
  @response = response
52
54
  end
53
55
 
@@ -32,6 +32,7 @@ module GoCardlessPro
32
32
  #
33
33
  class PayoutItem
34
34
  attr_reader :amount
35
+ attr_reader :taxes
35
36
  attr_reader :type
36
37
 
37
38
  # Initialize a payout_item resource instance
@@ -41,6 +42,7 @@ module GoCardlessPro
41
42
 
42
43
  @amount = object['amount']
43
44
  @links = object['links']
45
+ @taxes = object['taxes']
44
46
  @type = object['type']
45
47
  @response = response
46
48
  end
@@ -71,6 +73,10 @@ module GoCardlessPro
71
73
  def payment
72
74
  @links['payment']
73
75
  end
76
+
77
+ def refund
78
+ @links['refund']
79
+ end
74
80
  end
75
81
  end
76
82
  end
@@ -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,51 @@
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 tax_rate resource returned from the API
14
+
15
+ # Tax rates from tax authority.
16
+ #
17
+ # We also maintain a [static list of the tax rates for each
18
+ # jurisdiction](#appendix-tax-rates).
19
+ class TaxRate
20
+ attr_reader :end_date
21
+ attr_reader :id
22
+ attr_reader :jurisdiction
23
+ attr_reader :percentage
24
+ attr_reader :start_date
25
+ attr_reader :type
26
+
27
+ # Initialize a tax_rate resource instance
28
+ # @param object [Hash] an object returned from the API
29
+ def initialize(object, response = nil)
30
+ @object = object
31
+
32
+ @end_date = object['end_date']
33
+ @id = object['id']
34
+ @jurisdiction = object['jurisdiction']
35
+ @percentage = object['percentage']
36
+ @start_date = object['start_date']
37
+ @type = object['type']
38
+ @response = response
39
+ end
40
+
41
+ def api_response
42
+ ApiResponse.new(@response)
43
+ end
44
+
45
+ # Provides the tax_rate resource as a hash of all its readable attributes
46
+ def to_h
47
+ @object
48
+ end
49
+ end
50
+ end
51
+ 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