gocardless_pro 0.3.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 (76) 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 +146 -0
  6. data/circle.yml +3 -0
  7. data/demo.rb +9 -0
  8. data/gocardless_pro.gemspec +26 -0
  9. data/lib/gocardless_pro.rb +73 -0
  10. data/lib/gocardless_pro/api_service.rb +58 -0
  11. data/lib/gocardless_pro/client.rb +135 -0
  12. data/lib/gocardless_pro/error.rb +42 -0
  13. data/lib/gocardless_pro/error/gocardless_error.rb +5 -0
  14. data/lib/gocardless_pro/error/invalid_api_usage_error.rb +5 -0
  15. data/lib/gocardless_pro/error/invalid_state_error.rb +5 -0
  16. data/lib/gocardless_pro/error/validation_error.rb +5 -0
  17. data/lib/gocardless_pro/list_response.rb +29 -0
  18. data/lib/gocardless_pro/paginator.rb +43 -0
  19. data/lib/gocardless_pro/request.rb +69 -0
  20. data/lib/gocardless_pro/resources/creditor.rb +84 -0
  21. data/lib/gocardless_pro/resources/creditor_bank_account.rb +78 -0
  22. data/lib/gocardless_pro/resources/customer.rb +75 -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 +87 -0
  28. data/lib/gocardless_pro/resources/payout.rb +66 -0
  29. data/lib/gocardless_pro/resources/redirect_flow.rb +106 -0
  30. data/lib/gocardless_pro/resources/refund.rb +71 -0
  31. data/lib/gocardless_pro/resources/subscription.rb +155 -0
  32. data/lib/gocardless_pro/response.rb +77 -0
  33. data/lib/gocardless_pro/services/base_service.rb +28 -0
  34. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +119 -0
  35. data/lib/gocardless_pro/services/creditors_service.rb +113 -0
  36. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +154 -0
  37. data/lib/gocardless_pro/services/customers_service.rb +113 -0
  38. data/lib/gocardless_pro/services/events_service.rb +80 -0
  39. data/lib/gocardless_pro/services/helpers_service.rb +99 -0
  40. data/lib/gocardless_pro/services/mandates_service.rb +173 -0
  41. data/lib/gocardless_pro/services/payments_service.rb +168 -0
  42. data/lib/gocardless_pro/services/payouts_service.rb +82 -0
  43. data/lib/gocardless_pro/services/redirect_flows_service.rb +98 -0
  44. data/lib/gocardless_pro/services/refunds_service.rb +132 -0
  45. data/lib/gocardless_pro/services/subscriptions_service.rb +134 -0
  46. data/lib/gocardless_pro/version.rb +8 -0
  47. data/spec/api_service_spec.rb +73 -0
  48. data/spec/client_spec.rb +19 -0
  49. data/spec/error_spec.rb +44 -0
  50. data/spec/resources/creditor_bank_account_spec.rb +109 -0
  51. data/spec/resources/creditor_spec.rb +125 -0
  52. data/spec/resources/customer_bank_account_spec.rb +109 -0
  53. data/spec/resources/customer_spec.rb +135 -0
  54. data/spec/resources/event_spec.rb +113 -0
  55. data/spec/resources/helper_spec.rb +23 -0
  56. data/spec/resources/mandate_spec.rb +97 -0
  57. data/spec/resources/payment_spec.rb +129 -0
  58. data/spec/resources/payout_spec.rb +89 -0
  59. data/spec/resources/redirect_flow_spec.rb +97 -0
  60. data/spec/resources/refund_spec.rb +77 -0
  61. data/spec/resources/subscription_spec.rb +165 -0
  62. data/spec/response_spec.rb +89 -0
  63. data/spec/services/creditor_bank_accounts_service_spec.rb +413 -0
  64. data/spec/services/creditors_service_spec.rb +388 -0
  65. data/spec/services/customer_bank_accounts_service_spec.rb +452 -0
  66. data/spec/services/customers_service_spec.rb +429 -0
  67. data/spec/services/events_service_spec.rb +217 -0
  68. data/spec/services/helpers_service_spec.rb +122 -0
  69. data/spec/services/mandates_service_spec.rb +495 -0
  70. data/spec/services/payments_service_spec.rb +546 -0
  71. data/spec/services/payouts_service_spec.rb +217 -0
  72. data/spec/services/redirect_flows_service_spec.rb +254 -0
  73. data/spec/services/refunds_service_spec.rb +323 -0
  74. data/spec/services/subscriptions_service_spec.rb +557 -0
  75. data/spec/spec_helper.rb +91 -0
  76. metadata +224 -0
@@ -0,0 +1,80 @@
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
+ # Customer Bank Accounts hold the bank details of a
15
+ # [customer](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customers).
16
+ # They always belong to a
17
+ # [customer](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-customers),
18
+ # and may be linked to several Direct Debit
19
+ # [mandates](https://developer.gocardless.com/pro/2015-04-29/#api-endpoints-mandates).
20
+
21
+ # #
22
+ # Note that customer bank accounts must be unique, and so you will
23
+ # encounter a `bank_account_exists` error if you try to create a duplicate
24
+ # bank account. You may wish to handle this by updating the existing record
25
+ # instead, the ID of which will be provided as links[customer_bank_account] in
26
+ # the error response.
27
+ # Represents an instance of a customer_bank_account resource returned from the API
28
+ class CustomerBankAccount
29
+ attr_reader :account_holder_name
30
+
31
+ attr_reader :account_number_ending
32
+
33
+ attr_reader :bank_name
34
+
35
+ attr_reader :country_code
36
+
37
+ attr_reader :created_at
38
+
39
+ attr_reader :currency
40
+
41
+ attr_reader :enabled
42
+
43
+ attr_reader :id
44
+
45
+ attr_reader :metadata
46
+ # initialize a resource instance
47
+ # @param object [Hash] an object returned from the API
48
+ def initialize(object)
49
+ @object = object
50
+
51
+ @account_holder_name = object['account_holder_name']
52
+ @account_number_ending = object['account_number_ending']
53
+ @bank_name = object['bank_name']
54
+ @country_code = object['country_code']
55
+ @created_at = object['created_at']
56
+ @currency = object['currency']
57
+ @enabled = object['enabled']
58
+ @id = object['id']
59
+ @links = object['links']
60
+ @metadata = object['metadata']
61
+ end
62
+
63
+ # return the links that the resource has
64
+ def links
65
+ Struct.new(
66
+ *{
67
+
68
+ customer: ''
69
+
70
+ }.keys.sort
71
+ ).new(*@links.sort.map(&:last))
72
+ end
73
+
74
+ # Provides the resource as a hash of all it's readable attributes
75
+ def to_h
76
+ @object
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,75 @@
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
+ # Events are stored for all webhooks. An event refers to a resource which has
15
+ # been updated, for example a payment which has been collected, or a mandate
16
+ # which has been transferred.
17
+ # Represents an instance of a event resource returned from the API
18
+ class Event
19
+ attr_reader :action
20
+
21
+ attr_reader :created_at
22
+
23
+ attr_reader :details
24
+
25
+ attr_reader :id
26
+
27
+ attr_reader :metadata
28
+
29
+ attr_reader :resource_type
30
+ # initialize a resource instance
31
+ # @param object [Hash] an object returned from the API
32
+ def initialize(object)
33
+ @object = object
34
+
35
+ @action = object['action']
36
+ @created_at = object['created_at']
37
+ @details = object['details']
38
+ @id = object['id']
39
+ @links = object['links']
40
+ @metadata = object['metadata']
41
+ @resource_type = object['resource_type']
42
+ end
43
+
44
+ # return the links that the resource has
45
+ def links
46
+ Struct.new(
47
+ *{
48
+
49
+ mandate: '',
50
+
51
+ new_customer_bank_account: '',
52
+
53
+ parent_event: '',
54
+
55
+ payment: '',
56
+
57
+ payout: '',
58
+
59
+ previous_customer_bank_account: '',
60
+
61
+ refund: '',
62
+
63
+ subscription: ''
64
+
65
+ }.keys.sort
66
+ ).new(*@links.sort.map(&:last))
67
+ end
68
+
69
+ # Provides the resource as a hash of all it's readable attributes
70
+ def to_h
71
+ @object
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,29 @@
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
+ #
15
+ # Represents an instance of a helper resource returned from the API
16
+ class Helper
17
+ # initialize a resource instance
18
+ # @param object [Hash] an object returned from the API
19
+ def initialize(object)
20
+ @object = object
21
+ end
22
+
23
+ # Provides the resource as a hash of all it's readable attributes
24
+ def to_h
25
+ @object
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,70 @@
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
+ # 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.
21
+ # Represents an instance of a mandate resource returned from the API
22
+ class Mandate
23
+ attr_reader :created_at
24
+
25
+ attr_reader :id
26
+
27
+ attr_reader :metadata
28
+
29
+ attr_reader :next_possible_charge_date
30
+
31
+ attr_reader :reference
32
+
33
+ attr_reader :scheme
34
+
35
+ attr_reader :status
36
+ # initialize a resource instance
37
+ # @param object [Hash] an object returned from the API
38
+ def initialize(object)
39
+ @object = object
40
+
41
+ @created_at = object['created_at']
42
+ @id = object['id']
43
+ @links = object['links']
44
+ @metadata = object['metadata']
45
+ @next_possible_charge_date = object['next_possible_charge_date']
46
+ @reference = object['reference']
47
+ @scheme = object['scheme']
48
+ @status = object['status']
49
+ end
50
+
51
+ # return the links that the resource has
52
+ def links
53
+ Struct.new(
54
+ *{
55
+
56
+ creditor: '',
57
+
58
+ customer_bank_account: ''
59
+
60
+ }.keys.sort
61
+ ).new(*@links.sort.map(&:last))
62
+ end
63
+
64
+ # Provides the resource as a hash of all it's readable attributes
65
+ def to_h
66
+ @object
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,87 @@
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
+ # 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.
25
+ # Represents an instance of a payment resource returned from the API
26
+ class Payment
27
+ attr_reader :amount
28
+
29
+ attr_reader :amount_refunded
30
+
31
+ attr_reader :charge_date
32
+
33
+ attr_reader :created_at
34
+
35
+ attr_reader :currency
36
+
37
+ attr_reader :description
38
+
39
+ attr_reader :id
40
+
41
+ attr_reader :metadata
42
+
43
+ attr_reader :reference
44
+
45
+ attr_reader :status
46
+ # initialize a resource instance
47
+ # @param object [Hash] an object returned from the API
48
+ def initialize(object)
49
+ @object = object
50
+
51
+ @amount = object['amount']
52
+ @amount_refunded = object['amount_refunded']
53
+ @charge_date = object['charge_date']
54
+ @created_at = object['created_at']
55
+ @currency = object['currency']
56
+ @description = object['description']
57
+ @id = object['id']
58
+ @links = object['links']
59
+ @metadata = object['metadata']
60
+ @reference = object['reference']
61
+ @status = object['status']
62
+ end
63
+
64
+ # return the links that the resource has
65
+ def links
66
+ Struct.new(
67
+ *{
68
+
69
+ creditor: '',
70
+
71
+ mandate: '',
72
+
73
+ payout: '',
74
+
75
+ subscription: ''
76
+
77
+ }.keys.sort
78
+ ).new(*@links.sort.map(&:last))
79
+ end
80
+
81
+ # Provides the resource as a hash of all it's readable attributes
82
+ def to_h
83
+ @object
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,66 @@
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
+ # 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.
20
+ # Represents an instance of a payout resource returned from the API
21
+ class Payout
22
+ attr_reader :amount
23
+
24
+ attr_reader :created_at
25
+
26
+ attr_reader :currency
27
+
28
+ attr_reader :id
29
+
30
+ attr_reader :reference
31
+
32
+ attr_reader :status
33
+ # initialize a resource instance
34
+ # @param object [Hash] an object returned from the API
35
+ def initialize(object)
36
+ @object = object
37
+
38
+ @amount = object['amount']
39
+ @created_at = object['created_at']
40
+ @currency = object['currency']
41
+ @id = object['id']
42
+ @links = object['links']
43
+ @reference = object['reference']
44
+ @status = object['status']
45
+ end
46
+
47
+ # return the links that the resource has
48
+ def links
49
+ Struct.new(
50
+ *{
51
+
52
+ creditor: '',
53
+
54
+ creditor_bank_account: ''
55
+
56
+ }.keys.sort
57
+ ).new(*@links.sort.map(&:last))
58
+ end
59
+
60
+ # Provides the resource as a hash of all it's readable attributes
61
+ def to_h
62
+ @object
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,106 @@
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
+ # Redirect flows enable you to use GoCardless Pro's secure payment pages to
15
+ # set up mandates with your customers.
16
+ #
17
+ # The overall flow is:
18
+ #
19
+ #
20
+ # 1. You
21
+ # [create](https://developer.gocardless.com/pro/2015-04-29/#create-a-redirect-flow)
22
+ # a redirect flow for your customer, and redirect them to the returned
23
+ # redirect url, e.g. `https://pay.gocardless.com/flow/RE123`.
24
+ #
25
+ # 2. Your
26
+ # customer supplies their name, email, address, and bank account details, and
27
+ # submits the form. This securely stores their details, and redirects them
28
+ # back to your `success_redirect_url` with `redirect_flow_id=RE123` in the
29
+ # querystring.
30
+ #
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.
48
+ #
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.
53
+ #
54
+ # [View an example
55
+ # integration](https://pay-sandbox.gocardless.com/AL000000AKFPFF) that uses
56
+ # redirect flows.
57
+ # Represents an instance of a redirect_flow resource returned from the API
58
+ class RedirectFlow
59
+ attr_reader :created_at
60
+
61
+ attr_reader :description
62
+
63
+ attr_reader :id
64
+
65
+ attr_reader :redirect_url
66
+
67
+ attr_reader :scheme
68
+
69
+ attr_reader :session_token
70
+
71
+ attr_reader :success_redirect_url
72
+ # initialize a resource instance
73
+ # @param object [Hash] an object returned from the API
74
+ def initialize(object)
75
+ @object = object
76
+
77
+ @created_at = object['created_at']
78
+ @description = object['description']
79
+ @id = object['id']
80
+ @links = object['links']
81
+ @redirect_url = object['redirect_url']
82
+ @scheme = object['scheme']
83
+ @session_token = object['session_token']
84
+ @success_redirect_url = object['success_redirect_url']
85
+ end
86
+
87
+ # return the links that the resource has
88
+ def links
89
+ Struct.new(
90
+ *{
91
+
92
+ creditor: '',
93
+
94
+ mandate: ''
95
+
96
+ }.keys.sort
97
+ ).new(*@links.sort.map(&:last))
98
+ end
99
+
100
+ # Provides the resource as a hash of all it's readable attributes
101
+ def to_h
102
+ @object
103
+ end
104
+ end
105
+ end
106
+ end