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,51 @@
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 GoCardless
12
+ # A module containing classes for each of the resources in the GC Api
13
+ module Resources
14
+ # Publishable API keys are designed to be used by the [js
15
+ # flow](https://developer.gocardless.com/pro/#api-endpoints-customer-bank-account-tokens).
16
+ # You should generate a key and then use it to make requests to the API. They
17
+ # do not expire, but can be disabled.
18
+ #
19
+ # Publishable API keys only have
20
+ # permissions to create [customer bank account
21
+ # tokens](https://developer.gocardless.com/pro/#api-endpoints-customer-bank-account-tokens).
22
+ # Represents an instance of a publishable_api_key resource returned from the API
23
+ class PublishableApiKey
24
+ attr_reader :created_at
25
+
26
+ attr_reader :enabled
27
+
28
+ attr_reader :id
29
+
30
+ attr_reader :key
31
+
32
+ attr_reader :name
33
+ # initialize a resource instance
34
+ # @param object [Hash] an object returned from the API
35
+ def initialize(object)
36
+ @object = object
37
+
38
+ @created_at = object['created_at']
39
+ @enabled = object['enabled']
40
+ @id = object['id']
41
+ @key = object['key']
42
+ @name = object['name']
43
+ end
44
+
45
+ # Provides the resource as a hash of all it's readable attributes
46
+ def to_h
47
+ @object
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,104 @@
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 GoCardless
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/#create-a-redirect-flow) a
22
+ # redirect flow for your customer, and redirect them to the returned redirect
23
+ # url, e.g. `https://pay.gocardless.com/flow/RE123`.
24
+ #
25
+ # 2. Your customer
26
+ # supplies their name, email, address, and bank account details, and submits
27
+ # the form. This securely stores their details, and redirects them back to
28
+ # your `success_redirect_url` with `redirect_flow_id=RE123` in the
29
+ # querystring.
30
+ #
31
+ # 3. You
32
+ # [complete](https://developer.gocardless.com/pro/#complete-a-redirect-flow)
33
+ # the redirect flow, which creates a
34
+ # [customer](https://developer.gocardless.com/pro/#api-endpoints-customers),
35
+ # [customer bank
36
+ # account](https://developer.gocardless.com/pro/#api-endpoints-customer-bank-accounts),
37
+ # and [mandate](https://developer.gocardless.com/pro/#api-endpoints-mandates),
38
+ # and returns the ID of the mandate. You may wish to create a
39
+ # [subscription](https://developer.gocardless.com/pro/#api-endpoints-subscriptions)
40
+ # or [payment](https://developer.gocardless.com/pro/#api-endpoints-payments)
41
+ # at this point.
42
+ #
43
+ # It is recommended that you link the redirect flow to
44
+ # your user object as soon as it is created, and attach the created resources
45
+ # to that user in the complete step.
46
+ #
47
+ # Redirect flows expire 30 minutes
48
+ # after they are first created. You cannot
49
+ # [complete](https://developer.gocardless.com/pro/#complete-a-redirect-flow)
50
+ # an expired redirect flow.
51
+ #
52
+ # [View an example
53
+ # integration](https://pay-sandbox.gocardless.com/AL000000AKFPFF) that uses
54
+ # redirect flows.
55
+ # Represents an instance of a redirect_flow resource returned from the API
56
+ class RedirectFlow
57
+ attr_reader :created_at
58
+
59
+ attr_reader :description
60
+
61
+ attr_reader :id
62
+
63
+ attr_reader :redirect_url
64
+
65
+ attr_reader :scheme
66
+
67
+ attr_reader :session_token
68
+
69
+ attr_reader :success_redirect_url
70
+ # initialize a resource instance
71
+ # @param object [Hash] an object returned from the API
72
+ def initialize(object)
73
+ @object = object
74
+
75
+ @created_at = object['created_at']
76
+ @description = object['description']
77
+ @id = object['id']
78
+ @links = object['links']
79
+ @redirect_url = object['redirect_url']
80
+ @scheme = object['scheme']
81
+ @session_token = object['session_token']
82
+ @success_redirect_url = object['success_redirect_url']
83
+ end
84
+
85
+ # return the links that the resource has
86
+ def links
87
+ Struct.new(
88
+ *{
89
+
90
+ creditor: '',
91
+
92
+ mandate: ''
93
+
94
+ }.keys.sort
95
+ ).new(*@links.sort.map(&:last))
96
+ end
97
+
98
+ # Provides the resource as a hash of all it's readable attributes
99
+ def to_h
100
+ @object
101
+ end
102
+ end
103
+ end
104
+ 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 GoCardless
12
+ # A module containing classes for each of the resources in the GC Api
13
+ module Resources
14
+ # Refund objects represent (partial) refunds of a
15
+ # [payment](https://developer.gocardless.com/pro/#api-endpoints-payment) back
16
+ # to the
17
+ # [customer](https://developer.gocardless.com/pro/#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/#webhooks) whenever a refund
25
+ # is created.
26
+ #
27
+ # _Note:_ A payment that has been (partially) refunded
28
+ # can still receive a late failure or chargeback from the banks.
29
+ # Represents an instance of a refund resource returned from the API
30
+ class Refund
31
+ attr_reader :amount
32
+
33
+ attr_reader :created_at
34
+
35
+ attr_reader :currency
36
+
37
+ attr_reader :id
38
+
39
+ attr_reader :metadata
40
+ # initialize a resource instance
41
+ # @param object [Hash] an object returned from the API
42
+ def initialize(object)
43
+ @object = object
44
+
45
+ @amount = object['amount']
46
+ @created_at = object['created_at']
47
+ @currency = object['currency']
48
+ @id = object['id']
49
+ @links = object['links']
50
+ @metadata = object['metadata']
51
+ end
52
+
53
+ # return the links that the resource has
54
+ def links
55
+ Struct.new(
56
+ *{
57
+
58
+ payment: ''
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,101 @@
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 GoCardless
12
+ # A module containing classes for each of the resources in the GC Api
13
+ module Resources
14
+ # <a name="insufficient_permissions"></a>Roles represent a set of permissions
15
+ # that may be granted to a user. The permissions are specified at the
16
+ # resource-type level, and can be `full_access` or `read_only`. If a
17
+ # resource-type is not included that role's users will have no access to
18
+ # resources of that type, and will receive an `insufficient_permissions` error
19
+ # when trying to use those endpoints.
20
+ #
21
+ # A role's `permissions`
22
+ # attribute is used to set/show the permissions for a role and it's key/value
23
+ # pairs are restricted to the below:
24
+ #
25
+ # <dl>
26
+ #
27
+ # <dt><p><code>resource</code></p></dt>
28
+ # <dd><p>One of:</p>
29
+ # <ul>
30
+
31
+ # # <li><code>customers</code></li>
32
+ #
33
+ # <li><code>customer_bank_accounts</code></li>
34
+ #
35
+ # <li><code>mandates</code></li>
36
+ # <li><code>payments</code></li>
37
+ #
38
+ # <li><code>payouts</code></li>
39
+ #
40
+ # <li><code>creditors</code></li>
41
+ #
42
+ # <li><code>creditor_bank_accounts</code></li>
43
+ #
44
+ # <li><code>roles</code></li>
45
+ # <li><code>users</code></li>
46
+ #
47
+ # <li><code>events</code></li>
48
+ # <li><code>api_keys</code></li>
49
+ #
50
+ # <li><code>subscriptions</code></li>
51
+ #
52
+ # <li><code>redirect_flows</code></li>
53
+ # </ul>
54
+ # </dd>
55
+ # </dl>
56
+ #
57
+ #
58
+ # <dl>
59
+ # <dt><p><code>access</code></p></dt>
60
+ # <dd><p>One
61
+ # of:</p>
62
+ # <ul>
63
+ # <li><code>full_access</code>: read and write
64
+ # all records of this type</li>
65
+ # <li><code>read_only</code>: list and
66
+ # show endpoints available, but not create, update, delete, or actions</li>
67
+
68
+ # # </ul>
69
+ # </dd>
70
+ # </dl>
71
+ #
72
+ # Represents an instance of a role resource returned from the API
73
+ class Role
74
+ attr_reader :created_at
75
+
76
+ attr_reader :enabled
77
+
78
+ attr_reader :id
79
+
80
+ attr_reader :name
81
+
82
+ attr_reader :permissions
83
+ # initialize a resource instance
84
+ # @param object [Hash] an object returned from the API
85
+ def initialize(object)
86
+ @object = object
87
+
88
+ @created_at = object['created_at']
89
+ @enabled = object['enabled']
90
+ @id = object['id']
91
+ @name = object['name']
92
+ @permissions = object['permissions']
93
+ end
94
+
95
+ # Provides the resource as a hash of all it's readable attributes
96
+ def to_h
97
+ @object
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,152 @@
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 GoCardless
12
+ # A module containing classes for each of the resources in the GC Api
13
+ module Resources
14
+ # Subscriptions create
15
+ # [payments](https://developer.gocardless.com/pro/#api-endpoints-payments)
16
+ # according to a schedule.
17
+ #
18
+ # #### Recurrence Rules
19
+ #
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:
30
+ #
31
+ # | interval_unit | month
32
+ # | day_of_month |
33
+ # |
34
+ # :-------------- | :--------------------------------------------- |
35
+ # :-------------------------------------- |
36
+ # | yearly | optional
37
+ # (required if `day_of_month` provided) | optional (required if `month`
38
+ # provided) |
39
+ # | monthly | invalid
40
+ # | required |
41
+ # | weekly |
42
+ # invalid | invalid
43
+ # |
44
+ #
45
+ # Examples:
46
+ #
47
+ # | interval_unit | interval |
48
+ # month | day_of_month | valid?
49
+ # |
50
+ # | :-------------- | :--------- | :------ | :------------- |
51
+ # :------------------------------------------------- |
52
+ # | yearly |
53
+ # 1 | january | -1 | valid
54
+ # |
55
+ # | yearly | 1 | march |
56
+ # | invalid - missing `day_of_month` |
57
+ # | monthly
58
+ # | 6 | | 12 | valid
59
+ # |
60
+ # | monthly | 6 | august | 12
61
+ # | invalid - `month` must be blank |
62
+ # | weekly
63
+ # | 2 | | | valid
64
+ # |
65
+ # | weekly | 2 | october | 10
66
+ # | invalid - `month` and `day_of_month` must be blank |
67
+ #
68
+ # ####
69
+ # Rolling dates
70
+ #
71
+ # When a charge date falls on a non-business day, one
72
+ # of two things will happen:
73
+ #
74
+ # - if the recurrence rule specified `-1`
75
+ # as the `day_of_month`, the charge date will be rolled __backwards__ to the
76
+ # previous business day (i.e., the last working day of the month).
77
+ # -
78
+ # otherwise the charge date will be rolled __forwards__ to the next business
79
+ # day.
80
+ #
81
+ # Represents an instance of a subscription resource returned from the API
82
+ class Subscription
83
+ attr_reader :amount
84
+
85
+ attr_reader :count
86
+
87
+ attr_reader :created_at
88
+
89
+ attr_reader :currency
90
+
91
+ attr_reader :day_of_month
92
+
93
+ attr_reader :end_at
94
+
95
+ attr_reader :id
96
+
97
+ attr_reader :interval
98
+
99
+ attr_reader :interval_unit
100
+
101
+ attr_reader :metadata
102
+
103
+ attr_reader :month
104
+
105
+ attr_reader :name
106
+
107
+ attr_reader :start_at
108
+
109
+ attr_reader :status
110
+
111
+ attr_reader :upcoming_payments
112
+ # initialize a resource instance
113
+ # @param object [Hash] an object returned from the API
114
+ def initialize(object)
115
+ @object = object
116
+
117
+ @amount = object['amount']
118
+ @count = object['count']
119
+ @created_at = object['created_at']
120
+ @currency = object['currency']
121
+ @day_of_month = object['day_of_month']
122
+ @end_at = object['end_at']
123
+ @id = object['id']
124
+ @interval = object['interval']
125
+ @interval_unit = object['interval_unit']
126
+ @links = object['links']
127
+ @metadata = object['metadata']
128
+ @month = object['month']
129
+ @name = object['name']
130
+ @start_at = object['start_at']
131
+ @status = object['status']
132
+ @upcoming_payments = object['upcoming_payments']
133
+ end
134
+
135
+ # return the links that the resource has
136
+ def links
137
+ Struct.new(
138
+ *{
139
+
140
+ mandate: ''
141
+
142
+ }.keys.sort
143
+ ).new(*@links.sort.map(&:last))
144
+ end
145
+
146
+ # Provides the resource as a hash of all it's readable attributes
147
+ def to_h
148
+ @object
149
+ end
150
+ end
151
+ end
152
+ end