gocardless_pro 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +146 -0
  6. data/circle.yml +3 -0
  7. data/demo.rb +9 -0
  8. data/gocardless_pro.gemspec +26 -0
  9. data/lib/gocardless_pro.rb +73 -0
  10. data/lib/gocardless_pro/api_service.rb +58 -0
  11. data/lib/gocardless_pro/client.rb +135 -0
  12. data/lib/gocardless_pro/error.rb +42 -0
  13. data/lib/gocardless_pro/error/gocardless_error.rb +5 -0
  14. data/lib/gocardless_pro/error/invalid_api_usage_error.rb +5 -0
  15. data/lib/gocardless_pro/error/invalid_state_error.rb +5 -0
  16. data/lib/gocardless_pro/error/validation_error.rb +5 -0
  17. data/lib/gocardless_pro/list_response.rb +29 -0
  18. data/lib/gocardless_pro/paginator.rb +43 -0
  19. data/lib/gocardless_pro/request.rb +69 -0
  20. data/lib/gocardless_pro/resources/creditor.rb +84 -0
  21. data/lib/gocardless_pro/resources/creditor_bank_account.rb +78 -0
  22. data/lib/gocardless_pro/resources/customer.rb +75 -0
  23. data/lib/gocardless_pro/resources/customer_bank_account.rb +80 -0
  24. data/lib/gocardless_pro/resources/event.rb +75 -0
  25. data/lib/gocardless_pro/resources/helper.rb +29 -0
  26. data/lib/gocardless_pro/resources/mandate.rb +70 -0
  27. data/lib/gocardless_pro/resources/payment.rb +87 -0
  28. data/lib/gocardless_pro/resources/payout.rb +66 -0
  29. data/lib/gocardless_pro/resources/redirect_flow.rb +106 -0
  30. data/lib/gocardless_pro/resources/refund.rb +71 -0
  31. data/lib/gocardless_pro/resources/subscription.rb +155 -0
  32. data/lib/gocardless_pro/response.rb +77 -0
  33. data/lib/gocardless_pro/services/base_service.rb +28 -0
  34. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +119 -0
  35. data/lib/gocardless_pro/services/creditors_service.rb +113 -0
  36. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +154 -0
  37. data/lib/gocardless_pro/services/customers_service.rb +113 -0
  38. data/lib/gocardless_pro/services/events_service.rb +80 -0
  39. data/lib/gocardless_pro/services/helpers_service.rb +99 -0
  40. data/lib/gocardless_pro/services/mandates_service.rb +173 -0
  41. data/lib/gocardless_pro/services/payments_service.rb +168 -0
  42. data/lib/gocardless_pro/services/payouts_service.rb +82 -0
  43. data/lib/gocardless_pro/services/redirect_flows_service.rb +98 -0
  44. data/lib/gocardless_pro/services/refunds_service.rb +132 -0
  45. data/lib/gocardless_pro/services/subscriptions_service.rb +134 -0
  46. data/lib/gocardless_pro/version.rb +8 -0
  47. data/spec/api_service_spec.rb +73 -0
  48. data/spec/client_spec.rb +19 -0
  49. data/spec/error_spec.rb +44 -0
  50. data/spec/resources/creditor_bank_account_spec.rb +109 -0
  51. data/spec/resources/creditor_spec.rb +125 -0
  52. data/spec/resources/customer_bank_account_spec.rb +109 -0
  53. data/spec/resources/customer_spec.rb +135 -0
  54. data/spec/resources/event_spec.rb +113 -0
  55. data/spec/resources/helper_spec.rb +23 -0
  56. data/spec/resources/mandate_spec.rb +97 -0
  57. data/spec/resources/payment_spec.rb +129 -0
  58. data/spec/resources/payout_spec.rb +89 -0
  59. data/spec/resources/redirect_flow_spec.rb +97 -0
  60. data/spec/resources/refund_spec.rb +77 -0
  61. data/spec/resources/subscription_spec.rb +165 -0
  62. data/spec/response_spec.rb +89 -0
  63. data/spec/services/creditor_bank_accounts_service_spec.rb +413 -0
  64. data/spec/services/creditors_service_spec.rb +388 -0
  65. data/spec/services/customer_bank_accounts_service_spec.rb +452 -0
  66. data/spec/services/customers_service_spec.rb +429 -0
  67. data/spec/services/events_service_spec.rb +217 -0
  68. data/spec/services/helpers_service_spec.rb +122 -0
  69. data/spec/services/mandates_service_spec.rb +495 -0
  70. data/spec/services/payments_service_spec.rb +546 -0
  71. data/spec/services/payouts_service_spec.rb +217 -0
  72. data/spec/services/redirect_flows_service_spec.rb +254 -0
  73. data/spec/services/refunds_service_spec.rb +323 -0
  74. data/spec/services/subscriptions_service_spec.rb +557 -0
  75. data/spec/spec_helper.rb +91 -0
  76. metadata +224 -0
@@ -0,0 +1,113 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the Creditor endpoints
12
+ class CreditorsService < BaseService
13
+ # Creates a new creditor.
14
+ # Example URL: /creditors
15
+ # @param options [Hash] parameters as a hash, under a params key.
16
+ def create(options = {})
17
+ path = '/creditors'
18
+
19
+ params = options.delete(:params) || {}
20
+ options[:params] = {}
21
+ options[:params][envelope_key] = params
22
+ response = make_request(:post, path, options)
23
+
24
+ return if response.body.nil?
25
+ Resources::Creditor.new(unenvelope_body(response.body))
26
+ end
27
+
28
+ # Returns a
29
+ # [cursor-paginated](https://developer.gocardless.com/pro/2015-04-29/#overview-cursor-pagination)
30
+ # list of your creditors.
31
+ # Example URL: /creditors
32
+ # @param options [Hash] parameters as a hash, under a params key.
33
+ def list(options = {})
34
+ path = '/creditors'
35
+
36
+ response = make_request(:get, path, options)
37
+ ListResponse.new(
38
+ raw_response: response,
39
+ unenveloped_body: unenvelope_body(response.body),
40
+ resource_class: Resources::Creditor
41
+ )
42
+ end
43
+
44
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
45
+ #
46
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
47
+ # Otherwise they will be the body of the request.
48
+ def all(options = {})
49
+ Paginator.new(
50
+ service: self,
51
+ path: '/creditors',
52
+ options: options,
53
+ resource_class: Resources::Creditor
54
+ ).enumerator
55
+ end
56
+
57
+ # Retrieves the details of an existing creditor.
58
+ # Example URL: /creditors/:identity
59
+ #
60
+ # @param identity # Unique identifier, beginning with "CR".
61
+ # @param options [Hash] parameters as a hash, under a params key.
62
+ def get(identity, options = {})
63
+ path = sub_url('/creditors/:identity', 'identity' => identity)
64
+
65
+ response = make_request(:get, path, options)
66
+
67
+ return if response.body.nil?
68
+ Resources::Creditor.new(unenvelope_body(response.body))
69
+ end
70
+
71
+ # Updates a creditor object. Supports all of the fields supported when creating
72
+ # a creditor.
73
+ # Example URL: /creditors/:identity
74
+ #
75
+ # @param identity # Unique identifier, beginning with "CR".
76
+ # @param options [Hash] parameters as a hash, under a params key.
77
+ def update(identity, options = {})
78
+ path = sub_url('/creditors/:identity', 'identity' => identity)
79
+
80
+ params = options.delete(:params) || {}
81
+ options[:params] = {}
82
+ options[:params][envelope_key] = params
83
+ response = make_request(:put, path, options)
84
+
85
+ return if response.body.nil?
86
+ Resources::Creditor.new(unenvelope_body(response.body))
87
+ end
88
+
89
+ # Unenvelope the response of the body using the service's `envelope_key`
90
+ #
91
+ # @param body [Hash]
92
+ def unenvelope_body(body)
93
+ body[envelope_key] || body['data']
94
+ end
95
+
96
+ private
97
+
98
+ # return the key which API responses will envelope data under
99
+ def envelope_key
100
+ 'creditors'
101
+ end
102
+
103
+ # take a URL with placeholder params and substitute them out for the acutal value
104
+ # @param url [String] the URL with placeholders in
105
+ # @param param_map [Hash] a hash of placeholders and their actual values
106
+ def sub_url(url, param_map)
107
+ param_map.reduce(url) do |new_url, (param, value)|
108
+ new_url.gsub(":#{param}", value)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,154 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the CustomerBankAccount endpoints
12
+ class CustomerBankAccountsService < BaseService
13
+ # Creates a new customer bank account object.
14
+ #
15
+ # There are three different
16
+ # ways to supply bank account details:
17
+ #
18
+ # - [Local
19
+ # details](https://developer.gocardless.com/pro/2015-04-29/#ui-local-bank-details)
20
+ #
21
+ #
22
+ # - IBAN
23
+ #
24
+ # - [Customer Bank Account
25
+ # Tokens](https://developer.gocardless.com/pro/2015-04-29/#js-flow-create-a-customer-bank-account-token)
26
+ #
27
+ #
28
+ # For more information on the different fields required in each country, see
29
+ # [local bank
30
+ # details](https://developer.gocardless.com/pro/2015-04-29/#ui-local-bank-details).
31
+ # Example URL: /customer_bank_accounts
32
+ # @param options [Hash] parameters as a hash, under a params key.
33
+ def create(options = {})
34
+ path = '/customer_bank_accounts'
35
+
36
+ params = options.delete(:params) || {}
37
+ options[:params] = {}
38
+ options[:params][envelope_key] = params
39
+ response = make_request(:post, path, options)
40
+
41
+ return if response.body.nil?
42
+ Resources::CustomerBankAccount.new(unenvelope_body(response.body))
43
+ end
44
+
45
+ # Returns a
46
+ # [cursor-paginated](https://developer.gocardless.com/pro/2015-04-29/#overview-cursor-pagination)
47
+ # list of your bank accounts.
48
+ # Example URL: /customer_bank_accounts
49
+ # @param options [Hash] parameters as a hash, under a params key.
50
+ def list(options = {})
51
+ path = '/customer_bank_accounts'
52
+
53
+ response = make_request(:get, path, options)
54
+ ListResponse.new(
55
+ raw_response: response,
56
+ unenveloped_body: unenvelope_body(response.body),
57
+ resource_class: Resources::CustomerBankAccount
58
+ )
59
+ end
60
+
61
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
62
+ #
63
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
64
+ # Otherwise they will be the body of the request.
65
+ def all(options = {})
66
+ Paginator.new(
67
+ service: self,
68
+ path: '/customer_bank_accounts',
69
+ options: options,
70
+ resource_class: Resources::CustomerBankAccount
71
+ ).enumerator
72
+ end
73
+
74
+ # Retrieves the details of an existing bank account.
75
+ # Example URL: /customer_bank_accounts/:identity
76
+ #
77
+ # @param identity # Unique identifier, beginning with "BA"
78
+ # @param options [Hash] parameters as a hash, under a params key.
79
+ def get(identity, options = {})
80
+ path = sub_url('/customer_bank_accounts/:identity', 'identity' => identity)
81
+
82
+ response = make_request(:get, path, options)
83
+
84
+ return if response.body.nil?
85
+ Resources::CustomerBankAccount.new(unenvelope_body(response.body))
86
+ end
87
+
88
+ # Updates a customer bank account object. Only the metadata parameter is
89
+ # allowed.
90
+ # Example URL: /customer_bank_accounts/:identity
91
+ #
92
+ # @param identity # Unique identifier, beginning with "BA"
93
+ # @param options [Hash] parameters as a hash, under a params key.
94
+ def update(identity, options = {})
95
+ path = sub_url('/customer_bank_accounts/:identity', 'identity' => identity)
96
+
97
+ params = options.delete(:params) || {}
98
+ options[:params] = {}
99
+ options[:params][envelope_key] = params
100
+ response = make_request(:put, path, options)
101
+
102
+ return if response.body.nil?
103
+ Resources::CustomerBankAccount.new(unenvelope_body(response.body))
104
+ end
105
+
106
+ # Immediately cancels all associated mandates and cancellable payments.
107
+ #
108
+ #
109
+ # This will return a `disable_failed` error if the bank account has already been
110
+ # disabled.
111
+ #
112
+ # A disabled bank account can be re-enabled by creating a new
113
+ # bank account resource with the same details.
114
+ # Example URL: /customer_bank_accounts/:identity/actions/disable
115
+ #
116
+ # @param identity # Unique identifier, beginning with "BA"
117
+ # @param options [Hash] parameters as a hash, under a params key.
118
+ def disable(identity, options = {})
119
+ path = sub_url('/customer_bank_accounts/:identity/actions/disable', 'identity' => identity)
120
+
121
+ params = options.delete(:params) || {}
122
+ options[:params] = {}
123
+ options[:params]['data'] = params
124
+ response = make_request(:post, path, options)
125
+
126
+ return if response.body.nil?
127
+ Resources::CustomerBankAccount.new(unenvelope_body(response.body))
128
+ end
129
+
130
+ # Unenvelope the response of the body using the service's `envelope_key`
131
+ #
132
+ # @param body [Hash]
133
+ def unenvelope_body(body)
134
+ body[envelope_key] || body['data']
135
+ end
136
+
137
+ private
138
+
139
+ # return the key which API responses will envelope data under
140
+ def envelope_key
141
+ 'customer_bank_accounts'
142
+ end
143
+
144
+ # take a URL with placeholder params and substitute them out for the acutal value
145
+ # @param url [String] the URL with placeholders in
146
+ # @param param_map [Hash] a hash of placeholders and their actual values
147
+ def sub_url(url, param_map)
148
+ param_map.reduce(url) do |new_url, (param, value)|
149
+ new_url.gsub(":#{param}", value)
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,113 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the Customer endpoints
12
+ class CustomersService < BaseService
13
+ # Creates a new customer object.
14
+ # Example URL: /customers
15
+ # @param options [Hash] parameters as a hash, under a params key.
16
+ def create(options = {})
17
+ path = '/customers'
18
+
19
+ params = options.delete(:params) || {}
20
+ options[:params] = {}
21
+ options[:params][envelope_key] = params
22
+ response = make_request(:post, path, options)
23
+
24
+ return if response.body.nil?
25
+ Resources::Customer.new(unenvelope_body(response.body))
26
+ end
27
+
28
+ # Returns a
29
+ # [cursor-paginated](https://developer.gocardless.com/pro/2015-04-29/#overview-cursor-pagination)
30
+ # list of your customers.
31
+ # Example URL: /customers
32
+ # @param options [Hash] parameters as a hash, under a params key.
33
+ def list(options = {})
34
+ path = '/customers'
35
+
36
+ response = make_request(:get, path, options)
37
+ ListResponse.new(
38
+ raw_response: response,
39
+ unenveloped_body: unenvelope_body(response.body),
40
+ resource_class: Resources::Customer
41
+ )
42
+ end
43
+
44
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
45
+ #
46
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
47
+ # Otherwise they will be the body of the request.
48
+ def all(options = {})
49
+ Paginator.new(
50
+ service: self,
51
+ path: '/customers',
52
+ options: options,
53
+ resource_class: Resources::Customer
54
+ ).enumerator
55
+ end
56
+
57
+ # Retrieves the details of an existing customer.
58
+ # Example URL: /customers/:identity
59
+ #
60
+ # @param identity # Unique identifier, beginning with "CU".
61
+ # @param options [Hash] parameters as a hash, under a params key.
62
+ def get(identity, options = {})
63
+ path = sub_url('/customers/:identity', 'identity' => identity)
64
+
65
+ response = make_request(:get, path, options)
66
+
67
+ return if response.body.nil?
68
+ Resources::Customer.new(unenvelope_body(response.body))
69
+ end
70
+
71
+ # Updates a customer object. Supports all of the fields supported when creating
72
+ # a customer.
73
+ # Example URL: /customers/:identity
74
+ #
75
+ # @param identity # Unique identifier, beginning with "CU".
76
+ # @param options [Hash] parameters as a hash, under a params key.
77
+ def update(identity, options = {})
78
+ path = sub_url('/customers/:identity', 'identity' => identity)
79
+
80
+ params = options.delete(:params) || {}
81
+ options[:params] = {}
82
+ options[:params][envelope_key] = params
83
+ response = make_request(:put, path, options)
84
+
85
+ return if response.body.nil?
86
+ Resources::Customer.new(unenvelope_body(response.body))
87
+ end
88
+
89
+ # Unenvelope the response of the body using the service's `envelope_key`
90
+ #
91
+ # @param body [Hash]
92
+ def unenvelope_body(body)
93
+ body[envelope_key] || body['data']
94
+ end
95
+
96
+ private
97
+
98
+ # return the key which API responses will envelope data under
99
+ def envelope_key
100
+ 'customers'
101
+ end
102
+
103
+ # take a URL with placeholder params and substitute them out for the acutal value
104
+ # @param url [String] the URL with placeholders in
105
+ # @param param_map [Hash] a hash of placeholders and their actual values
106
+ def sub_url(url, param_map)
107
+ param_map.reduce(url) do |new_url, (param, value)|
108
+ new_url.gsub(":#{param}", value)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,80 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the Event endpoints
12
+ class EventsService < BaseService
13
+ # Returns a
14
+ # [cursor-paginated](https://developer.gocardless.com/pro/2015-04-29/#overview-cursor-pagination)
15
+ # list of your events.
16
+ # Example URL: /events
17
+ # @param options [Hash] parameters as a hash, under a params key.
18
+ def list(options = {})
19
+ path = '/events'
20
+
21
+ response = make_request(:get, path, options)
22
+ ListResponse.new(
23
+ raw_response: response,
24
+ unenveloped_body: unenvelope_body(response.body),
25
+ resource_class: Resources::Event
26
+ )
27
+ end
28
+
29
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
30
+ #
31
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
32
+ # Otherwise they will be the body of the request.
33
+ def all(options = {})
34
+ Paginator.new(
35
+ service: self,
36
+ path: '/events',
37
+ options: options,
38
+ resource_class: Resources::Event
39
+ ).enumerator
40
+ end
41
+
42
+ # Retrieves the details of a single event.
43
+ # Example URL: /events/:identity
44
+ #
45
+ # @param identity # Unique identifier, beginning with "EV"
46
+ # @param options [Hash] parameters as a hash, under a params key.
47
+ def get(identity, options = {})
48
+ path = sub_url('/events/:identity', 'identity' => identity)
49
+
50
+ response = make_request(:get, path, options)
51
+
52
+ return if response.body.nil?
53
+ Resources::Event.new(unenvelope_body(response.body))
54
+ end
55
+
56
+ # Unenvelope the response of the body using the service's `envelope_key`
57
+ #
58
+ # @param body [Hash]
59
+ def unenvelope_body(body)
60
+ body[envelope_key] || body['data']
61
+ end
62
+
63
+ private
64
+
65
+ # return the key which API responses will envelope data under
66
+ def envelope_key
67
+ 'events'
68
+ end
69
+
70
+ # take a URL with placeholder params and substitute them out for the acutal value
71
+ # @param url [String] the URL with placeholders in
72
+ # @param param_map [Hash] a hash of placeholders and their actual values
73
+ def sub_url(url, param_map)
74
+ param_map.reduce(url) do |new_url, (param, value)|
75
+ new_url.gsub(":#{param}", value)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end