gocardless-pro 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +132 -0
- data/circle.yml +18 -0
- data/demo.rb +10 -0
- data/gocardless-pro.gemspec +27 -0
- data/lib/gocardless-pro.rb +243 -0
- data/lib/gocardless-pro/api_service.rb +57 -0
- data/lib/gocardless-pro/error.rb +42 -0
- data/lib/gocardless-pro/error/gocardless_error.rb +5 -0
- data/lib/gocardless-pro/error/invalid_api_usage_error.rb +5 -0
- data/lib/gocardless-pro/error/invalid_state_error.rb +5 -0
- data/lib/gocardless-pro/error/validation_error.rb +5 -0
- data/lib/gocardless-pro/list_response.rb +34 -0
- data/lib/gocardless-pro/paginator.rb +37 -0
- data/lib/gocardless-pro/request.rb +69 -0
- data/lib/gocardless-pro/resources/api_key.rb +62 -0
- data/lib/gocardless-pro/resources/creditor.rb +83 -0
- data/lib/gocardless-pro/resources/creditor_bank_account.rb +78 -0
- data/lib/gocardless-pro/resources/customer.rb +72 -0
- data/lib/gocardless-pro/resources/customer_bank_account.rb +80 -0
- data/lib/gocardless-pro/resources/event.rb +75 -0
- data/lib/gocardless-pro/resources/helper.rb +29 -0
- data/lib/gocardless-pro/resources/mandate.rb +70 -0
- data/lib/gocardless-pro/resources/payment.rb +86 -0
- data/lib/gocardless-pro/resources/payout.rb +66 -0
- data/lib/gocardless-pro/resources/publishable_api_key.rb +51 -0
- data/lib/gocardless-pro/resources/redirect_flow.rb +104 -0
- data/lib/gocardless-pro/resources/refund.rb +70 -0
- data/lib/gocardless-pro/resources/role.rb +101 -0
- data/lib/gocardless-pro/resources/subscription.rb +152 -0
- data/lib/gocardless-pro/resources/user.rb +60 -0
- data/lib/gocardless-pro/response.rb +77 -0
- data/lib/gocardless-pro/services/api_key_service.rb +130 -0
- data/lib/gocardless-pro/services/base_service.rb +29 -0
- data/lib/gocardless-pro/services/creditor_bank_account_service.rb +122 -0
- data/lib/gocardless-pro/services/creditor_service.rb +112 -0
- data/lib/gocardless-pro/services/customer_bank_account_service.rb +153 -0
- data/lib/gocardless-pro/services/customer_service.rb +112 -0
- data/lib/gocardless-pro/services/event_service.rb +80 -0
- data/lib/gocardless-pro/services/helper_service.rb +97 -0
- data/lib/gocardless-pro/services/mandate_service.rb +170 -0
- data/lib/gocardless-pro/services/payment_service.rb +164 -0
- data/lib/gocardless-pro/services/payout_service.rb +80 -0
- data/lib/gocardless-pro/services/publishable_api_key_service.rb +130 -0
- data/lib/gocardless-pro/services/redirect_flow_service.rb +96 -0
- data/lib/gocardless-pro/services/refund_service.rb +126 -0
- data/lib/gocardless-pro/services/role_service.rb +127 -0
- data/lib/gocardless-pro/services/subscription_service.rb +133 -0
- data/lib/gocardless-pro/services/user_service.rb +148 -0
- data/lib/gocardless-pro/version.rb +8 -0
- data/spec/api_service_spec.rb +69 -0
- data/spec/client_spec.rb +29 -0
- data/spec/error_spec.rb +44 -0
- data/spec/resources/api_key_spec.rb +85 -0
- data/spec/resources/creditor_bank_account_spec.rb +109 -0
- data/spec/resources/creditor_spec.rb +125 -0
- data/spec/resources/customer_bank_account_spec.rb +109 -0
- data/spec/resources/customer_spec.rb +127 -0
- data/spec/resources/event_spec.rb +113 -0
- data/spec/resources/helper_spec.rb +23 -0
- data/spec/resources/mandate_spec.rb +97 -0
- data/spec/resources/payment_spec.rb +129 -0
- data/spec/resources/payout_spec.rb +89 -0
- data/spec/resources/publishable_api_key_spec.rb +63 -0
- data/spec/resources/redirect_flow_spec.rb +97 -0
- data/spec/resources/refund_spec.rb +77 -0
- data/spec/resources/role_spec.rb +63 -0
- data/spec/resources/subscription_spec.rb +157 -0
- data/spec/resources/user_spec.rb +85 -0
- data/spec/response_spec.rb +79 -0
- data/spec/services/api_key_service_spec.rb +362 -0
- data/spec/services/creditor_bank_account_service_spec.rb +365 -0
- data/spec/services/creditor_service_spec.rb +339 -0
- data/spec/services/customer_bank_account_service_spec.rb +404 -0
- data/spec/services/customer_service_spec.rb +365 -0
- data/spec/services/event_service_spec.rb +172 -0
- data/spec/services/helper_service_spec.rb +123 -0
- data/spec/services/mandate_service_spec.rb +449 -0
- data/spec/services/payment_service_spec.rb +497 -0
- data/spec/services/payout_service_spec.rb +172 -0
- data/spec/services/publishable_api_key_service_spec.rb +336 -0
- data/spec/services/redirect_flow_service_spec.rb +208 -0
- data/spec/services/refund_service_spec.rb +279 -0
- data/spec/services/role_service_spec.rb +336 -0
- data/spec/services/subscription_service_spec.rb +488 -0
- data/spec/services/user_service_spec.rb +433 -0
- data/spec/spec_helper.rb +91 -0
- metadata +255 -0
@@ -0,0 +1,153 @@
|
|
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 GoCardless
|
10
|
+
module Services
|
11
|
+
# Service for making requests to the CustomerBankAccount endpoints
|
12
|
+
class CustomerBankAccountService < BaseService
|
13
|
+
# Creates a new bank account object associated to a customer id.
|
14
|
+
#
|
15
|
+
# There are
|
16
|
+
# three different ways to supply bank account details:
|
17
|
+
#
|
18
|
+
# - [Local
|
19
|
+
# details](https://developer.gocardless.com/pro/#ui-compliance-local-bank-details)
|
20
|
+
#
|
21
|
+
#
|
22
|
+
# - IBAN
|
23
|
+
#
|
24
|
+
# - [Customer Bank Account
|
25
|
+
# Tokens](https://developer.gocardless.com/pro/#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/#ui-compliance-local-bank-details).
|
31
|
+
# Example URL: /customer_bank_accounts
|
32
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
33
|
+
# Else, they will be the body of the request.
|
34
|
+
def create(options = {}, custom_headers = {})
|
35
|
+
path = '/customer_bank_accounts'
|
36
|
+
new_options = {}
|
37
|
+
new_options[envelope_key] = options
|
38
|
+
options = new_options
|
39
|
+
response = make_request(:post, path, options, custom_headers)
|
40
|
+
|
41
|
+
Resources::CustomerBankAccount.new(unenvelope_body(response.body))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns a
|
45
|
+
# [cursor-paginated](https://developer.gocardless.com/pro/#overview-cursor-pagination)
|
46
|
+
# list of your bank accounts.
|
47
|
+
# Example URL: /customer_bank_accounts
|
48
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
49
|
+
# Else, they will be the body of the request.
|
50
|
+
def list(options = {}, custom_headers = {})
|
51
|
+
path = '/customer_bank_accounts'
|
52
|
+
|
53
|
+
response = make_request(:get, path, options, custom_headers)
|
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
|
+
).enumerator
|
71
|
+
end
|
72
|
+
|
73
|
+
# Retrieves the details of an existing bank account.
|
74
|
+
# Example URL: /customer_bank_accounts/:identity
|
75
|
+
#
|
76
|
+
# @param identity # Unique identifier, beginning with "BA"
|
77
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
78
|
+
# Else, they will be the body of the request.
|
79
|
+
def get(identity, options = {}, custom_headers = {})
|
80
|
+
path = sub_url('/customer_bank_accounts/:identity', 'identity' => identity)
|
81
|
+
|
82
|
+
response = make_request(:get, path, options, custom_headers)
|
83
|
+
|
84
|
+
Resources::CustomerBankAccount.new(unenvelope_body(response.body))
|
85
|
+
end
|
86
|
+
|
87
|
+
# Updates a customer bank account object. Only the metadata parameter is
|
88
|
+
# allowed.
|
89
|
+
# Example URL: /customer_bank_accounts/:identity
|
90
|
+
#
|
91
|
+
# @param identity # Unique identifier, beginning with "BA"
|
92
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
93
|
+
# Else, they will be the body of the request.
|
94
|
+
def update(identity, options = {}, custom_headers = {})
|
95
|
+
path = sub_url('/customer_bank_accounts/:identity', 'identity' => identity)
|
96
|
+
|
97
|
+
new_options = {}
|
98
|
+
new_options[envelope_key] = options
|
99
|
+
options = new_options
|
100
|
+
response = make_request(:put, path, options, custom_headers)
|
101
|
+
|
102
|
+
Resources::CustomerBankAccount.new(unenvelope_body(response.body))
|
103
|
+
end
|
104
|
+
|
105
|
+
# Immediately cancels all associated mandates and cancellable payments.
|
106
|
+
#
|
107
|
+
#
|
108
|
+
# This will return a `disable_failed` error if the bank account has already been
|
109
|
+
# disabled.
|
110
|
+
#
|
111
|
+
# A disabled bank account can be re-enabled by creating a new
|
112
|
+
# bank account resource with the same details.
|
113
|
+
# Example URL: /customer_bank_accounts/:identity/actions/disable
|
114
|
+
#
|
115
|
+
# @param identity # Unique identifier, beginning with "BA"
|
116
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
117
|
+
# Else, they will be the body of the request.
|
118
|
+
def disable(identity, options = {}, custom_headers = {})
|
119
|
+
path = sub_url('/customer_bank_accounts/:identity/actions/disable', 'identity' => identity)
|
120
|
+
|
121
|
+
new_options = {}
|
122
|
+
new_options['data'] = options
|
123
|
+
options = new_options
|
124
|
+
response = make_request(:post, path, options, custom_headers)
|
125
|
+
|
126
|
+
Resources::CustomerBankAccount.new(unenvelope_body(response.body))
|
127
|
+
end
|
128
|
+
|
129
|
+
# Unenvelope the response of the body using the service's `envelope_key`
|
130
|
+
#
|
131
|
+
# @param body [Hash]
|
132
|
+
def unenvelope_body(body)
|
133
|
+
body[envelope_key] || body['data']
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
# return the key which API responses will envelope data under
|
139
|
+
def envelope_key
|
140
|
+
'customer_bank_accounts'
|
141
|
+
end
|
142
|
+
|
143
|
+
# take a URL with placeholder params and substitute them out for the acutal value
|
144
|
+
# @param url [String] the URL with placeholders in
|
145
|
+
# @param param_map [Hash] a hash of placeholders and their actual values
|
146
|
+
def sub_url(url, param_map)
|
147
|
+
param_map.reduce(url) do |new_url, (param, value)|
|
148
|
+
new_url.gsub(":#{param}", value)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,112 @@
|
|
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 GoCardless
|
10
|
+
module Services
|
11
|
+
# Service for making requests to the Customer endpoints
|
12
|
+
class CustomerService < BaseService
|
13
|
+
# Creates a new customer object.
|
14
|
+
# Example URL: /customers
|
15
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
16
|
+
# Else, they will be the body of the request.
|
17
|
+
def create(options = {}, custom_headers = {})
|
18
|
+
path = '/customers'
|
19
|
+
new_options = {}
|
20
|
+
new_options[envelope_key] = options
|
21
|
+
options = new_options
|
22
|
+
response = make_request(:post, path, options, custom_headers)
|
23
|
+
|
24
|
+
Resources::Customer.new(unenvelope_body(response.body))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns a
|
28
|
+
# [cursor-paginated](https://developer.gocardless.com/pro/#overview-cursor-pagination)
|
29
|
+
# list of your customers.
|
30
|
+
# Example URL: /customers
|
31
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
32
|
+
# Else, they will be the body of the request.
|
33
|
+
def list(options = {}, custom_headers = {})
|
34
|
+
path = '/customers'
|
35
|
+
|
36
|
+
response = make_request(:get, path, options, custom_headers)
|
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
|
+
).enumerator
|
54
|
+
end
|
55
|
+
|
56
|
+
# Retrieves the details of an existing customer.
|
57
|
+
# Example URL: /customers/:identity
|
58
|
+
#
|
59
|
+
# @param identity # Unique identifier, beginning with "CU".
|
60
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
61
|
+
# Else, they will be the body of the request.
|
62
|
+
def get(identity, options = {}, custom_headers = {})
|
63
|
+
path = sub_url('/customers/:identity', 'identity' => identity)
|
64
|
+
|
65
|
+
response = make_request(:get, path, options, custom_headers)
|
66
|
+
|
67
|
+
Resources::Customer.new(unenvelope_body(response.body))
|
68
|
+
end
|
69
|
+
|
70
|
+
# Updates a customer object. Supports all of the fields supported when creating
|
71
|
+
# a customer.
|
72
|
+
# Example URL: /customers/:identity
|
73
|
+
#
|
74
|
+
# @param identity # Unique identifier, beginning with "CU".
|
75
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
76
|
+
# Else, they will be the body of the request.
|
77
|
+
def update(identity, options = {}, custom_headers = {})
|
78
|
+
path = sub_url('/customers/:identity', 'identity' => identity)
|
79
|
+
|
80
|
+
new_options = {}
|
81
|
+
new_options[envelope_key] = options
|
82
|
+
options = new_options
|
83
|
+
response = make_request(:put, path, options, custom_headers)
|
84
|
+
|
85
|
+
Resources::Customer.new(unenvelope_body(response.body))
|
86
|
+
end
|
87
|
+
|
88
|
+
# Unenvelope the response of the body using the service's `envelope_key`
|
89
|
+
#
|
90
|
+
# @param body [Hash]
|
91
|
+
def unenvelope_body(body)
|
92
|
+
body[envelope_key] || body['data']
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
# return the key which API responses will envelope data under
|
98
|
+
def envelope_key
|
99
|
+
'customers'
|
100
|
+
end
|
101
|
+
|
102
|
+
# take a URL with placeholder params and substitute them out for the acutal value
|
103
|
+
# @param url [String] the URL with placeholders in
|
104
|
+
# @param param_map [Hash] a hash of placeholders and their actual values
|
105
|
+
def sub_url(url, param_map)
|
106
|
+
param_map.reduce(url) do |new_url, (param, value)|
|
107
|
+
new_url.gsub(":#{param}", value)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
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 GoCardless
|
10
|
+
module Services
|
11
|
+
# Service for making requests to the Event endpoints
|
12
|
+
class EventService < BaseService
|
13
|
+
# Returns a
|
14
|
+
# [cursor-paginated](https://developer.gocardless.com/pro/#overview-cursor-pagination)
|
15
|
+
# list of your events.
|
16
|
+
# Example URL: /events
|
17
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
18
|
+
# Else, they will be the body of the request.
|
19
|
+
def list(options = {}, custom_headers = {})
|
20
|
+
path = '/events'
|
21
|
+
|
22
|
+
response = make_request(:get, path, options, custom_headers)
|
23
|
+
ListResponse.new(
|
24
|
+
raw_response: response,
|
25
|
+
unenveloped_body: unenvelope_body(response.body),
|
26
|
+
resource_class: Resources::Event
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
|
31
|
+
#
|
32
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
33
|
+
# Otherwise they will be the body of the request.
|
34
|
+
def all(options = {})
|
35
|
+
Paginator.new(
|
36
|
+
service: self,
|
37
|
+
path: '/events',
|
38
|
+
options: options
|
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. If the request is a GET, these will be converted to query parameters.
|
47
|
+
# Else, they will be the body of the request.
|
48
|
+
def get(identity, options = {}, custom_headers = {})
|
49
|
+
path = sub_url('/events/:identity', 'identity' => identity)
|
50
|
+
|
51
|
+
response = make_request(:get, path, options, custom_headers)
|
52
|
+
|
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
|
@@ -0,0 +1,97 @@
|
|
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 GoCardless
|
10
|
+
module Services
|
11
|
+
# Service for making requests to the Helper endpoints
|
12
|
+
class HelperService < BaseService
|
13
|
+
# Returns a PDF mandate form with a signature field, ready to be signed by your
|
14
|
+
# customer. May be fully or partially pre-filled.
|
15
|
+
#
|
16
|
+
# You must specify `Accept:
|
17
|
+
# application/pdf` on requests to this endpoint.
|
18
|
+
#
|
19
|
+
# Bank account details may
|
20
|
+
# either be supplied using the IBAN (international bank account number), or
|
21
|
+
# [local
|
22
|
+
# details](https://developer.gocardless.com/pro/#ui-compliance-local-bank-details).
|
23
|
+
# For more information on the different fields required in each country, please
|
24
|
+
# see the [local bank
|
25
|
+
# details](https://developer.gocardless.com/pro/#ui-compliance-local-bank-details)
|
26
|
+
# section.
|
27
|
+
#
|
28
|
+
# To generate a mandate in a foreign language, set your
|
29
|
+
# `Accept-Language` header to the relevant [ISO
|
30
|
+
# 639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes#Partial_ISO_639_table)
|
31
|
+
# language code. Currently Dutch, English, French, German, Italian, Portuguese
|
32
|
+
# and Spanish are supported.
|
33
|
+
#
|
34
|
+
# _Note:_ If you want to render a PDF of an
|
35
|
+
# existing mandate you can also do so using the [mandate show
|
36
|
+
# endpoint](https://developer.gocardless.com/pro/#mandates-get-a-single-mandate).
|
37
|
+
# Example URL: /helpers/mandate
|
38
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
39
|
+
# Else, they will be the body of the request.
|
40
|
+
def mandate(options = {}, custom_headers = {})
|
41
|
+
path = '/helpers/mandate'
|
42
|
+
new_options = {}
|
43
|
+
new_options['data'] = options
|
44
|
+
options = new_options
|
45
|
+
response = make_request(:post, path, options, custom_headers)
|
46
|
+
|
47
|
+
Resources::Helper.new(unenvelope_body(response.body))
|
48
|
+
end
|
49
|
+
|
50
|
+
# Check whether an account number and bank / branch code combination are
|
51
|
+
# compatible.
|
52
|
+
#
|
53
|
+
# Bank account details may either be supplied using the IBAN
|
54
|
+
# (international bank account number), or [local
|
55
|
+
# details](https://developer.gocardless.com/pro/#ui-compliance-local-bank-details).
|
56
|
+
# For more information on the different fields required in each country, please
|
57
|
+
# see the [local bank
|
58
|
+
# details](https://developer.gocardless.com/pro/#ui-compliance-local-bank-details)
|
59
|
+
# section.
|
60
|
+
# Example URL: /helpers/modulus_check
|
61
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
62
|
+
# Else, they will be the body of the request.
|
63
|
+
def modulus_check(options = {}, custom_headers = {})
|
64
|
+
path = '/helpers/modulus_check'
|
65
|
+
new_options = {}
|
66
|
+
new_options['data'] = options
|
67
|
+
options = new_options
|
68
|
+
response = make_request(:post, path, options, custom_headers)
|
69
|
+
|
70
|
+
Resources::Helper.new(unenvelope_body(response.body))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Unenvelope the response of the body using the service's `envelope_key`
|
74
|
+
#
|
75
|
+
# @param body [Hash]
|
76
|
+
def unenvelope_body(body)
|
77
|
+
body[envelope_key] || body['data']
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# return the key which API responses will envelope data under
|
83
|
+
def envelope_key
|
84
|
+
'helpers'
|
85
|
+
end
|
86
|
+
|
87
|
+
# take a URL with placeholder params and substitute them out for the acutal value
|
88
|
+
# @param url [String] the URL with placeholders in
|
89
|
+
# @param param_map [Hash] a hash of placeholders and their actual values
|
90
|
+
def sub_url(url, param_map)
|
91
|
+
param_map.reduce(url) do |new_url, (param, value)|
|
92
|
+
new_url.gsub(":#{param}", value)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,170 @@
|
|
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 GoCardless
|
10
|
+
module Services
|
11
|
+
# Service for making requests to the Mandate endpoints
|
12
|
+
class MandateService < BaseService
|
13
|
+
# Creates a new mandate object
|
14
|
+
# Example URL: /mandates
|
15
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
16
|
+
# Else, they will be the body of the request.
|
17
|
+
def create(options = {}, custom_headers = {})
|
18
|
+
path = '/mandates'
|
19
|
+
new_options = {}
|
20
|
+
new_options[envelope_key] = options
|
21
|
+
options = new_options
|
22
|
+
response = make_request(:post, path, options, custom_headers)
|
23
|
+
|
24
|
+
Resources::Mandate.new(unenvelope_body(response.body))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns a
|
28
|
+
# [cursor-paginated](https://developer.gocardless.com/pro/#overview-cursor-pagination)
|
29
|
+
# list of your mandates. Except where stated, these filters can only be used one
|
30
|
+
# at a time.
|
31
|
+
# Example URL: /mandates
|
32
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
33
|
+
# Else, they will be the body of the request.
|
34
|
+
def list(options = {}, custom_headers = {})
|
35
|
+
path = '/mandates'
|
36
|
+
|
37
|
+
response = make_request(:get, path, options, custom_headers)
|
38
|
+
ListResponse.new(
|
39
|
+
raw_response: response,
|
40
|
+
unenveloped_body: unenvelope_body(response.body),
|
41
|
+
resource_class: Resources::Mandate
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
|
46
|
+
#
|
47
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
48
|
+
# Otherwise they will be the body of the request.
|
49
|
+
def all(options = {})
|
50
|
+
Paginator.new(
|
51
|
+
service: self,
|
52
|
+
path: '/mandates',
|
53
|
+
options: options
|
54
|
+
).enumerator
|
55
|
+
end
|
56
|
+
|
57
|
+
# Retrieves the details of an existing mandate.
|
58
|
+
#
|
59
|
+
# If you specify `Accept:
|
60
|
+
# application/pdf` on a request to this endpoint it will return a PDF complying
|
61
|
+
# to the relevant scheme rules, which you can present to your customer.
|
62
|
+
#
|
63
|
+
# PDF
|
64
|
+
# mandates can be retrieved in Dutch, English, French, German, Italian,
|
65
|
+
# Portuguese and Spanish by specifying the [ISO
|
66
|
+
# 639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes#Partial_ISO_639_table)
|
67
|
+
# language code as an `Accept-Language` header.
|
68
|
+
# Example URL: /mandates/:identity
|
69
|
+
#
|
70
|
+
# @param identity # Unique identifier, beginning with "MD"
|
71
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
72
|
+
# Else, they will be the body of the request.
|
73
|
+
def get(identity, options = {}, custom_headers = {})
|
74
|
+
path = sub_url('/mandates/:identity', 'identity' => identity)
|
75
|
+
|
76
|
+
response = make_request(:get, path, options, custom_headers)
|
77
|
+
|
78
|
+
Resources::Mandate.new(unenvelope_body(response.body))
|
79
|
+
end
|
80
|
+
|
81
|
+
# Updates a mandate object. This accepts only the metadata parameter.
|
82
|
+
# Example URL: /mandates/:identity
|
83
|
+
#
|
84
|
+
# @param identity # Unique identifier, beginning with "MD"
|
85
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
86
|
+
# Else, they will be the body of the request.
|
87
|
+
def update(identity, options = {}, custom_headers = {})
|
88
|
+
path = sub_url('/mandates/:identity', 'identity' => identity)
|
89
|
+
|
90
|
+
new_options = {}
|
91
|
+
new_options[envelope_key] = options
|
92
|
+
options = new_options
|
93
|
+
response = make_request(:put, path, options, custom_headers)
|
94
|
+
|
95
|
+
Resources::Mandate.new(unenvelope_body(response.body))
|
96
|
+
end
|
97
|
+
|
98
|
+
# Immediately cancels a mandate and all associated cancellable payments. Any
|
99
|
+
# metadata supplied to this endpoint will be stored on the mandate cancellation
|
100
|
+
# event it causes.
|
101
|
+
#
|
102
|
+
# This will fail with a `cancellation_failed` error if the
|
103
|
+
# mandate is already cancelled.
|
104
|
+
# Example URL: /mandates/:identity/actions/cancel
|
105
|
+
#
|
106
|
+
# @param identity # Unique identifier, beginning with "MD"
|
107
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
108
|
+
# Else, they will be the body of the request.
|
109
|
+
def cancel(identity, options = {}, custom_headers = {})
|
110
|
+
path = sub_url('/mandates/:identity/actions/cancel', 'identity' => identity)
|
111
|
+
|
112
|
+
new_options = {}
|
113
|
+
new_options['data'] = options
|
114
|
+
options = new_options
|
115
|
+
response = make_request(:post, path, options, custom_headers)
|
116
|
+
|
117
|
+
Resources::Mandate.new(unenvelope_body(response.body))
|
118
|
+
end
|
119
|
+
|
120
|
+
# <a name="mandate_not_inactive"></a>Reinstates a cancelled or expired mandate
|
121
|
+
# to the banks. You will receive a `resubmission_requested` webhook, but after
|
122
|
+
# that reinstating the mandate follows the same process as its initial creation,
|
123
|
+
# so you will receive a `submitted` webhook, followed by a `reinstated` or
|
124
|
+
# `failed` webhook up to two working days later. Any metadata supplied to this
|
125
|
+
# endpoint will be stored on the `resubmission_requested` event it causes.
|
126
|
+
#
|
127
|
+
#
|
128
|
+
# This will fail with a `mandate_not_inactive` error if the mandate is already
|
129
|
+
# being submitted, or is active.
|
130
|
+
# Example URL: /mandates/:identity/actions/reinstate
|
131
|
+
#
|
132
|
+
# @param identity # Unique identifier, beginning with "MD"
|
133
|
+
# @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
|
134
|
+
# Else, they will be the body of the request.
|
135
|
+
def reinstate(identity, options = {}, custom_headers = {})
|
136
|
+
path = sub_url('/mandates/:identity/actions/reinstate', 'identity' => identity)
|
137
|
+
|
138
|
+
new_options = {}
|
139
|
+
new_options['data'] = options
|
140
|
+
options = new_options
|
141
|
+
response = make_request(:post, path, options, custom_headers)
|
142
|
+
|
143
|
+
Resources::Mandate.new(unenvelope_body(response.body))
|
144
|
+
end
|
145
|
+
|
146
|
+
# Unenvelope the response of the body using the service's `envelope_key`
|
147
|
+
#
|
148
|
+
# @param body [Hash]
|
149
|
+
def unenvelope_body(body)
|
150
|
+
body[envelope_key] || body['data']
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
# return the key which API responses will envelope data under
|
156
|
+
def envelope_key
|
157
|
+
'mandates'
|
158
|
+
end
|
159
|
+
|
160
|
+
# take a URL with placeholder params and substitute them out for the acutal value
|
161
|
+
# @param url [String] the URL with placeholders in
|
162
|
+
# @param param_map [Hash] a hash of placeholders and their actual values
|
163
|
+
def sub_url(url, param_map)
|
164
|
+
param_map.reduce(url) do |new_url, (param, value)|
|
165
|
+
new_url.gsub(":#{param}", value)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|