gocardless_pro 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -29,7 +29,7 @@ module GoCardlessPro
29
29
  attr_reader :resource_type
30
30
  # initialize a resource instance
31
31
  # @param object [Hash] an object returned from the API
32
- def initialize(object)
32
+ def initialize(object, response = nil)
33
33
  @object = object
34
34
 
35
35
  @action = object['action']
@@ -39,6 +39,11 @@ module GoCardlessPro
39
39
  @links = object['links']
40
40
  @metadata = object['metadata']
41
41
  @resource_type = object['resource_type']
42
+ @response = response
43
+ end
44
+
45
+ def api_response
46
+ ApiResponse.new(@response)
42
47
  end
43
48
 
44
49
  # return the links that the resource has
@@ -12,12 +12,10 @@ module GoCardlessPro
12
12
  # A module containing classes for each of the resources in the GC Api
13
13
  module Resources
14
14
  # Mandates represent the Direct Debit mandate with a
15
- # [customer](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customers).
16
-
17
- # #
18
- # GoCardless will notify you via a
19
- # [webhook](https://developer.gocardless.com/pro/2015-04-29/#webhooks)
20
- # whenever the status of a mandate changes.
15
+ # [customer](#core-endpoints-customers).
16
+ #
17
+ # GoCardless will notify you
18
+ # via a [webhook](#webhooks) whenever the status of a mandate changes.
21
19
  # Represents an instance of a mandate resource returned from the API
22
20
  class Mandate
23
21
  attr_reader :created_at
@@ -35,7 +33,7 @@ module GoCardlessPro
35
33
  attr_reader :status
36
34
  # initialize a resource instance
37
35
  # @param object [Hash] an object returned from the API
38
- def initialize(object)
36
+ def initialize(object, response = nil)
39
37
  @object = object
40
38
 
41
39
  @created_at = object['created_at']
@@ -46,6 +44,11 @@ module GoCardlessPro
46
44
  @reference = object['reference']
47
45
  @scheme = object['scheme']
48
46
  @status = object['status']
47
+ @response = response
48
+ end
49
+
50
+ def api_response
51
+ ApiResponse.new(@response)
49
52
  end
50
53
 
51
54
  # return the links that the resource has
@@ -0,0 +1,42 @@
1
+
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
+ require 'uri'
10
+
11
+ module GoCardlessPro
12
+ # A module containing classes for each of the resources in the GC Api
13
+ module Resources
14
+ # Mandate PDFs allow you to easily display [scheme-rules
15
+ # compliant](#ui-compliance-requirements) Direct Debit mandates to your
16
+ # customers.
17
+ # Represents an instance of a mandate_pdf resource returned from the API
18
+ class MandatePdf
19
+ attr_reader :expires_at
20
+
21
+ attr_reader :url
22
+ # initialize a resource instance
23
+ # @param object [Hash] an object returned from the API
24
+ def initialize(object, response = nil)
25
+ @object = object
26
+
27
+ @expires_at = object['expires_at']
28
+ @url = object['url']
29
+ @response = response
30
+ end
31
+
32
+ def api_response
33
+ ApiResponse.new(@response)
34
+ end
35
+
36
+ # Provides the resource as a hash of all it's readable attributes
37
+ def to_h
38
+ @object
39
+ end
40
+ end
41
+ end
42
+ end
@@ -12,16 +12,12 @@ module GoCardlessPro
12
12
  # A module containing classes for each of the resources in the GC Api
13
13
  module Resources
14
14
  # Payment objects represent payments from a
15
- # [customer](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customers)
16
- # to a
17
- # [creditor](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-creditors),
18
- # taken against a Direct Debit
19
- # [mandate](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-mandates).
20
-
21
- # #
22
- # GoCardless will notify you via a
23
- # [webhook](https://developer.gocardless.com/pro/2015-04-29/#webhooks)
24
- # whenever the state of a payment changes.
15
+ # [customer](#core-endpoints-customers) to a
16
+ # [creditor](#core-endpoints-creditors), taken against a Direct Debit
17
+ # [mandate](#core-endpoints-mandates).
18
+ #
19
+ # GoCardless will notify you via
20
+ # a [webhook](#webhooks) whenever the state of a payment changes.
25
21
  # Represents an instance of a payment resource returned from the API
26
22
  class Payment
27
23
  attr_reader :amount
@@ -45,7 +41,7 @@ module GoCardlessPro
45
41
  attr_reader :status
46
42
  # initialize a resource instance
47
43
  # @param object [Hash] an object returned from the API
48
- def initialize(object)
44
+ def initialize(object, response = nil)
49
45
  @object = object
50
46
 
51
47
  @amount = object['amount']
@@ -59,6 +55,11 @@ module GoCardlessPro
59
55
  @metadata = object['metadata']
60
56
  @reference = object['reference']
61
57
  @status = object['status']
58
+ @response = response
59
+ end
60
+
61
+ def api_response
62
+ ApiResponse.new(@response)
62
63
  end
63
64
 
64
65
  # return the links that the resource has
@@ -12,11 +12,9 @@ module GoCardlessPro
12
12
  # A module containing classes for each of the resources in the GC Api
13
13
  module Resources
14
14
  # Payouts represent transfers from GoCardless to a
15
- # [creditor](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-creditors).
16
- # Each payout contains the funds collected from one or many
17
- # [payments](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-payments).
18
- # Payouts are created automatically after a payment has been successfully
19
- # collected.
15
+ # [creditor](#core-endpoints-creditors). Each payout contains the funds
16
+ # collected from one or many [payments](#core-endpoints-payments). Payouts are
17
+ # created automatically after a payment has been successfully collected.
20
18
  # Represents an instance of a payout resource returned from the API
21
19
  class Payout
22
20
  attr_reader :amount
@@ -32,7 +30,7 @@ module GoCardlessPro
32
30
  attr_reader :status
33
31
  # initialize a resource instance
34
32
  # @param object [Hash] an object returned from the API
35
- def initialize(object)
33
+ def initialize(object, response = nil)
36
34
  @object = object
37
35
 
38
36
  @amount = object['amount']
@@ -42,6 +40,11 @@ module GoCardlessPro
42
40
  @links = object['links']
43
41
  @reference = object['reference']
44
42
  @status = object['status']
43
+ @response = response
44
+ end
45
+
46
+ def api_response
47
+ ApiResponse.new(@response)
45
48
  end
46
49
 
47
50
  # return the links that the resource has
@@ -11,14 +11,15 @@ require 'uri'
11
11
  module GoCardlessPro
12
12
  # A module containing classes for each of the resources in the GC Api
13
13
  module Resources
14
- # Redirect flows enable you to use GoCardless Pro's secure payment pages to
15
- # set up mandates with your customers.
14
+ # Redirect flows enable you to use GoCardless Pro's [hosted payment
15
+ # pages](https://pay-sandbox.gocardless.com/AL000000AKFPFF) to set up mandates
16
+ # with your customers. These pages are fully compliant and have been
17
+ # translated into Dutch, French, German, Italian, Portuguese and Spanish.
16
18
  #
17
- # The overall flow is:
18
19
  #
20
+ # The overall flow is:
19
21
  #
20
- # 1. You
21
- # [create](https://developer.gocardless.com/pro/2015-04-29/#create-a-redirect-flow)
22
+ # 1. You [create](#create-a-redirect-flow)
22
23
  # a redirect flow for your customer, and redirect them to the returned
23
24
  # redirect url, e.g. `https://pay.gocardless.com/flow/RE123`.
24
25
  #
@@ -28,32 +29,20 @@ module GoCardlessPro
28
29
  # back to your `success_redirect_url` with `redirect_flow_id=RE123` in the
29
30
  # querystring.
30
31
  #
31
- # 3. You
32
- # [complete](https://developer.gocardless.com/pro/2015-04-29/#complete-a-redirect-flow)
33
- # the redirect flow, which creates a
34
- # [customer](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customers),
35
- # [customer bank
36
- # account](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customer-bank-accounts),
37
- # and
38
- # [mandate](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-mandates),
39
- # and returns the ID of the mandate. You may wish to create a
40
- # [subscription](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-subscriptions)
41
- # or
42
- # [payment](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-payments)
43
- # at this point.
44
- #
45
- # It is recommended that you link the redirect flow to
46
- # your user object as soon as it is created, and attach the created resources
47
- # to that user in the complete step.
32
+ # 3. You [complete](#complete-a-redirect-flow) the
33
+ # redirect flow, which creates a [customer](#core-endpoints-customers),
34
+ # [customer bank account](#core-endpoints-customer-bank-accounts), and
35
+ # [mandate](#core-endpoints-mandates), and returns the ID of the mandate. You
36
+ # may wish to create a [subscription](#core-endpoints-subscriptions) or
37
+ # [payment](#core-endpoints-payments) at this point.
48
38
  #
49
- # Redirect flows expire 30 minutes
50
- # after they are first created. You cannot
51
- # [complete](https://developer.gocardless.com/pro/2015-04-29/#complete-a-redirect-flow)
52
- # an expired redirect flow.
39
+ # It is
40
+ # recommended that you link the redirect flow to your user object as soon as
41
+ # it is created, and attach the created resources to that user in the complete
42
+ # step.
53
43
  #
54
- # [View an example
55
- # integration](https://pay-sandbox.gocardless.com/AL000000AKFPFF) that uses
56
- # redirect flows.
44
+ # Redirect flows expire 30 minutes after they are first
45
+ # created. You cannot complete an expired redirect flow.
57
46
  # Represents an instance of a redirect_flow resource returned from the API
58
47
  class RedirectFlow
59
48
  attr_reader :created_at
@@ -71,7 +60,7 @@ module GoCardlessPro
71
60
  attr_reader :success_redirect_url
72
61
  # initialize a resource instance
73
62
  # @param object [Hash] an object returned from the API
74
- def initialize(object)
63
+ def initialize(object, response = nil)
75
64
  @object = object
76
65
 
77
66
  @created_at = object['created_at']
@@ -82,6 +71,11 @@ module GoCardlessPro
82
71
  @scheme = object['scheme']
83
72
  @session_token = object['session_token']
84
73
  @success_redirect_url = object['success_redirect_url']
74
+ @response = response
75
+ end
76
+
77
+ def api_response
78
+ ApiResponse.new(@response)
85
79
  end
86
80
 
87
81
  # return the links that the resource has
@@ -12,21 +12,16 @@ module GoCardlessPro
12
12
  # A module containing classes for each of the resources in the GC Api
13
13
  module Resources
14
14
  # Refund objects represent (partial) refunds of a
15
- # [payment](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-payment)
16
- # back to the
17
- # [customer](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customers).
18
-
19
- # #
20
- # The API allows you to create, show, list and update your refunds.
21
-
22
- # #
23
- # GoCardless will notify you via a
24
- # [webhook](https://developer.gocardless.com/pro/2015-04-29/#webhooks)
25
- # whenever a refund is created, and will update the `amount_refunded` property
26
- # of the payment.
15
+ # [payment](#core-endpoints-payment) back to the
16
+ # [customer](#core-endpoints-customers).
17
+ #
18
+ # GoCardless will notify you
19
+ # via a [webhook](#webhooks) whenever a refund is created, and will update the
20
+ # `amount_refunded` property of the payment.
27
21
  #
28
- # _Note:_ A payment that has been (partially)
29
- # refunded can still receive a late failure or chargeback from the banks.
22
+ # _Note:_ A payment that
23
+ # has been (partially) refunded can still receive a late failure or chargeback
24
+ # from the banks.
30
25
  # Represents an instance of a refund resource returned from the API
31
26
  class Refund
32
27
  attr_reader :amount
@@ -40,7 +35,7 @@ module GoCardlessPro
40
35
  attr_reader :metadata
41
36
  # initialize a resource instance
42
37
  # @param object [Hash] an object returned from the API
43
- def initialize(object)
38
+ def initialize(object, response = nil)
44
39
  @object = object
45
40
 
46
41
  @amount = object['amount']
@@ -49,6 +44,11 @@ module GoCardlessPro
49
44
  @id = object['id']
50
45
  @links = object['links']
51
46
  @metadata = object['metadata']
47
+ @response = response
48
+ end
49
+
50
+ def api_response
51
+ ApiResponse.new(@response)
52
52
  end
53
53
 
54
54
  # return the links that the resource has
@@ -11,27 +11,26 @@ require 'uri'
11
11
  module GoCardlessPro
12
12
  # A module containing classes for each of the resources in the GC Api
13
13
  module Resources
14
- # Subscriptions create
15
- # [payments](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-payments)
16
- # according to a schedule.
14
+ # Subscriptions create [payments](#core-endpoints-payments) according to a
15
+ # schedule.
17
16
  #
18
17
  # #### Recurrence Rules
19
18
  #
20
- # The
21
- # following rules apply when specifying recurrence:
22
- # - The first payment
23
- # must be charged within 1 year.
24
- # - When neither `month` nor `day_of_month`
25
- # are present, the subscription will recur from the `start_at` based on the
26
- # `interval_unit`.
27
- # - If `month` or `day_of_month` are present, the
28
- # recurrence rules will be applied from the `start_at`, and the following
29
- # validations apply:
19
+ # The following rules apply
20
+ # when specifying recurrence:
21
+ # - The first payment must be charged within 1
22
+ # year.
23
+ # - When neither `month` nor `day_of_month` are present, the
24
+ # subscription will recur from the `start_date` based on the `interval_unit`.
25
+
26
+ # # - If `month` or `day_of_month` are present, the recurrence rules will be
27
+ # applied from the `start_date`, and the following validations apply:
30
28
  #
31
- # | interval_unit | month
32
- # | day_of_month |
33
- # |
34
- # :-------------- | :--------------------------------------------- |
29
+ #
30
+ # | interval_unit | month |
31
+ # day_of_month |
32
+ # | :-------------- |
33
+ # :--------------------------------------------- |
35
34
  # :-------------------------------------- |
36
35
  # | yearly | optional
37
36
  # (required if `day_of_month` provided) | optional (required if `month`
@@ -90,7 +89,7 @@ module GoCardlessPro
90
89
 
91
90
  attr_reader :day_of_month
92
91
 
93
- attr_reader :end_at
92
+ attr_reader :end_date
94
93
 
95
94
  attr_reader :id
96
95
 
@@ -106,14 +105,14 @@ module GoCardlessPro
106
105
 
107
106
  attr_reader :payment_reference
108
107
 
109
- attr_reader :start_at
108
+ attr_reader :start_date
110
109
 
111
110
  attr_reader :status
112
111
 
113
112
  attr_reader :upcoming_payments
114
113
  # initialize a resource instance
115
114
  # @param object [Hash] an object returned from the API
116
- def initialize(object)
115
+ def initialize(object, response = nil)
117
116
  @object = object
118
117
 
119
118
  @amount = object['amount']
@@ -121,7 +120,7 @@ module GoCardlessPro
121
120
  @created_at = object['created_at']
122
121
  @currency = object['currency']
123
122
  @day_of_month = object['day_of_month']
124
- @end_at = object['end_at']
123
+ @end_date = object['end_date']
125
124
  @id = object['id']
126
125
  @interval = object['interval']
127
126
  @interval_unit = object['interval_unit']
@@ -130,9 +129,14 @@ module GoCardlessPro
130
129
  @month = object['month']
131
130
  @name = object['name']
132
131
  @payment_reference = object['payment_reference']
133
- @start_at = object['start_at']
132
+ @start_date = object['start_date']
134
133
  @status = object['status']
135
134
  @upcoming_payments = object['upcoming_payments']
135
+ @response = response
136
+ end
137
+
138
+ def api_response
139
+ ApiResponse.new(@response)
136
140
  end
137
141
 
138
142
  # return the links that the resource has
@@ -1,6 +1,11 @@
1
1
  module GoCardlessPro
2
2
  # A class to wrap an API response
3
3
  class Response
4
+ extend Forwardable
5
+
6
+ def_delegator :@response, :headers
7
+ def_delegator :@response, :status, :status_code
8
+
4
9
  # Initialize a response instance
5
10
  # @param response an API response
6
11
  def initialize(response)
@@ -0,0 +1,55 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the BankDetailsLookup endpoints
12
+ class BankDetailsLookupsService < BaseService
13
+ # Performs a bank details lookup.
14
+ #
15
+ # Bank account details may be supplied
16
+ # using [local details](#appendix-local-bank-details) or an IBAN.
17
+ # Example URL: /bank_details_lookups
18
+ # @param options [Hash] parameters as a hash, under a params key.
19
+ def create(options = {})
20
+ path = '/bank_details_lookups'
21
+
22
+ params = options.delete(:params) || {}
23
+ options[:params] = {}
24
+ options[:params][envelope_key] = params
25
+ response = make_request(:post, path, options)
26
+
27
+ return if response.body.nil?
28
+ Resources::BankDetailsLookup.new(unenvelope_body(response.body), response)
29
+ end
30
+
31
+ # Unenvelope the response of the body using the service's `envelope_key`
32
+ #
33
+ # @param body [Hash]
34
+ def unenvelope_body(body)
35
+ body[envelope_key] || body['data']
36
+ end
37
+
38
+ private
39
+
40
+ # return the key which API responses will envelope data under
41
+ def envelope_key
42
+ 'bank_details_lookups'
43
+ end
44
+
45
+ # take a URL with placeholder params and substitute them out for the acutal value
46
+ # @param url [String] the URL with placeholders in
47
+ # @param param_map [Hash] a hash of placeholders and their actual values
48
+ def sub_url(url, param_map)
49
+ param_map.reduce(url) do |new_url, (param, value)|
50
+ new_url.gsub(":#{param}", value)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end