gocardless_pro 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -29
  3. data/lib/gocardless_pro.rb +7 -3
  4. data/lib/gocardless_pro/api_response.rb +14 -0
  5. data/lib/gocardless_pro/client.rb +24 -12
  6. data/lib/gocardless_pro/list_response.rb +7 -3
  7. data/lib/gocardless_pro/request.rb +3 -11
  8. data/lib/gocardless_pro/resources/{helper.rb → bank_details_lookup.rb} +15 -4
  9. data/lib/gocardless_pro/resources/creditor.rb +14 -13
  10. data/lib/gocardless_pro/resources/creditor_bank_account.rb +14 -10
  11. data/lib/gocardless_pro/resources/customer.rb +8 -4
  12. data/lib/gocardless_pro/resources/customer_bank_account.rb +15 -13
  13. data/lib/gocardless_pro/resources/event.rb +6 -1
  14. data/lib/gocardless_pro/resources/mandate.rb +10 -7
  15. data/lib/gocardless_pro/resources/mandate_pdf.rb +42 -0
  16. data/lib/gocardless_pro/resources/payment.rb +12 -11
  17. data/lib/gocardless_pro/resources/payout.rb +9 -6
  18. data/lib/gocardless_pro/resources/redirect_flow.rb +24 -30
  19. data/lib/gocardless_pro/resources/refund.rb +15 -15
  20. data/lib/gocardless_pro/resources/subscription.rb +26 -22
  21. data/lib/gocardless_pro/response.rb +5 -0
  22. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +55 -0
  23. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +8 -9
  24. data/lib/gocardless_pro/services/creditors_service.rb +6 -7
  25. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +15 -18
  26. data/lib/gocardless_pro/services/customers_service.rb +6 -7
  27. data/lib/gocardless_pro/services/events_service.rb +4 -6
  28. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +63 -0
  29. data/lib/gocardless_pro/services/mandates_service.rb +12 -24
  30. data/lib/gocardless_pro/services/payments_service.rb +15 -16
  31. data/lib/gocardless_pro/services/payouts_service.rb +5 -6
  32. data/lib/gocardless_pro/services/redirect_flows_service.rb +13 -17
  33. data/lib/gocardless_pro/services/refunds_service.rb +16 -19
  34. data/lib/gocardless_pro/services/subscriptions_service.rb +10 -11
  35. data/lib/gocardless_pro/version.rb +1 -1
  36. data/spec/api_response_spec.rb +28 -0
  37. data/spec/resources/bank_details_lookup_spec.rb +39 -0
  38. data/spec/resources/creditor_spec.rb +0 -4
  39. data/spec/resources/{helper_spec.rb → mandate_pdf_spec.rb} +17 -1
  40. data/spec/resources/subscription_spec.rb +4 -4
  41. data/spec/services/bank_details_lookups_service_spec.rb +80 -0
  42. data/spec/services/creditor_bank_accounts_service_spec.rb +2 -0
  43. data/spec/services/creditors_service_spec.rb +2 -0
  44. data/spec/services/customer_bank_accounts_service_spec.rb +2 -0
  45. data/spec/services/customers_service_spec.rb +2 -0
  46. data/spec/services/events_service_spec.rb +2 -0
  47. data/spec/services/mandate_pdfs_service_spec.rb +80 -0
  48. data/spec/services/mandates_service_spec.rb +2 -0
  49. data/spec/services/payments_service_spec.rb +2 -0
  50. data/spec/services/payouts_service_spec.rb +2 -0
  51. data/spec/services/refunds_service_spec.rb +2 -0
  52. data/spec/services/subscriptions_service_spec.rb +26 -24
  53. metadata +17 -8
  54. data/lib/gocardless_pro/services/helpers_service.rb +0 -99
  55. data/spec/services/helpers_service_spec.rb +0 -122
@@ -14,9 +14,9 @@ module GoCardlessPro
14
14
  #
15
15
  # This
16
16
  # fails with a `mandate_is_inactive` error if the linked
17
- # [mandate](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-mandates)
18
- # is cancelled. Payments can be created against `pending_submission` mandates,
19
- # but they will not be submitted until the mandate becomes active.
17
+ # [mandate](#core-endpoints-mandates) is cancelled. Payments can be created
18
+ # against `pending_submission` mandates, but they will not be submitted until
19
+ # the mandate becomes active.
20
20
  # Example URL: /payments
21
21
  # @param options [Hash] parameters as a hash, under a params key.
22
22
  def create(options = {})
@@ -28,12 +28,11 @@ module GoCardlessPro
28
28
  response = make_request(:post, path, options)
29
29
 
30
30
  return if response.body.nil?
31
- Resources::Payment.new(unenvelope_body(response.body))
31
+ Resources::Payment.new(unenvelope_body(response.body), response)
32
32
  end
33
33
 
34
- # Returns a
35
- # [cursor-paginated](https://developer.gocardless.com/pro/2015-04-29/#overview-cursor-pagination)
36
- # list of your payments.
34
+ # Returns a [cursor-paginated](#overview-cursor-pagination) list of your
35
+ # payments.
37
36
  # Example URL: /payments
38
37
  # @param options [Hash] parameters as a hash, under a params key.
39
38
  def list(options = {})
@@ -41,7 +40,7 @@ module GoCardlessPro
41
40
 
42
41
  response = make_request(:get, path, options)
43
42
  ListResponse.new(
44
- raw_response: response,
43
+ response: response,
45
44
  unenveloped_body: unenvelope_body(response.body),
46
45
  resource_class: Resources::Payment
47
46
  )
@@ -63,7 +62,7 @@ module GoCardlessPro
63
62
  # Retrieves the details of a single existing payment.
64
63
  # Example URL: /payments/:identity
65
64
  #
66
- # @param identity # Unique identifier, beginning with "PM"
65
+ # @param identity # Unique identifier, beginning with "PM".
67
66
  # @param options [Hash] parameters as a hash, under a params key.
68
67
  def get(identity, options = {})
69
68
  path = sub_url('/payments/:identity', 'identity' => identity)
@@ -71,13 +70,13 @@ module GoCardlessPro
71
70
  response = make_request(:get, path, options)
72
71
 
73
72
  return if response.body.nil?
74
- Resources::Payment.new(unenvelope_body(response.body))
73
+ Resources::Payment.new(unenvelope_body(response.body), response)
75
74
  end
76
75
 
77
76
  # Updates a payment object. This accepts only the metadata parameter.
78
77
  # Example URL: /payments/:identity
79
78
  #
80
- # @param identity # Unique identifier, beginning with "PM"
79
+ # @param identity # Unique identifier, beginning with "PM".
81
80
  # @param options [Hash] parameters as a hash, under a params key.
82
81
  def update(identity, options = {})
83
82
  path = sub_url('/payments/:identity', 'identity' => identity)
@@ -88,7 +87,7 @@ module GoCardlessPro
88
87
  response = make_request(:put, path, options)
89
88
 
90
89
  return if response.body.nil?
91
- Resources::Payment.new(unenvelope_body(response.body))
90
+ Resources::Payment.new(unenvelope_body(response.body), response)
92
91
  end
93
92
 
94
93
  # Cancels the payment if it has not already been submitted to the banks. Any
@@ -99,7 +98,7 @@ module GoCardlessPro
99
98
  # the payment's status is `pending_submission`.
100
99
  # Example URL: /payments/:identity/actions/cancel
101
100
  #
102
- # @param identity # Unique identifier, beginning with "PM"
101
+ # @param identity # Unique identifier, beginning with "PM".
103
102
  # @param options [Hash] parameters as a hash, under a params key.
104
103
  def cancel(identity, options = {})
105
104
  path = sub_url('/payments/:identity/actions/cancel', 'identity' => identity)
@@ -110,7 +109,7 @@ module GoCardlessPro
110
109
  response = make_request(:post, path, options)
111
110
 
112
111
  return if response.body.nil?
113
- Resources::Payment.new(unenvelope_body(response.body))
112
+ Resources::Payment.new(unenvelope_body(response.body), response)
114
113
  end
115
114
 
116
115
  # <a name="retry_failed"></a>Retries a failed payment if the underlying mandate
@@ -127,7 +126,7 @@ module GoCardlessPro
127
126
  # times.
128
127
  # Example URL: /payments/:identity/actions/retry
129
128
  #
130
- # @param identity # Unique identifier, beginning with "PM"
129
+ # @param identity # Unique identifier, beginning with "PM".
131
130
  # @param options [Hash] parameters as a hash, under a params key.
132
131
  def retry(identity, options = {})
133
132
  path = sub_url('/payments/:identity/actions/retry', 'identity' => identity)
@@ -138,7 +137,7 @@ module GoCardlessPro
138
137
  response = make_request(:post, path, options)
139
138
 
140
139
  return if response.body.nil?
141
- Resources::Payment.new(unenvelope_body(response.body))
140
+ Resources::Payment.new(unenvelope_body(response.body), response)
142
141
  end
143
142
 
144
143
  # Unenvelope the response of the body using the service's `envelope_key`
@@ -10,9 +10,8 @@ module GoCardlessPro
10
10
  module Services
11
11
  # Service for making requests to the Payout endpoints
12
12
  class PayoutsService < BaseService
13
- # Returns a
14
- # [cursor-paginated](https://developer.gocardless.com/pro/2015-04-29/#overview-cursor-pagination)
15
- # list of your payouts.
13
+ # Returns a [cursor-paginated](#overview-cursor-pagination) list of your
14
+ # payouts.
16
15
  # Example URL: /payouts
17
16
  # @param options [Hash] parameters as a hash, under a params key.
18
17
  def list(options = {})
@@ -20,7 +19,7 @@ module GoCardlessPro
20
19
 
21
20
  response = make_request(:get, path, options)
22
21
  ListResponse.new(
23
- raw_response: response,
22
+ response: response,
24
23
  unenveloped_body: unenvelope_body(response.body),
25
24
  resource_class: Resources::Payout
26
25
  )
@@ -44,7 +43,7 @@ module GoCardlessPro
44
43
  # guide](#events-fetching-events-for-a-payout).
45
44
  # Example URL: /payouts/:identity
46
45
  #
47
- # @param identity # Unique identifier, beginning with "PO"
46
+ # @param identity # Unique identifier, beginning with "PO".
48
47
  # @param options [Hash] parameters as a hash, under a params key.
49
48
  def get(identity, options = {})
50
49
  path = sub_url('/payouts/:identity', 'identity' => identity)
@@ -52,7 +51,7 @@ module GoCardlessPro
52
51
  response = make_request(:get, path, options)
53
52
 
54
53
  return if response.body.nil?
55
- Resources::Payout.new(unenvelope_body(response.body))
54
+ Resources::Payout.new(unenvelope_body(response.body), response)
56
55
  end
57
56
 
58
57
  # Unenvelope the response of the body using the service's `envelope_key`
@@ -23,7 +23,7 @@ module GoCardlessPro
23
23
  response = make_request(:post, path, options)
24
24
 
25
25
  return if response.body.nil?
26
- Resources::RedirectFlow.new(unenvelope_body(response.body))
26
+ Resources::RedirectFlow.new(unenvelope_body(response.body), response)
27
27
  end
28
28
 
29
29
  # Returns all details about a single redirect flow
@@ -37,24 +37,20 @@ module GoCardlessPro
37
37
  response = make_request(:get, path, options)
38
38
 
39
39
  return if response.body.nil?
40
- Resources::RedirectFlow.new(unenvelope_body(response.body))
40
+ Resources::RedirectFlow.new(unenvelope_body(response.body), response)
41
41
  end
42
42
 
43
- # This creates a
44
- # [customer](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customers),
45
- # [customer bank
46
- # account](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customer-bank-accounts),
47
- # and
48
- # [mandate](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-mandates)
49
- # using the details supplied by your customer and returns the ID of the created
50
- # mandate.
43
+ # This creates a [customer](#core-endpoints-customers), [customer bank
44
+ # account](#core-endpoints-customer-bank-accounts), and
45
+ # [mandate](#core-endpoints-mandates) using the details supplied by your
46
+ # customer and returns the ID of the created mandate.
51
47
  #
52
- # This will return a `redirect_flow_incomplete` error if your
53
- # customer has not yet been redirected back to your site, and a
54
- # `redirect_flow_already_completed` error if your integration has already
55
- # completed this flow. It will return a `bad_request` error if the
56
- # `session_token` differs to the one supplied when the redirect flow was
57
- # created.
48
+ # This will return a
49
+ # `redirect_flow_incomplete` error if your customer has not yet been redirected
50
+ # back to your site, and a `redirect_flow_already_completed` error if your
51
+ # integration has already completed this flow. It will return a `bad_request`
52
+ # error if the `session_token` differs to the one supplied when the redirect
53
+ # flow was created.
58
54
  # Example URL: /redirect_flows/:identity/actions/complete
59
55
  #
60
56
  # @param identity # Unique identifier, beginning with "RE".
@@ -68,7 +64,7 @@ module GoCardlessPro
68
64
  response = make_request(:post, path, options)
69
65
 
70
66
  return if response.body.nil?
71
- Resources::RedirectFlow.new(unenvelope_body(response.body))
67
+ Resources::RedirectFlow.new(unenvelope_body(response.body), response)
72
68
  end
73
69
 
74
70
  # Unenvelope the response of the body using the service's `envelope_key`
@@ -18,18 +18,16 @@ module GoCardlessPro
18
18
  # name="number_of_refunds_exceeded"></a>
19
19
  #
20
20
  # - `refund_payment_invalid_state`
21
- # error if the linked
22
- # [payment](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-payments)
23
- # isn't either `confirmed` or `paid_out`.
21
+ # error if the linked [payment](#core-endpoints-payments) isn't either
22
+ # `confirmed` or `paid_out`.
24
23
  #
25
- # -
26
- # `total_amount_confirmation_invalid` if the confirmation amount doesn't match
27
- # the total amount refunded for the payment. This safeguard is there to prevent
28
- # two processes from creating refunds without awareness of each other.
24
+ # - `total_amount_confirmation_invalid` if the
25
+ # confirmation amount doesn't match the total amount refunded for the payment.
26
+ # This safeguard is there to prevent two processes from creating refunds without
27
+ # awareness of each other.
29
28
  #
30
- # -
31
- # `number_of_refunds_exceeded` if five or more refunds have already been created
32
- # against the payment.
29
+ # - `number_of_refunds_exceeded` if five or more
30
+ # refunds have already been created against the payment.
33
31
  #
34
32
  # Example URL: /refunds
35
33
  # @param options [Hash] parameters as a hash, under a params key.
@@ -42,12 +40,11 @@ module GoCardlessPro
42
40
  response = make_request(:post, path, options)
43
41
 
44
42
  return if response.body.nil?
45
- Resources::Refund.new(unenvelope_body(response.body))
43
+ Resources::Refund.new(unenvelope_body(response.body), response)
46
44
  end
47
45
 
48
- # Returns a
49
- # [cursor-paginated](https://developer.gocardless.com/pro/2015-04-29/#overview-cursor-pagination)
50
- # list of your refunds.
46
+ # Returns a [cursor-paginated](#overview-cursor-pagination) list of your
47
+ # refunds.
51
48
  # Example URL: /refunds
52
49
  # @param options [Hash] parameters as a hash, under a params key.
53
50
  def list(options = {})
@@ -55,7 +52,7 @@ module GoCardlessPro
55
52
 
56
53
  response = make_request(:get, path, options)
57
54
  ListResponse.new(
58
- raw_response: response,
55
+ response: response,
59
56
  unenveloped_body: unenvelope_body(response.body),
60
57
  resource_class: Resources::Refund
61
58
  )
@@ -77,7 +74,7 @@ module GoCardlessPro
77
74
  # Retrieves all details for a single refund
78
75
  # Example URL: /refunds/:identity
79
76
  #
80
- # @param identity # Unique identifier, beginning with "RF"
77
+ # @param identity # Unique identifier, beginning with "RF".
81
78
  # @param options [Hash] parameters as a hash, under a params key.
82
79
  def get(identity, options = {})
83
80
  path = sub_url('/refunds/:identity', 'identity' => identity)
@@ -85,13 +82,13 @@ module GoCardlessPro
85
82
  response = make_request(:get, path, options)
86
83
 
87
84
  return if response.body.nil?
88
- Resources::Refund.new(unenvelope_body(response.body))
85
+ Resources::Refund.new(unenvelope_body(response.body), response)
89
86
  end
90
87
 
91
88
  # Updates a refund object.
92
89
  # Example URL: /refunds/:identity
93
90
  #
94
- # @param identity # Unique identifier, beginning with "RF"
91
+ # @param identity # Unique identifier, beginning with "RF".
95
92
  # @param options [Hash] parameters as a hash, under a params key.
96
93
  def update(identity, options = {})
97
94
  path = sub_url('/refunds/:identity', 'identity' => identity)
@@ -102,7 +99,7 @@ module GoCardlessPro
102
99
  response = make_request(:put, path, options)
103
100
 
104
101
  return if response.body.nil?
105
- Resources::Refund.new(unenvelope_body(response.body))
102
+ Resources::Refund.new(unenvelope_body(response.body), response)
106
103
  end
107
104
 
108
105
  # Unenvelope the response of the body using the service's `envelope_key`
@@ -22,12 +22,11 @@ module GoCardlessPro
22
22
  response = make_request(:post, path, options)
23
23
 
24
24
  return if response.body.nil?
25
- Resources::Subscription.new(unenvelope_body(response.body))
25
+ Resources::Subscription.new(unenvelope_body(response.body), response)
26
26
  end
27
27
 
28
- # Returns a
29
- # [cursor-paginated](https://developer.gocardless.com/pro/2015-04-29/#overview-cursor-pagination)
30
- # list of your subscriptions.
28
+ # Returns a [cursor-paginated](#overview-cursor-pagination) list of your
29
+ # subscriptions.
31
30
  # Example URL: /subscriptions
32
31
  # @param options [Hash] parameters as a hash, under a params key.
33
32
  def list(options = {})
@@ -35,7 +34,7 @@ module GoCardlessPro
35
34
 
36
35
  response = make_request(:get, path, options)
37
36
  ListResponse.new(
38
- raw_response: response,
37
+ response: response,
39
38
  unenveloped_body: unenvelope_body(response.body),
40
39
  resource_class: Resources::Subscription
41
40
  )
@@ -57,7 +56,7 @@ module GoCardlessPro
57
56
  # Retrieves the details of a single subscription.
58
57
  # Example URL: /subscriptions/:identity
59
58
  #
60
- # @param identity # Unique identifier, beginning with "SB"
59
+ # @param identity # Unique identifier, beginning with "SB".
61
60
  # @param options [Hash] parameters as a hash, under a params key.
62
61
  def get(identity, options = {})
63
62
  path = sub_url('/subscriptions/:identity', 'identity' => identity)
@@ -65,13 +64,13 @@ module GoCardlessPro
65
64
  response = make_request(:get, path, options)
66
65
 
67
66
  return if response.body.nil?
68
- Resources::Subscription.new(unenvelope_body(response.body))
67
+ Resources::Subscription.new(unenvelope_body(response.body), response)
69
68
  end
70
69
 
71
70
  # Updates a subscription object.
72
71
  # Example URL: /subscriptions/:identity
73
72
  #
74
- # @param identity # Unique identifier, beginning with "SB"
73
+ # @param identity # Unique identifier, beginning with "SB".
75
74
  # @param options [Hash] parameters as a hash, under a params key.
76
75
  def update(identity, options = {})
77
76
  path = sub_url('/subscriptions/:identity', 'identity' => identity)
@@ -82,7 +81,7 @@ module GoCardlessPro
82
81
  response = make_request(:put, path, options)
83
82
 
84
83
  return if response.body.nil?
85
- Resources::Subscription.new(unenvelope_body(response.body))
84
+ Resources::Subscription.new(unenvelope_body(response.body), response)
86
85
  end
87
86
 
88
87
  # Immediately cancels a subscription; no more payments will be created under it.
@@ -93,7 +92,7 @@ module GoCardlessPro
93
92
  # error if the subscription is already cancelled or finished.
94
93
  # Example URL: /subscriptions/:identity/actions/cancel
95
94
  #
96
- # @param identity # Unique identifier, beginning with "SB"
95
+ # @param identity # Unique identifier, beginning with "SB".
97
96
  # @param options [Hash] parameters as a hash, under a params key.
98
97
  def cancel(identity, options = {})
99
98
  path = sub_url('/subscriptions/:identity/actions/cancel', 'identity' => identity)
@@ -104,7 +103,7 @@ module GoCardlessPro
104
103
  response = make_request(:post, path, options)
105
104
 
106
105
  return if response.body.nil?
107
- Resources::Subscription.new(unenvelope_body(response.body))
106
+ Resources::Subscription.new(unenvelope_body(response.body), response)
108
107
  end
109
108
 
110
109
  # Unenvelope the response of the body using the service's `envelope_key`
@@ -4,5 +4,5 @@ end
4
4
 
5
5
  module GoCardlessPro
6
6
  # Current version of the GC gem
7
- VERSION = '0.3.0'
7
+ VERSION = '1.0.0'
8
8
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe GoCardlessPro::ApiResponse do
5
+ describe "wrapping a Faraday response" do
6
+ let(:content_type) { 'application/json' }
7
+
8
+ let(:stubbed) do
9
+ Faraday::Adapter::Test::Stubs.new do |stub|
10
+ stub.get('/testing') do |env|
11
+ [200, { 'Content-Type' => content_type}, { test: true }.to_json]
12
+ end
13
+ end
14
+ end
15
+ let(:test) { Faraday.new { |builder| builder.adapter :test, stubbed } }
16
+ subject(:api_response) do
17
+ described_class.new(
18
+ GoCardlessPro::Response.new(test.get('/testing'))
19
+ )
20
+ end
21
+
22
+ specify { expect(api_response.status_code).to eql(200) }
23
+ specify do
24
+ expect(api_response.headers).to eql('Content-Type' => content_type)
25
+ end
26
+ specify { expect(api_response.body).to eql("test" => true) }
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::BankDetailsLookup do
4
+ describe "initialising" do
5
+ let(:data) do
6
+ {
7
+
8
+
9
+ "available_debit_schemes" => "available_debit_schemes-input",
10
+
11
+
12
+
13
+ "bank_name" => "bank_name-input",
14
+
15
+
16
+ }
17
+ end
18
+
19
+ it "can be initialized from an uneveloped response" do
20
+ resource = described_class.new(data)
21
+
22
+
23
+ expect(resource.available_debit_schemes).to eq("available_debit_schemes-input")
24
+
25
+
26
+
27
+ expect(resource.bank_name).to eq("bank_name-input")
28
+
29
+
30
+ end
31
+
32
+ describe "#to_h" do
33
+ it "returns a hash representing the resource" do
34
+ expect(described_class.new(data).to_h).to eq(data)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
@@ -40,8 +40,6 @@ describe GoCardlessPro::Resources::Creditor do
40
40
 
41
41
  "default_gbp_payout_account" => "default_gbp_payout_account-input",
42
42
 
43
- "logo" => "logo-input",
44
-
45
43
  },
46
44
 
47
45
 
@@ -97,8 +95,6 @@ describe GoCardlessPro::Resources::Creditor do
97
95
 
98
96
  expect(resource.links.default_gbp_payout_account).to eq("default_gbp_payout_account-input")
99
97
 
100
- expect(resource.links.logo).to eq("logo-input")
101
-
102
98
 
103
99
 
104
100