gocardless_pro 1.0.3 → 1.0.4

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -0
  3. data/README.md +71 -28
  4. data/gocardless_pro.gemspec +1 -1
  5. data/lib/gocardless_pro/api_service.rb +4 -2
  6. data/lib/gocardless_pro/client.rb +2 -1
  7. data/lib/gocardless_pro/error.rb +12 -1
  8. data/lib/gocardless_pro/resources/mandate.rb +3 -0
  9. data/lib/gocardless_pro/resources/payout.rb +3 -0
  10. data/lib/gocardless_pro/resources/redirect_flow.rb +15 -14
  11. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +10 -0
  12. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +5 -2
  13. data/lib/gocardless_pro/services/creditors_service.rb +5 -2
  14. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +7 -3
  15. data/lib/gocardless_pro/services/customers_service.rb +5 -2
  16. data/lib/gocardless_pro/services/events_service.rb +2 -1
  17. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +2 -1
  18. data/lib/gocardless_pro/services/mandates_service.rb +10 -5
  19. data/lib/gocardless_pro/services/payments_service.rb +11 -6
  20. data/lib/gocardless_pro/services/payouts_service.rb +2 -1
  21. data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -3
  22. data/lib/gocardless_pro/services/refunds_service.rb +5 -2
  23. data/lib/gocardless_pro/services/subscriptions_service.rb +7 -3
  24. data/lib/gocardless_pro/version.rb +1 -1
  25. data/spec/api_response_spec.rb +4 -4
  26. data/spec/api_service_spec.rb +41 -43
  27. data/spec/client_spec.rb +2 -2
  28. data/spec/error_spec.rb +27 -18
  29. data/spec/resources/bank_details_lookup_spec.rb +19 -34
  30. data/spec/resources/creditor_bank_account_spec.rb +54 -99
  31. data/spec/resources/creditor_spec.rb +66 -115
  32. data/spec/resources/customer_bank_account_spec.rb +54 -99
  33. data/spec/resources/customer_spec.rb +71 -138
  34. data/spec/resources/event_spec.rb +74 -107
  35. data/spec/resources/mandate_pdf_spec.rb +15 -26
  36. data/spec/resources/mandate_spec.rb +54 -87
  37. data/spec/resources/payment_spec.rb +70 -119
  38. data/spec/resources/payout_spec.rb +50 -79
  39. data/spec/resources/redirect_flow_spec.rb +58 -95
  40. data/spec/resources/refund_spec.rb +42 -75
  41. data/spec/resources/subscription_spec.rb +82 -155
  42. data/spec/response_spec.rb +45 -46
  43. data/spec/services/bank_details_lookups_service_spec.rb +55 -60
  44. data/spec/services/creditor_bank_accounts_service_spec.rb +303 -347
  45. data/spec/services/creditors_service_spec.rb +290 -333
  46. data/spec/services/customer_bank_accounts_service_spec.rb +332 -380
  47. data/spec/services/customers_service_spec.rb +347 -400
  48. data/spec/services/events_service_spec.rb +154 -184
  49. data/spec/services/mandate_pdfs_service_spec.rb +52 -57
  50. data/spec/services/mandates_service_spec.rb +374 -410
  51. data/spec/services/payments_service_spec.rb +404 -461
  52. data/spec/services/payouts_service_spec.rb +161 -184
  53. data/spec/services/redirect_flows_service_spec.rb +188 -205
  54. data/spec/services/refunds_service_spec.rb +245 -280
  55. data/spec/services/subscriptions_service_spec.rb +423 -485
  56. data/spec/spec_helper.rb +46 -48
  57. metadata +22 -20
@@ -1,72 +1,70 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GoCardlessPro::ApiService do
4
- subject(:service) { described_class.new("https://api.example.com", "secret_token") }
4
+ subject(:service) { described_class.new('https://api.example.com', 'secret_token') }
5
5
 
6
- it "uses basic auth" do
7
- stub = stub_request(:get, 'https://api.example.com/customers').
8
- with(headers: { "Authorization" => "Bearer secret_token" })
9
- service.make_request(:get, "/customers")
6
+ it 'uses basic auth' do
7
+ stub = stub_request(:get, 'https://api.example.com/customers')
8
+ .with(headers: { 'Authorization' => 'Bearer secret_token' })
9
+ service.make_request(:get, '/customers')
10
10
  expect(stub).to have_been_requested
11
11
  end
12
12
 
13
- describe "making a get request without any parameters" do
14
- it "is expected to call the correct stub" do
13
+ describe 'making a get request without any parameters' do
14
+ it 'is expected to call the correct stub' do
15
15
  stub = stub_request(:get, /.*api.example.com\/customers/)
16
- service.make_request(:get, "/customers")
16
+ service.make_request(:get, '/customers')
17
17
  expect(stub).to have_been_requested
18
18
  end
19
19
  end
20
20
 
21
- describe "making a get request with query parameters" do
22
- it "correctly passes the query parameters" do
21
+ describe 'making a get request with query parameters' do
22
+ it 'correctly passes the query parameters' do
23
23
  stub = stub_request(:get, /.*api.example.com\/customers\?a=1&b=2/)
24
- service.make_request(:get, "/customers", params: { a: 1, b: 2 })
24
+ service.make_request(:get, '/customers', params: { a: 1, b: 2 })
25
25
  expect(stub).to have_been_requested
26
26
  end
27
27
  end
28
28
 
29
- describe "making a post request with some data" do
30
- it "passes the data in as the post body" do
31
- stub = stub_request(:post, /.*api.example.com\/customers/).
32
- with(body: { given_name: "Jack", family_name: "Franklin" })
33
- service.make_request(:post, "/customers", params: {
34
- given_name: "Jack",
35
- family_name: "Franklin"
36
- })
29
+ describe 'making a post request with some data' do
30
+ it 'passes the data in as the post body' do
31
+ stub = stub_request(:post, /.*api.example.com\/customers/)
32
+ .with(body: { given_name: 'Jack', family_name: 'Franklin' })
33
+ service.make_request(:post, '/customers', params: {
34
+ given_name: 'Jack',
35
+ family_name: 'Franklin'
36
+ })
37
37
  expect(stub).to have_been_requested
38
38
  end
39
39
  end
40
40
 
41
- describe "making a post request with data and custom header" do
42
- it "passes the data in as the post body" do
43
- stub = stub_request(:post, /.*api.example.com\/customers/).
44
- with(
45
- body: { given_name: "Jack", family_name: "Franklin" },
46
- headers: { 'Foo' => 'Bar' }
47
- )
41
+ describe 'making a post request with data and custom header' do
42
+ it 'passes the data in as the post body' do
43
+ stub = stub_request(:post, /.*api.example.com\/customers/)
44
+ .with(
45
+ body: { given_name: 'Jack', family_name: 'Franklin' },
46
+ headers: { 'Foo' => 'Bar' }
47
+ )
48
48
 
49
- service.make_request(:post, "/customers", {
50
- params: {
51
- given_name: "Jack",
52
- family_name: "Franklin"
53
- },
54
- headers: {
55
- 'Foo' => 'Bar'
56
- }
57
- })
49
+ service.make_request(:post, '/customers', params: {
50
+ given_name: 'Jack',
51
+ family_name: 'Franklin'
52
+ },
53
+ headers: {
54
+ 'Foo' => 'Bar'
55
+ })
58
56
  expect(stub).to have_been_requested
59
57
  end
60
58
  end
61
59
 
62
- describe "making a put request with some data" do
63
- it "passes the data in as the request body" do
64
- stub = stub_request(:put, /.*api.example.com\/customers\/CU123/).
65
- with(body: { given_name: "Jack", family_name: "Franklin" })
66
- service.make_request(:put, "/customers/CU123", params: {
67
- given_name: "Jack",
68
- family_name: "Franklin"
69
- })
60
+ describe 'making a put request with some data' do
61
+ it 'passes the data in as the request body' do
62
+ stub = stub_request(:put, /.*api.example.com\/customers\/CU123/)
63
+ .with(body: { given_name: 'Jack', family_name: 'Franklin' })
64
+ service.make_request(:put, '/customers/CU123', params: {
65
+ given_name: 'Jack',
66
+ family_name: 'Franklin'
67
+ })
70
68
  expect(stub).to have_been_requested
71
69
  end
72
70
  end
@@ -10,10 +10,10 @@ describe GoCardlessPro::Client do
10
10
  }
11
11
  end
12
12
 
13
- context "when initialised without an Access Token" do
13
+ context 'when initialised without an Access Token' do
14
14
  let(:environment) { :live }
15
15
  let(:token) { nil }
16
16
 
17
- it { is_expected.to raise_error("No Access Token given to GoCardless Client") }
17
+ it { is_expected.to raise_error('No Access Token given to GoCardless Client') }
18
18
  end
19
19
  end
@@ -5,40 +5,49 @@ describe GoCardlessPro::Error do
5
5
 
6
6
  let(:api_error) do
7
7
  {
8
- "documentation_url" => "https://developer.gocardless.com/pro#validation_failed",
9
- "message" => "Validation failed",
10
- "type" => "validation_failed",
11
- "code" => 422,
12
- "request_id" => "dd50eaaf-8213-48fe-90d6-5466872efbc4",
13
- "errors" => [
8
+ 'documentation_url' => 'https://developer.gocardless.com/pro#validation_failed',
9
+ 'message' => 'Validation failed',
10
+ 'type' => 'validation_failed',
11
+ 'code' => 422,
12
+ 'request_id' => 'dd50eaaf-8213-48fe-90d6-5466872efbc4',
13
+ 'errors' => [
14
14
  {
15
- "message" => "must be a number",
16
- "field" => "branch_code"
15
+ 'message' => 'must be a number',
16
+ 'field' => 'branch_code'
17
17
  }, {
18
- "message" => "is the wrong length (should be 8 characters)",
19
- "field" => "branch_code"
18
+ 'message' => 'is the wrong length (should be 8 characters)',
19
+ 'field' => 'branch_code'
20
20
  }
21
21
  ]
22
22
  }
23
23
  end
24
24
 
25
25
  specify do
26
- expect(error.documentation_url).to eq("https://developer.gocardless.com/pro#validation_failed")
26
+ expect(error.documentation_url).to eq('https://developer.gocardless.com/pro#validation_failed')
27
27
  end
28
28
 
29
- specify { expect(error.message).to eq("Validation failed") }
30
- specify { expect(error.type).to eq("validation_failed") }
29
+ specify { expect(error.message).to eq('Validation failed') }
30
+ specify do
31
+ expect(error.to_s)
32
+ .to eq('branch_code must be a number, '\
33
+ 'branch_code is the wrong length (should be 8 characters)')
34
+ end
35
+ specify { expect(error.type).to eq('validation_failed') }
31
36
  specify { expect(error.code).to eq(422) }
32
- specify { expect(error.request_id).to eq("dd50eaaf-8213-48fe-90d6-5466872efbc4") }
37
+ specify { expect(error.request_id).to eq('dd50eaaf-8213-48fe-90d6-5466872efbc4') }
33
38
  specify do
34
39
  expect(error.errors).to eq([
35
40
  {
36
- "message" => "must be a number",
37
- "field" => "branch_code"
41
+ 'message' => 'must be a number',
42
+ 'field' => 'branch_code'
38
43
  }, {
39
- "message" => "is the wrong length (should be 8 characters)",
40
- "field" => "branch_code"
44
+ 'message' => 'is the wrong length (should be 8 characters)',
45
+ 'field' => 'branch_code'
41
46
  }
42
47
  ])
43
48
  end
49
+
50
+ context 'when initializing an error with a string' do
51
+ specify { expect { described_class.new('FOO') }.to raise_error(ArgumentError) }
52
+ end
44
53
  end
@@ -1,51 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GoCardlessPro::Resources::BankDetailsLookup do
4
- describe "initialising" do
4
+ describe 'initialising' do
5
5
  let(:data) do
6
6
  {
7
-
8
-
9
- "available_debit_schemes" => "available_debit_schemes-input",
10
-
11
-
12
-
13
- "bank_name" => "bank_name-input",
14
-
15
-
16
-
17
- "bic" => "bic-input",
18
-
19
-
7
+
8
+ 'available_debit_schemes' => 'available_debit_schemes-input',
9
+
10
+ 'bank_name' => 'bank_name-input',
11
+
12
+ 'bic' => 'bic-input'
13
+
20
14
  }
21
15
  end
22
16
 
23
- it "can be initialized from an unenveloped response" do
17
+ it 'can be initialized from an unenveloped response' do
24
18
  resource = described_class.new(data)
25
-
26
-
27
- expect(resource.available_debit_schemes).to eq("available_debit_schemes-input")
28
-
29
-
30
-
31
- expect(resource.bank_name).to eq("bank_name-input")
32
-
33
-
34
-
35
- expect(resource.bic).to eq("bic-input")
36
-
37
-
19
+
20
+ expect(resource.available_debit_schemes).to eq('available_debit_schemes-input')
21
+
22
+ expect(resource.bank_name).to eq('bank_name-input')
23
+
24
+ expect(resource.bic).to eq('bic-input')
38
25
  end
39
26
 
40
- it "can handle new attributes without erroring" do
41
- data["foo"] = "bar"
27
+ it 'can handle new attributes without erroring' do
28
+ data['foo'] = 'bar'
42
29
  expect { described_class.new(data) }.to_not raise_error
43
30
  end
44
31
 
45
-
46
-
47
- describe "#to_h" do
48
- it "returns a hash representing the resource" do
32
+ describe '#to_h' do
33
+ it 'returns a hash representing the resource' do
49
34
  expect(described_class.new(data).to_h).to eq(data)
50
35
  end
51
36
  end
@@ -1,123 +1,78 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GoCardlessPro::Resources::CreditorBankAccount do
4
- describe "initialising" do
4
+ describe 'initialising' do
5
5
  let(:data) do
6
6
  {
7
-
8
-
9
- "account_holder_name" => "account_holder_name-input",
10
-
11
-
12
-
13
- "account_number_ending" => "account_number_ending-input",
14
-
15
-
16
-
17
- "bank_name" => "bank_name-input",
18
-
19
-
20
-
21
- "country_code" => "country_code-input",
22
-
23
-
24
-
25
- "created_at" => "created_at-input",
26
-
27
-
28
-
29
- "currency" => "currency-input",
30
-
31
-
32
-
33
- "enabled" => "enabled-input",
34
-
35
-
36
-
37
- "id" => "id-input",
38
-
39
-
40
-
41
- "links" => {
42
-
43
- "creditor" => "creditor-input",
44
-
7
+
8
+ 'account_holder_name' => 'account_holder_name-input',
9
+
10
+ 'account_number_ending' => 'account_number_ending-input',
11
+
12
+ 'bank_name' => 'bank_name-input',
13
+
14
+ 'country_code' => 'country_code-input',
15
+
16
+ 'created_at' => 'created_at-input',
17
+
18
+ 'currency' => 'currency-input',
19
+
20
+ 'enabled' => 'enabled-input',
21
+
22
+ 'id' => 'id-input',
23
+
24
+ 'links' => {
25
+
26
+ 'creditor' => 'creditor-input'
27
+
45
28
  },
46
-
47
-
48
-
49
- "metadata" => "metadata-input",
50
-
51
-
29
+
30
+ 'metadata' => 'metadata-input'
31
+
52
32
  }
53
33
  end
54
34
 
55
- it "can be initialized from an unenveloped response" do
35
+ it 'can be initialized from an unenveloped response' do
56
36
  resource = described_class.new(data)
57
-
58
-
59
- expect(resource.account_holder_name).to eq("account_holder_name-input")
60
-
61
-
62
-
63
- expect(resource.account_number_ending).to eq("account_number_ending-input")
64
-
65
-
66
-
67
- expect(resource.bank_name).to eq("bank_name-input")
68
-
69
-
70
-
71
- expect(resource.country_code).to eq("country_code-input")
72
-
73
-
74
-
75
- expect(resource.created_at).to eq("created_at-input")
76
-
77
-
78
-
79
- expect(resource.currency).to eq("currency-input")
80
-
81
-
82
-
83
- expect(resource.enabled).to eq("enabled-input")
84
-
85
-
86
-
87
- expect(resource.id).to eq("id-input")
88
-
89
-
90
-
91
-
92
- expect(resource.links.creditor).to eq("creditor-input")
93
-
94
-
95
-
96
-
97
- expect(resource.metadata).to eq("metadata-input")
98
-
99
-
37
+
38
+ expect(resource.account_holder_name).to eq('account_holder_name-input')
39
+
40
+ expect(resource.account_number_ending).to eq('account_number_ending-input')
41
+
42
+ expect(resource.bank_name).to eq('bank_name-input')
43
+
44
+ expect(resource.country_code).to eq('country_code-input')
45
+
46
+ expect(resource.created_at).to eq('created_at-input')
47
+
48
+ expect(resource.currency).to eq('currency-input')
49
+
50
+ expect(resource.enabled).to eq('enabled-input')
51
+
52
+ expect(resource.id).to eq('id-input')
53
+
54
+ expect(resource.links.creditor).to eq('creditor-input')
55
+
56
+ expect(resource.metadata).to eq('metadata-input')
100
57
  end
101
58
 
102
- it "can handle new attributes without erroring" do
103
- data["foo"] = "bar"
59
+ it 'can handle new attributes without erroring' do
60
+ data['foo'] = 'bar'
104
61
  expect { described_class.new(data) }.to_not raise_error
105
62
  end
106
63
 
107
-
108
- it "can handle new link attributes without erroring" do
109
- data["links"]["foo"] = "bar"
64
+ it 'can handle new link attributes without erroring' do
65
+ data['links']['foo'] = 'bar'
110
66
  expect { described_class.new(data) }.to_not raise_error
111
67
  end
112
68
 
113
- it "can handle a nil links value" do
114
- data["links"] = nil
69
+ it 'can handle a nil links value' do
70
+ data['links'] = nil
115
71
  expect { described_class.new(data).links }.to_not raise_error
116
72
  end
117
-
118
73
 
119
- describe "#to_h" do
120
- it "returns a hash representing the resource" do
74
+ describe '#to_h' do
75
+ it 'returns a hash representing the resource' do
121
76
  expect(described_class.new(data).to_h).to eq(data)
122
77
  end
123
78
  end
@@ -1,139 +1,90 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GoCardlessPro::Resources::Creditor do
4
- describe "initialising" do
4
+ describe 'initialising' do
5
5
  let(:data) do
6
6
  {
7
-
8
-
9
- "address_line1" => "address_line1-input",
10
-
11
-
12
-
13
- "address_line2" => "address_line2-input",
14
-
15
-
16
-
17
- "address_line3" => "address_line3-input",
18
-
19
-
20
-
21
- "city" => "city-input",
22
-
23
-
24
-
25
- "country_code" => "country_code-input",
26
-
27
-
28
-
29
- "created_at" => "created_at-input",
30
-
31
-
32
-
33
- "id" => "id-input",
34
-
35
-
36
-
37
- "links" => {
38
-
39
- "default_eur_payout_account" => "default_eur_payout_account-input",
40
-
41
- "default_gbp_payout_account" => "default_gbp_payout_account-input",
42
-
43
- "default_sek_payout_account" => "default_sek_payout_account-input",
44
-
7
+
8
+ 'address_line1' => 'address_line1-input',
9
+
10
+ 'address_line2' => 'address_line2-input',
11
+
12
+ 'address_line3' => 'address_line3-input',
13
+
14
+ 'city' => 'city-input',
15
+
16
+ 'country_code' => 'country_code-input',
17
+
18
+ 'created_at' => 'created_at-input',
19
+
20
+ 'id' => 'id-input',
21
+
22
+ 'links' => {
23
+
24
+ 'default_eur_payout_account' => 'default_eur_payout_account-input',
25
+
26
+ 'default_gbp_payout_account' => 'default_gbp_payout_account-input',
27
+
28
+ 'default_sek_payout_account' => 'default_sek_payout_account-input'
29
+
45
30
  },
46
-
47
-
48
-
49
- "name" => "name-input",
50
-
51
-
52
-
53
- "postal_code" => "postal_code-input",
54
-
55
-
56
-
57
- "region" => "region-input",
58
-
59
-
31
+
32
+ 'name' => 'name-input',
33
+
34
+ 'postal_code' => 'postal_code-input',
35
+
36
+ 'region' => 'region-input'
37
+
60
38
  }
61
39
  end
62
40
 
63
- it "can be initialized from an unenveloped response" do
41
+ it 'can be initialized from an unenveloped response' do
64
42
  resource = described_class.new(data)
65
-
66
-
67
- expect(resource.address_line1).to eq("address_line1-input")
68
-
69
-
70
-
71
- expect(resource.address_line2).to eq("address_line2-input")
72
-
73
-
74
-
75
- expect(resource.address_line3).to eq("address_line3-input")
76
-
77
-
78
-
79
- expect(resource.city).to eq("city-input")
80
-
81
-
82
-
83
- expect(resource.country_code).to eq("country_code-input")
84
-
85
-
86
-
87
- expect(resource.created_at).to eq("created_at-input")
88
-
89
-
90
-
91
- expect(resource.id).to eq("id-input")
92
-
93
-
94
-
95
-
96
- expect(resource.links.default_eur_payout_account).to eq("default_eur_payout_account-input")
97
-
98
- expect(resource.links.default_gbp_payout_account).to eq("default_gbp_payout_account-input")
99
-
100
- expect(resource.links.default_sek_payout_account).to eq("default_sek_payout_account-input")
101
-
102
-
103
-
104
-
105
- expect(resource.name).to eq("name-input")
106
-
107
-
108
-
109
- expect(resource.postal_code).to eq("postal_code-input")
110
-
111
-
112
-
113
- expect(resource.region).to eq("region-input")
114
-
115
-
43
+
44
+ expect(resource.address_line1).to eq('address_line1-input')
45
+
46
+ expect(resource.address_line2).to eq('address_line2-input')
47
+
48
+ expect(resource.address_line3).to eq('address_line3-input')
49
+
50
+ expect(resource.city).to eq('city-input')
51
+
52
+ expect(resource.country_code).to eq('country_code-input')
53
+
54
+ expect(resource.created_at).to eq('created_at-input')
55
+
56
+ expect(resource.id).to eq('id-input')
57
+
58
+ expect(resource.links.default_eur_payout_account).to eq('default_eur_payout_account-input')
59
+
60
+ expect(resource.links.default_gbp_payout_account).to eq('default_gbp_payout_account-input')
61
+
62
+ expect(resource.links.default_sek_payout_account).to eq('default_sek_payout_account-input')
63
+
64
+ expect(resource.name).to eq('name-input')
65
+
66
+ expect(resource.postal_code).to eq('postal_code-input')
67
+
68
+ expect(resource.region).to eq('region-input')
116
69
  end
117
70
 
118
- it "can handle new attributes without erroring" do
119
- data["foo"] = "bar"
71
+ it 'can handle new attributes without erroring' do
72
+ data['foo'] = 'bar'
120
73
  expect { described_class.new(data) }.to_not raise_error
121
74
  end
122
75
 
123
-
124
- it "can handle new link attributes without erroring" do
125
- data["links"]["foo"] = "bar"
76
+ it 'can handle new link attributes without erroring' do
77
+ data['links']['foo'] = 'bar'
126
78
  expect { described_class.new(data) }.to_not raise_error
127
79
  end
128
80
 
129
- it "can handle a nil links value" do
130
- data["links"] = nil
81
+ it 'can handle a nil links value' do
82
+ data['links'] = nil
131
83
  expect { described_class.new(data).links }.to_not raise_error
132
84
  end
133
-
134
85
 
135
- describe "#to_h" do
136
- it "returns a hash representing the resource" do
86
+ describe '#to_h' do
87
+ it 'returns a hash representing the resource' do
137
88
  expect(described_class.new(data).to_h).to eq(data)
138
89
  end
139
90
  end