gocardless-pro 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) 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 +132 -0
  6. data/circle.yml +18 -0
  7. data/demo.rb +10 -0
  8. data/gocardless-pro.gemspec +27 -0
  9. data/lib/gocardless-pro.rb +243 -0
  10. data/lib/gocardless-pro/api_service.rb +57 -0
  11. data/lib/gocardless-pro/error.rb +42 -0
  12. data/lib/gocardless-pro/error/gocardless_error.rb +5 -0
  13. data/lib/gocardless-pro/error/invalid_api_usage_error.rb +5 -0
  14. data/lib/gocardless-pro/error/invalid_state_error.rb +5 -0
  15. data/lib/gocardless-pro/error/validation_error.rb +5 -0
  16. data/lib/gocardless-pro/list_response.rb +34 -0
  17. data/lib/gocardless-pro/paginator.rb +37 -0
  18. data/lib/gocardless-pro/request.rb +69 -0
  19. data/lib/gocardless-pro/resources/api_key.rb +62 -0
  20. data/lib/gocardless-pro/resources/creditor.rb +83 -0
  21. data/lib/gocardless-pro/resources/creditor_bank_account.rb +78 -0
  22. data/lib/gocardless-pro/resources/customer.rb +72 -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 +86 -0
  28. data/lib/gocardless-pro/resources/payout.rb +66 -0
  29. data/lib/gocardless-pro/resources/publishable_api_key.rb +51 -0
  30. data/lib/gocardless-pro/resources/redirect_flow.rb +104 -0
  31. data/lib/gocardless-pro/resources/refund.rb +70 -0
  32. data/lib/gocardless-pro/resources/role.rb +101 -0
  33. data/lib/gocardless-pro/resources/subscription.rb +152 -0
  34. data/lib/gocardless-pro/resources/user.rb +60 -0
  35. data/lib/gocardless-pro/response.rb +77 -0
  36. data/lib/gocardless-pro/services/api_key_service.rb +130 -0
  37. data/lib/gocardless-pro/services/base_service.rb +29 -0
  38. data/lib/gocardless-pro/services/creditor_bank_account_service.rb +122 -0
  39. data/lib/gocardless-pro/services/creditor_service.rb +112 -0
  40. data/lib/gocardless-pro/services/customer_bank_account_service.rb +153 -0
  41. data/lib/gocardless-pro/services/customer_service.rb +112 -0
  42. data/lib/gocardless-pro/services/event_service.rb +80 -0
  43. data/lib/gocardless-pro/services/helper_service.rb +97 -0
  44. data/lib/gocardless-pro/services/mandate_service.rb +170 -0
  45. data/lib/gocardless-pro/services/payment_service.rb +164 -0
  46. data/lib/gocardless-pro/services/payout_service.rb +80 -0
  47. data/lib/gocardless-pro/services/publishable_api_key_service.rb +130 -0
  48. data/lib/gocardless-pro/services/redirect_flow_service.rb +96 -0
  49. data/lib/gocardless-pro/services/refund_service.rb +126 -0
  50. data/lib/gocardless-pro/services/role_service.rb +127 -0
  51. data/lib/gocardless-pro/services/subscription_service.rb +133 -0
  52. data/lib/gocardless-pro/services/user_service.rb +148 -0
  53. data/lib/gocardless-pro/version.rb +8 -0
  54. data/spec/api_service_spec.rb +69 -0
  55. data/spec/client_spec.rb +29 -0
  56. data/spec/error_spec.rb +44 -0
  57. data/spec/resources/api_key_spec.rb +85 -0
  58. data/spec/resources/creditor_bank_account_spec.rb +109 -0
  59. data/spec/resources/creditor_spec.rb +125 -0
  60. data/spec/resources/customer_bank_account_spec.rb +109 -0
  61. data/spec/resources/customer_spec.rb +127 -0
  62. data/spec/resources/event_spec.rb +113 -0
  63. data/spec/resources/helper_spec.rb +23 -0
  64. data/spec/resources/mandate_spec.rb +97 -0
  65. data/spec/resources/payment_spec.rb +129 -0
  66. data/spec/resources/payout_spec.rb +89 -0
  67. data/spec/resources/publishable_api_key_spec.rb +63 -0
  68. data/spec/resources/redirect_flow_spec.rb +97 -0
  69. data/spec/resources/refund_spec.rb +77 -0
  70. data/spec/resources/role_spec.rb +63 -0
  71. data/spec/resources/subscription_spec.rb +157 -0
  72. data/spec/resources/user_spec.rb +85 -0
  73. data/spec/response_spec.rb +79 -0
  74. data/spec/services/api_key_service_spec.rb +362 -0
  75. data/spec/services/creditor_bank_account_service_spec.rb +365 -0
  76. data/spec/services/creditor_service_spec.rb +339 -0
  77. data/spec/services/customer_bank_account_service_spec.rb +404 -0
  78. data/spec/services/customer_service_spec.rb +365 -0
  79. data/spec/services/event_service_spec.rb +172 -0
  80. data/spec/services/helper_service_spec.rb +123 -0
  81. data/spec/services/mandate_service_spec.rb +449 -0
  82. data/spec/services/payment_service_spec.rb +497 -0
  83. data/spec/services/payout_service_spec.rb +172 -0
  84. data/spec/services/publishable_api_key_service_spec.rb +336 -0
  85. data/spec/services/redirect_flow_service_spec.rb +208 -0
  86. data/spec/services/refund_service_spec.rb +279 -0
  87. data/spec/services/role_service_spec.rb +336 -0
  88. data/spec/services/subscription_service_spec.rb +488 -0
  89. data/spec/services/user_service_spec.rb +433 -0
  90. data/spec/spec_helper.rb +91 -0
  91. metadata +255 -0
@@ -0,0 +1,172 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Services::EventService do
4
+ let(:client) do
5
+ GoCardless::Client.new(
6
+ api_key: "AK123",
7
+ api_secret: "ABC"
8
+ )
9
+ end
10
+
11
+
12
+
13
+
14
+
15
+
16
+ describe "#list" do
17
+ describe "with no filters" do
18
+ subject(:get_list_response) { client.events.list }
19
+
20
+ before do
21
+ stub_request(:get, /.*api.gocardless.com\/events/).to_return(
22
+ body: {
23
+ events: [{
24
+
25
+ "action" => "action-input",
26
+ "created_at" => "created_at-input",
27
+ "details" => "details-input",
28
+ "id" => "id-input",
29
+ "links" => "links-input",
30
+ "metadata" => "metadata-input",
31
+ "resource_type" => "resource_type-input",
32
+ }],
33
+ meta: {
34
+ cursors: {
35
+ before: nil,
36
+ after: "ABC123"
37
+ }
38
+ }
39
+ }.to_json,
40
+ :headers => {'Content-Type' => 'application/json'}
41
+ )
42
+ end
43
+
44
+ it "wraps each item in the resource class" do
45
+ expect(get_list_response.map { |x| x.class }.uniq.first).to eq(GoCardless::Resources::Event)
46
+
47
+
48
+
49
+ expect(get_list_response.first.action).to eq("action-input")
50
+
51
+
52
+
53
+ expect(get_list_response.first.created_at).to eq("created_at-input")
54
+
55
+
56
+
57
+ expect(get_list_response.first.details).to eq("details-input")
58
+
59
+
60
+
61
+ expect(get_list_response.first.id).to eq("id-input")
62
+
63
+
64
+
65
+
66
+
67
+ expect(get_list_response.first.metadata).to eq("metadata-input")
68
+
69
+
70
+
71
+ expect(get_list_response.first.resource_type).to eq("resource_type-input")
72
+
73
+
74
+ end
75
+
76
+ it "exposes the cursors for before and after" do
77
+ expect(get_list_response.before).to eq(nil)
78
+ expect(get_list_response.after).to eq("ABC123")
79
+ end
80
+ end
81
+ end
82
+
83
+ describe "#all" do
84
+ let!(:first_response_stub) do
85
+ stub_request(:get, /.*api.gocardless.com\/events$/).to_return(
86
+ body: {
87
+ events: [{
88
+
89
+ "action" => "action-input",
90
+ "created_at" => "created_at-input",
91
+ "details" => "details-input",
92
+ "id" => "id-input",
93
+ "links" => "links-input",
94
+ "metadata" => "metadata-input",
95
+ "resource_type" => "resource_type-input",
96
+ }],
97
+ meta: {
98
+ cursors: { after: 'AB345' },
99
+ limit: 1
100
+ }
101
+ }.to_json,
102
+ :headers => {'Content-Type' => 'application/json'}
103
+ )
104
+ end
105
+
106
+ let!(:second_response_stub) do
107
+ stub_request(:get, /.*api.gocardless.com\/events\?after=AB345/).to_return(
108
+ body: {
109
+ events: [{
110
+
111
+ "action" => "action-input",
112
+ "created_at" => "created_at-input",
113
+ "details" => "details-input",
114
+ "id" => "id-input",
115
+ "links" => "links-input",
116
+ "metadata" => "metadata-input",
117
+ "resource_type" => "resource_type-input",
118
+ }],
119
+ meta: {
120
+ limit: 2,
121
+ cursors: {}
122
+ }
123
+ }.to_json,
124
+ :headers => {'Content-Type' => 'application/json'}
125
+ )
126
+ end
127
+
128
+ it "automatically makes the extra requests" do
129
+ expect(client.events.all.to_a.length).to eq(2)
130
+ expect(first_response_stub).to have_been_requested
131
+ expect(second_response_stub).to have_been_requested
132
+ end
133
+ end
134
+
135
+
136
+
137
+
138
+
139
+
140
+ describe "#get" do
141
+ let(:id) { "ID123" }
142
+
143
+ subject(:get_response) { client.events.get(id) }
144
+
145
+ context "when there is a event to return" do
146
+ before do
147
+ stub_request(:get, /.*api.gocardless.com\/events\/ID123/).to_return(
148
+ body: {
149
+ events: {
150
+
151
+ "action" => "action-input",
152
+ "created_at" => "created_at-input",
153
+ "details" => "details-input",
154
+ "id" => "id-input",
155
+ "links" => "links-input",
156
+ "metadata" => "metadata-input",
157
+ "resource_type" => "resource_type-input",
158
+ }
159
+ }.to_json,
160
+ :headers => {'Content-Type' => 'application/json'}
161
+ )
162
+ end
163
+
164
+ it "wraps the response in a resource" do
165
+ expect(get_response).to be_a(GoCardless::Resources::Event)
166
+ end
167
+ end
168
+ end
169
+
170
+
171
+
172
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Services::HelperService do
4
+ let(:client) do
5
+ GoCardless::Client.new(
6
+ api_key: "AK123",
7
+ api_secret: "ABC"
8
+ )
9
+ end
10
+
11
+
12
+
13
+
14
+
15
+
16
+ describe "#mandate" do
17
+
18
+
19
+ subject(:post_response) { client.helpers.mandate }
20
+
21
+ let(:resource_id) { "ABC123" }
22
+
23
+ let!(:stub) do
24
+ # /helpers/mandate
25
+ stub_url = "/helpers/mandate".gsub(':identity', resource_id)
26
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
27
+ body: {
28
+ helpers: {
29
+
30
+ }
31
+ }.to_json,
32
+ headers: {'Content-Type' => 'application/json'},
33
+ )
34
+ end
35
+
36
+ it "wraps the response and calls the right endpoint" do
37
+ expect(post_response).to be_a(GoCardless::Resources::Helper)
38
+
39
+ expect(stub).to have_been_requested
40
+ end
41
+
42
+ context "when the request needs a body and custom header" do
43
+
44
+ subject(:post_response) { client.helpers.mandate(body, headers) }
45
+
46
+ let(:resource_id) { "ABC123" }
47
+
48
+ let!(:stub) do
49
+ # /helpers/mandate
50
+ stub_url = "/helpers/mandate".gsub(':identity', resource_id)
51
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
52
+ with(
53
+ body: { foo: 'bar' },
54
+ headers: { 'Foo' => 'Bar' }
55
+ ).to_return(
56
+ body: {
57
+ helpers: {
58
+
59
+ }
60
+ }.to_json,
61
+ headers: {'Content-Type' => 'application/json'},
62
+ )
63
+ end
64
+ end
65
+ end
66
+
67
+
68
+
69
+
70
+
71
+ describe "#modulus_check" do
72
+
73
+
74
+ subject(:post_response) { client.helpers.modulus_check }
75
+
76
+ let(:resource_id) { "ABC123" }
77
+
78
+ let!(:stub) do
79
+ # /helpers/modulus_check
80
+ stub_url = "/helpers/modulus_check".gsub(':identity', resource_id)
81
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
82
+ body: {
83
+ helpers: {
84
+
85
+ }
86
+ }.to_json,
87
+ headers: {'Content-Type' => 'application/json'},
88
+ )
89
+ end
90
+
91
+ it "wraps the response and calls the right endpoint" do
92
+ expect(post_response).to be_a(GoCardless::Resources::Helper)
93
+
94
+ expect(stub).to have_been_requested
95
+ end
96
+
97
+ context "when the request needs a body and custom header" do
98
+
99
+ subject(:post_response) { client.helpers.modulus_check(body, headers) }
100
+
101
+ let(:resource_id) { "ABC123" }
102
+
103
+ let!(:stub) do
104
+ # /helpers/modulus_check
105
+ stub_url = "/helpers/modulus_check".gsub(':identity', resource_id)
106
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
107
+ with(
108
+ body: { foo: 'bar' },
109
+ headers: { 'Foo' => 'Bar' }
110
+ ).to_return(
111
+ body: {
112
+ helpers: {
113
+
114
+ }
115
+ }.to_json,
116
+ headers: {'Content-Type' => 'application/json'},
117
+ )
118
+ end
119
+ end
120
+ end
121
+
122
+
123
+ end
@@ -0,0 +1,449 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardless::Services::MandateService do
4
+ let(:client) do
5
+ GoCardless::Client.new(
6
+ api_key: "AK123",
7
+ api_secret: "ABC"
8
+ )
9
+ end
10
+
11
+
12
+
13
+
14
+
15
+
16
+ describe "#create" do
17
+ subject(:post_create_response) { client.mandates.create(new_resource) }
18
+ context "with a valid request" do
19
+ let(:new_resource) do
20
+ {
21
+
22
+ "created_at" => "created_at-input",
23
+ "id" => "id-input",
24
+ "links" => "links-input",
25
+ "metadata" => "metadata-input",
26
+ "next_possible_charge_date" => "next_possible_charge_date-input",
27
+ "reference" => "reference-input",
28
+ "scheme" => "scheme-input",
29
+ "status" => "status-input",
30
+ }
31
+ end
32
+
33
+ before do
34
+ stub_request(:post, /.*api.gocardless.com\/mandates/).
35
+ with(
36
+ body: {
37
+ mandates: {
38
+
39
+ "created_at" => "created_at-input",
40
+ "id" => "id-input",
41
+ "links" => "links-input",
42
+ "metadata" => "metadata-input",
43
+ "next_possible_charge_date" => "next_possible_charge_date-input",
44
+ "reference" => "reference-input",
45
+ "scheme" => "scheme-input",
46
+ "status" => "status-input",
47
+ }
48
+ }
49
+ ).
50
+ to_return(
51
+ body: {
52
+ mandates: {
53
+
54
+ "created_at" => "created_at-input",
55
+ "id" => "id-input",
56
+ "links" => "links-input",
57
+ "metadata" => "metadata-input",
58
+ "next_possible_charge_date" => "next_possible_charge_date-input",
59
+ "reference" => "reference-input",
60
+ "scheme" => "scheme-input",
61
+ "status" => "status-input",
62
+ }
63
+ }.to_json,
64
+ :headers => {'Content-Type' => 'application/json'}
65
+ )
66
+ end
67
+
68
+ it "creates and returns the resource" do
69
+ expect(post_create_response).to be_a(GoCardless::Resources::Mandate)
70
+ end
71
+ end
72
+
73
+ context "with a request that returns a validation error" do
74
+ let(:new_resource) { {} }
75
+
76
+ before do
77
+ stub_request(:post, /.*api.gocardless.com\/mandates/).to_return(
78
+ body: {
79
+ error: {
80
+ type: 'validation_failed',
81
+ code: 422,
82
+ errors: [
83
+ { message: 'test error message', field: 'test_field' }
84
+ ]
85
+ }
86
+ }.to_json,
87
+ headers: {'Content-Type' => 'application/json'},
88
+ status: 422
89
+ )
90
+ end
91
+
92
+ it "throws the correct error" do
93
+ expect { post_create_response }.to raise_error(GoCardless::ValidationError)
94
+ end
95
+ end
96
+ end
97
+
98
+
99
+
100
+
101
+
102
+ describe "#list" do
103
+ describe "with no filters" do
104
+ subject(:get_list_response) { client.mandates.list }
105
+
106
+ before do
107
+ stub_request(:get, /.*api.gocardless.com\/mandates/).to_return(
108
+ body: {
109
+ mandates: [{
110
+
111
+ "created_at" => "created_at-input",
112
+ "id" => "id-input",
113
+ "links" => "links-input",
114
+ "metadata" => "metadata-input",
115
+ "next_possible_charge_date" => "next_possible_charge_date-input",
116
+ "reference" => "reference-input",
117
+ "scheme" => "scheme-input",
118
+ "status" => "status-input",
119
+ }],
120
+ meta: {
121
+ cursors: {
122
+ before: nil,
123
+ after: "ABC123"
124
+ }
125
+ }
126
+ }.to_json,
127
+ :headers => {'Content-Type' => 'application/json'}
128
+ )
129
+ end
130
+
131
+ it "wraps each item in the resource class" do
132
+ expect(get_list_response.map { |x| x.class }.uniq.first).to eq(GoCardless::Resources::Mandate)
133
+
134
+
135
+
136
+ expect(get_list_response.first.created_at).to eq("created_at-input")
137
+
138
+
139
+
140
+ expect(get_list_response.first.id).to eq("id-input")
141
+
142
+
143
+
144
+
145
+
146
+ expect(get_list_response.first.metadata).to eq("metadata-input")
147
+
148
+
149
+
150
+ expect(get_list_response.first.next_possible_charge_date).to eq("next_possible_charge_date-input")
151
+
152
+
153
+
154
+ expect(get_list_response.first.reference).to eq("reference-input")
155
+
156
+
157
+
158
+ expect(get_list_response.first.scheme).to eq("scheme-input")
159
+
160
+
161
+
162
+ expect(get_list_response.first.status).to eq("status-input")
163
+
164
+
165
+ end
166
+
167
+ it "exposes the cursors for before and after" do
168
+ expect(get_list_response.before).to eq(nil)
169
+ expect(get_list_response.after).to eq("ABC123")
170
+ end
171
+ end
172
+ end
173
+
174
+ describe "#all" do
175
+ let!(:first_response_stub) do
176
+ stub_request(:get, /.*api.gocardless.com\/mandates$/).to_return(
177
+ body: {
178
+ mandates: [{
179
+
180
+ "created_at" => "created_at-input",
181
+ "id" => "id-input",
182
+ "links" => "links-input",
183
+ "metadata" => "metadata-input",
184
+ "next_possible_charge_date" => "next_possible_charge_date-input",
185
+ "reference" => "reference-input",
186
+ "scheme" => "scheme-input",
187
+ "status" => "status-input",
188
+ }],
189
+ meta: {
190
+ cursors: { after: 'AB345' },
191
+ limit: 1
192
+ }
193
+ }.to_json,
194
+ :headers => {'Content-Type' => 'application/json'}
195
+ )
196
+ end
197
+
198
+ let!(:second_response_stub) do
199
+ stub_request(:get, /.*api.gocardless.com\/mandates\?after=AB345/).to_return(
200
+ body: {
201
+ mandates: [{
202
+
203
+ "created_at" => "created_at-input",
204
+ "id" => "id-input",
205
+ "links" => "links-input",
206
+ "metadata" => "metadata-input",
207
+ "next_possible_charge_date" => "next_possible_charge_date-input",
208
+ "reference" => "reference-input",
209
+ "scheme" => "scheme-input",
210
+ "status" => "status-input",
211
+ }],
212
+ meta: {
213
+ limit: 2,
214
+ cursors: {}
215
+ }
216
+ }.to_json,
217
+ :headers => {'Content-Type' => 'application/json'}
218
+ )
219
+ end
220
+
221
+ it "automatically makes the extra requests" do
222
+ expect(client.mandates.all.to_a.length).to eq(2)
223
+ expect(first_response_stub).to have_been_requested
224
+ expect(second_response_stub).to have_been_requested
225
+ end
226
+ end
227
+
228
+
229
+
230
+
231
+
232
+
233
+ describe "#get" do
234
+ let(:id) { "ID123" }
235
+
236
+ subject(:get_response) { client.mandates.get(id) }
237
+
238
+ context "when there is a mandate to return" do
239
+ before do
240
+ stub_request(:get, /.*api.gocardless.com\/mandates\/ID123/).to_return(
241
+ body: {
242
+ mandates: {
243
+
244
+ "created_at" => "created_at-input",
245
+ "id" => "id-input",
246
+ "links" => "links-input",
247
+ "metadata" => "metadata-input",
248
+ "next_possible_charge_date" => "next_possible_charge_date-input",
249
+ "reference" => "reference-input",
250
+ "scheme" => "scheme-input",
251
+ "status" => "status-input",
252
+ }
253
+ }.to_json,
254
+ :headers => {'Content-Type' => 'application/json'}
255
+ )
256
+ end
257
+
258
+ it "wraps the response in a resource" do
259
+ expect(get_response).to be_a(GoCardless::Resources::Mandate)
260
+ end
261
+ end
262
+ end
263
+
264
+
265
+
266
+
267
+
268
+
269
+ describe "#update" do
270
+ subject(:put_update_response) { client.mandates.update(id, update_params) }
271
+ let(:id) { "ABC123" }
272
+
273
+ context "with a valid request" do
274
+ let(:update_params) { { "hello" => "world" } }
275
+
276
+ let!(:stub) do
277
+ stub_request(:put, /.*api.gocardless.com\/mandates\/ABC123/).to_return(
278
+ body: {
279
+ mandates: {
280
+
281
+ "created_at" => "created_at-input",
282
+ "id" => "id-input",
283
+ "links" => "links-input",
284
+ "metadata" => "metadata-input",
285
+ "next_possible_charge_date" => "next_possible_charge_date-input",
286
+ "reference" => "reference-input",
287
+ "scheme" => "scheme-input",
288
+ "status" => "status-input",
289
+ }
290
+ }.to_json,
291
+ :headers => {'Content-Type' => 'application/json'}
292
+ )
293
+ end
294
+
295
+ it "updates and returns the resource" do
296
+ expect(put_update_response).to be_a(GoCardless::Resources::Mandate)
297
+ expect(stub).to have_been_requested
298
+ end
299
+ end
300
+ end
301
+
302
+
303
+
304
+
305
+
306
+ describe "#cancel" do
307
+
308
+
309
+ subject(:post_response) { client.mandates.cancel(resource_id) }
310
+
311
+ let(:resource_id) { "ABC123" }
312
+
313
+ let!(:stub) do
314
+ # /mandates/%v/actions/cancel
315
+ stub_url = "/mandates/:identity/actions/cancel".gsub(':identity', resource_id)
316
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
317
+ body: {
318
+ mandates: {
319
+
320
+ "created_at" => "created_at-input",
321
+ "id" => "id-input",
322
+ "links" => "links-input",
323
+ "metadata" => "metadata-input",
324
+ "next_possible_charge_date" => "next_possible_charge_date-input",
325
+ "reference" => "reference-input",
326
+ "scheme" => "scheme-input",
327
+ "status" => "status-input",
328
+ }
329
+ }.to_json,
330
+ headers: {'Content-Type' => 'application/json'},
331
+ )
332
+ end
333
+
334
+ it "wraps the response and calls the right endpoint" do
335
+ expect(post_response).to be_a(GoCardless::Resources::Mandate)
336
+
337
+ expect(stub).to have_been_requested
338
+ end
339
+
340
+ context "when the request needs a body and custom header" do
341
+
342
+ let(:body) { { foo: 'bar' } }
343
+ let(:headers) { { 'Foo' => 'Bar' } }
344
+ subject(:post_response) { client.mandates.cancel(resource_id, body, headers) }
345
+
346
+ let(:resource_id) { "ABC123" }
347
+
348
+ let!(:stub) do
349
+ # /mandates/%v/actions/cancel
350
+ stub_url = "/mandates/:identity/actions/cancel".gsub(':identity', resource_id)
351
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
352
+ with(
353
+ body: { foo: 'bar' },
354
+ headers: { 'Foo' => 'Bar' }
355
+ ).to_return(
356
+ body: {
357
+ mandates: {
358
+
359
+ "created_at" => "created_at-input",
360
+ "id" => "id-input",
361
+ "links" => "links-input",
362
+ "metadata" => "metadata-input",
363
+ "next_possible_charge_date" => "next_possible_charge_date-input",
364
+ "reference" => "reference-input",
365
+ "scheme" => "scheme-input",
366
+ "status" => "status-input",
367
+ }
368
+ }.to_json,
369
+ headers: {'Content-Type' => 'application/json'},
370
+ )
371
+ end
372
+ end
373
+ end
374
+
375
+
376
+
377
+
378
+
379
+ describe "#reinstate" do
380
+
381
+
382
+ subject(:post_response) { client.mandates.reinstate(resource_id) }
383
+
384
+ let(:resource_id) { "ABC123" }
385
+
386
+ let!(:stub) do
387
+ # /mandates/%v/actions/reinstate
388
+ stub_url = "/mandates/:identity/actions/reinstate".gsub(':identity', resource_id)
389
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
390
+ body: {
391
+ mandates: {
392
+
393
+ "created_at" => "created_at-input",
394
+ "id" => "id-input",
395
+ "links" => "links-input",
396
+ "metadata" => "metadata-input",
397
+ "next_possible_charge_date" => "next_possible_charge_date-input",
398
+ "reference" => "reference-input",
399
+ "scheme" => "scheme-input",
400
+ "status" => "status-input",
401
+ }
402
+ }.to_json,
403
+ headers: {'Content-Type' => 'application/json'},
404
+ )
405
+ end
406
+
407
+ it "wraps the response and calls the right endpoint" do
408
+ expect(post_response).to be_a(GoCardless::Resources::Mandate)
409
+
410
+ expect(stub).to have_been_requested
411
+ end
412
+
413
+ context "when the request needs a body and custom header" do
414
+
415
+ let(:body) { { foo: 'bar' } }
416
+ let(:headers) { { 'Foo' => 'Bar' } }
417
+ subject(:post_response) { client.mandates.reinstate(resource_id, body, headers) }
418
+
419
+ let(:resource_id) { "ABC123" }
420
+
421
+ let!(:stub) do
422
+ # /mandates/%v/actions/reinstate
423
+ stub_url = "/mandates/:identity/actions/reinstate".gsub(':identity', resource_id)
424
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
425
+ with(
426
+ body: { foo: 'bar' },
427
+ headers: { 'Foo' => 'Bar' }
428
+ ).to_return(
429
+ body: {
430
+ mandates: {
431
+
432
+ "created_at" => "created_at-input",
433
+ "id" => "id-input",
434
+ "links" => "links-input",
435
+ "metadata" => "metadata-input",
436
+ "next_possible_charge_date" => "next_possible_charge_date-input",
437
+ "reference" => "reference-input",
438
+ "scheme" => "scheme-input",
439
+ "status" => "status-input",
440
+ }
441
+ }.to_json,
442
+ headers: {'Content-Type' => 'application/json'},
443
+ )
444
+ end
445
+ end
446
+ end
447
+
448
+
449
+ end