processout 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +10 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/deploy.sh +25 -0
  12. data/lib/processout.rb +130 -0
  13. data/lib/processout/activity.rb +147 -0
  14. data/lib/processout/authorization_request.rb +248 -0
  15. data/lib/processout/card.rb +156 -0
  16. data/lib/processout/coupon.rb +284 -0
  17. data/lib/processout/customer.rb +418 -0
  18. data/lib/processout/customer_action.rb +50 -0
  19. data/lib/processout/discount.rb +217 -0
  20. data/lib/processout/errors/authentication_error.rb +7 -0
  21. data/lib/processout/errors/generic_error.rb +7 -0
  22. data/lib/processout/errors/internal_error.rb +7 -0
  23. data/lib/processout/errors/notfound_error.rb +7 -0
  24. data/lib/processout/errors/validation_error.rb +7 -0
  25. data/lib/processout/event.rb +176 -0
  26. data/lib/processout/gateway.rb +104 -0
  27. data/lib/processout/gateway_configuration.rb +91 -0
  28. data/lib/processout/invoice.rb +457 -0
  29. data/lib/processout/networking/request.rb +95 -0
  30. data/lib/processout/networking/response.rb +61 -0
  31. data/lib/processout/plan.rb +280 -0
  32. data/lib/processout/product.rb +313 -0
  33. data/lib/processout/project.rb +105 -0
  34. data/lib/processout/refund.rb +161 -0
  35. data/lib/processout/subscription.rb +633 -0
  36. data/lib/processout/token.rb +167 -0
  37. data/lib/processout/transaction.rb +302 -0
  38. data/lib/processout/version.rb +3 -0
  39. data/lib/processout/webhook.rb +154 -0
  40. data/processout.gemspec +26 -0
  41. metadata +125 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 887cc0f26e551363337e7ab95d17dfd5033ac841
4
+ data.tar.gz: 53fbdf4f56a200cca2acb58536d728252987358b
5
+ SHA512:
6
+ metadata.gz: 775a5b1507364616d04051b7705a76c2b3ac4aabd31371187689f6d213e81cd061b38c6c6d61220762f3b966e6fbb0a6e5e65ed776007a6de8a193e42b86f9d7
7
+ data.tar.gz: c71fb1bc3674f0c0fbf02eca4c887e931d950708513329e80b9eaa446c9cc9dd703c683a1bc4c570c53a8d2361e288abe81bb8bb4b683a0c8a82cbc7b6c8660d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in processout.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 ProcessOut
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+ ProcessOut Ruby
2
+ ==============
3
+
4
+ This package provides bindings to the ProcessOut API.
5
+
6
+ Dependencies
7
+ ------------
8
+
9
+ * Ruby >= 1.9.0
10
+ * json >= 1.0
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "processout"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ #! /bin/sh
2
+
3
+ echo " > Moving away generated library"
4
+ rm -rf ../.tmp
5
+ mkdir ../.tmp
6
+ mv {*,.[!.]*} ../.tmp/
7
+ echo " > Initializing git repository"
8
+ git init
9
+ git remote add origin git@github.com:processout/processout-ruby.git
10
+ echo " > Pulling from repository"
11
+ git fetch
12
+ git pull origin master
13
+ echo " > Removing everything from previous versions"
14
+ git rm -rf .
15
+ echo " > Adding back our new library"
16
+ mv ../.tmp/{*,.[!.]*} .
17
+ rm -rf ../tmp
18
+ echo " > Committing new library"
19
+ git add -A
20
+ git commit -m "$COMMITMESSAGE"
21
+ git tag -f "0.2.0"
22
+ echo " > Publishing the new version to github"
23
+ git push origin master --tags
24
+
25
+ echo " >> Done!"
@@ -0,0 +1,130 @@
1
+ require "processout/version"
2
+ require "processout/activity"
3
+ require "processout/authorization_request"
4
+ require "processout/card"
5
+ require "processout/coupon"
6
+ require "processout/customer"
7
+ require "processout/token"
8
+ require "processout/discount"
9
+ require "processout/event"
10
+ require "processout/gateway"
11
+ require "processout/gateway_configuration"
12
+ require "processout/invoice"
13
+ require "processout/customer_action"
14
+ require "processout/plan"
15
+ require "processout/product"
16
+ require "processout/project"
17
+ require "processout/refund"
18
+ require "processout/subscription"
19
+ require "processout/transaction"
20
+ require "processout/webhook"
21
+
22
+ module ProcessOut
23
+ class Client
24
+ attr_reader :host, :project_id, :project_secret
25
+
26
+ def initialize(project_id, project_secret)
27
+ @host = "https://api.processout.com"
28
+
29
+ @project_id = project_id
30
+ @project_secret = project_secret
31
+ end
32
+
33
+ # Create a new Activity instance
34
+ def new_activity()
35
+ Activity.new(self)
36
+ end
37
+
38
+ # Create a new AuthorizationRequest instance
39
+ def new_authorization_request()
40
+ AuthorizationRequest.new(self)
41
+ end
42
+
43
+ # Create a new Card instance
44
+ def new_card()
45
+ Card.new(self)
46
+ end
47
+
48
+ # Create a new Coupon instance
49
+ def new_coupon()
50
+ Coupon.new(self)
51
+ end
52
+
53
+ # Create a new Customer instance
54
+ def new_customer()
55
+ Customer.new(self)
56
+ end
57
+
58
+ # Create a new Token instance
59
+ def new_token()
60
+ Token.new(self)
61
+ end
62
+
63
+ # Create a new Discount instance
64
+ def new_discount()
65
+ Discount.new(self)
66
+ end
67
+
68
+ # Create a new Event instance
69
+ def new_event()
70
+ Event.new(self)
71
+ end
72
+
73
+ # Create a new Gateway instance
74
+ def new_gateway()
75
+ Gateway.new(self)
76
+ end
77
+
78
+ # Create a new GatewayConfiguration instance
79
+ def new_gateway_configuration()
80
+ GatewayConfiguration.new(self)
81
+ end
82
+
83
+ # Create a new Invoice instance
84
+ def new_invoice()
85
+ Invoice.new(self)
86
+ end
87
+
88
+ # Create a new CustomerAction instance
89
+ def new_customer_action()
90
+ CustomerAction.new(self)
91
+ end
92
+
93
+ # Create a new Plan instance
94
+ def new_plan()
95
+ Plan.new(self)
96
+ end
97
+
98
+ # Create a new Product instance
99
+ def new_product()
100
+ Product.new(self)
101
+ end
102
+
103
+ # Create a new Project instance
104
+ def new_project()
105
+ Project.new(self)
106
+ end
107
+
108
+ # Create a new Refund instance
109
+ def new_refund()
110
+ Refund.new(self)
111
+ end
112
+
113
+ # Create a new Subscription instance
114
+ def new_subscription()
115
+ Subscription.new(self)
116
+ end
117
+
118
+ # Create a new Transaction instance
119
+ def new_transaction()
120
+ Transaction.new(self)
121
+ end
122
+
123
+ # Create a new Webhook instance
124
+ def new_webhook()
125
+ Webhook.new(self)
126
+ end
127
+
128
+
129
+ end
130
+ end
@@ -0,0 +1,147 @@
1
+ # The content of this file was automatically generated
2
+
3
+ require "cgi"
4
+ require "processout/networking/request"
5
+ require "processout/networking/response"
6
+
7
+ module ProcessOut
8
+ class Activity
9
+
10
+ attr_reader :id
11
+ attr_reader :project
12
+ attr_reader :title
13
+ attr_reader :content
14
+ attr_reader :level
15
+ attr_reader :created_at
16
+
17
+
18
+ def id=(val)
19
+ @id = val
20
+ end
21
+
22
+ def project=(val)
23
+ if val.instance_of? Project
24
+ @project = val
25
+ else
26
+ obj = Project.new(@client)
27
+ obj.fill_with_data(val)
28
+ @project = obj
29
+ end
30
+
31
+ end
32
+
33
+ def title=(val)
34
+ @title = val
35
+ end
36
+
37
+ def content=(val)
38
+ @content = val
39
+ end
40
+
41
+ def level=(val)
42
+ @level = val
43
+ end
44
+
45
+ def created_at=(val)
46
+ @created_at = val
47
+ end
48
+
49
+
50
+ # Initializes the Activity object
51
+ # Params:
52
+ # +client+:: +ProcessOut+ client instance
53
+ def initialize(client)
54
+ @client = client
55
+
56
+ @id = ""
57
+ @project = nil
58
+ @title = ""
59
+ @content = ""
60
+ @level = 0
61
+ @created_at = ""
62
+
63
+ end
64
+
65
+ # Fills the object with data coming from the API
66
+ # Params:
67
+ # +data+:: +Hash+ of data coming from the API
68
+ def fill_with_data(data)
69
+ if data.include? "id"
70
+ @id = data["id"]
71
+ end
72
+ if data.include? "project"
73
+ @project = data["project"]
74
+ end
75
+ if data.include? "title"
76
+ @title = data["title"]
77
+ end
78
+ if data.include? "content"
79
+ @content = data["content"]
80
+ end
81
+ if data.include? "level"
82
+ @level = data["level"]
83
+ end
84
+ if data.include? "created_at"
85
+ @created_at = data["created_at"]
86
+ end
87
+
88
+ self
89
+ end
90
+
91
+ # Get all the project activities.
92
+ # Params:
93
+ # +options+:: +Hash+ of options
94
+ def all(options = nil)
95
+ request = Request.new(@client)
96
+ path = "/activities"
97
+ data = {
98
+
99
+ }
100
+
101
+ response = Response.new(request.get(path, data, options))
102
+ return_values = Array.new
103
+
104
+ a = Array.new
105
+ body = response.body
106
+ for v in body['activities']
107
+ tmp = Activity(@client)
108
+ tmp.fill_with_data(v)
109
+ a.push(tmp)
110
+ end
111
+
112
+ return_values.push(a)
113
+
114
+
115
+
116
+ return_values[0]
117
+ end
118
+
119
+ # Find a specific activity and fetch its data.
120
+ # Params:
121
+ # +activity_id+:: ID of the activity
122
+ # +options+:: +Hash+ of options
123
+ def find(activity_id, options = nil)
124
+ request = Request.new(@client)
125
+ path = "/activities/" + CGI.escape(activity_id) + ""
126
+ data = {
127
+
128
+ }
129
+
130
+ response = Response.new(request.get(path, data, options))
131
+ return_values = Array.new
132
+
133
+ body = response.body
134
+ body = body["activity"]
135
+
136
+
137
+ obj = Activity.new(@client)
138
+ return_values.push(obj.fill_with_data(body))
139
+
140
+
141
+
142
+ return_values[0]
143
+ end
144
+
145
+
146
+ end
147
+ end
@@ -0,0 +1,248 @@
1
+ # The content of this file was automatically generated
2
+
3
+ require "cgi"
4
+ require "processout/networking/request"
5
+ require "processout/networking/response"
6
+
7
+ module ProcessOut
8
+ class AuthorizationRequest
9
+
10
+ attr_reader :id
11
+ attr_reader :project
12
+ attr_reader :customer
13
+ attr_reader :token
14
+ attr_reader :url
15
+ attr_reader :authorized
16
+ attr_reader :name
17
+ attr_reader :currency
18
+ attr_reader :return_url
19
+ attr_reader :cancel_url
20
+ attr_reader :custom
21
+ attr_reader :sandbox
22
+ attr_reader :created_at
23
+
24
+
25
+ def id=(val)
26
+ @id = val
27
+ end
28
+
29
+ def project=(val)
30
+ if val.instance_of? Project
31
+ @project = val
32
+ else
33
+ obj = Project.new(@client)
34
+ obj.fill_with_data(val)
35
+ @project = obj
36
+ end
37
+
38
+ end
39
+
40
+ def customer=(val)
41
+ if val.instance_of? Customer
42
+ @customer = val
43
+ else
44
+ obj = Customer.new(@client)
45
+ obj.fill_with_data(val)
46
+ @customer = obj
47
+ end
48
+
49
+ end
50
+
51
+ def token=(val)
52
+ if val.instance_of? Token
53
+ @token = val
54
+ else
55
+ obj = Token.new(@client)
56
+ obj.fill_with_data(val)
57
+ @token = obj
58
+ end
59
+
60
+ end
61
+
62
+ def url=(val)
63
+ @url = val
64
+ end
65
+
66
+ def authorized=(val)
67
+ @authorized = val
68
+ end
69
+
70
+ def name=(val)
71
+ @name = val
72
+ end
73
+
74
+ def currency=(val)
75
+ @currency = val
76
+ end
77
+
78
+ def return_url=(val)
79
+ @return_url = val
80
+ end
81
+
82
+ def cancel_url=(val)
83
+ @cancel_url = val
84
+ end
85
+
86
+ def custom=(val)
87
+ @custom = val
88
+ end
89
+
90
+ def sandbox=(val)
91
+ @sandbox = val
92
+ end
93
+
94
+ def created_at=(val)
95
+ @created_at = val
96
+ end
97
+
98
+
99
+ # Initializes the AuthorizationRequest object
100
+ # Params:
101
+ # +client+:: +ProcessOut+ client instance
102
+ def initialize(client)
103
+ @client = client
104
+
105
+ @id = ""
106
+ @project = nil
107
+ @customer = nil
108
+ @token = nil
109
+ @url = ""
110
+ @authorized = false
111
+ @name = ""
112
+ @currency = ""
113
+ @return_url = ""
114
+ @cancel_url = ""
115
+ @custom = ""
116
+ @sandbox = false
117
+ @created_at = ""
118
+
119
+ end
120
+
121
+ # Fills the object with data coming from the API
122
+ # Params:
123
+ # +data+:: +Hash+ of data coming from the API
124
+ def fill_with_data(data)
125
+ if data.include? "id"
126
+ @id = data["id"]
127
+ end
128
+ if data.include? "project"
129
+ @project = data["project"]
130
+ end
131
+ if data.include? "customer"
132
+ @customer = data["customer"]
133
+ end
134
+ if data.include? "token"
135
+ @token = data["token"]
136
+ end
137
+ if data.include? "url"
138
+ @url = data["url"]
139
+ end
140
+ if data.include? "authorized"
141
+ @authorized = data["authorized"]
142
+ end
143
+ if data.include? "name"
144
+ @name = data["name"]
145
+ end
146
+ if data.include? "currency"
147
+ @currency = data["currency"]
148
+ end
149
+ if data.include? "return_url"
150
+ @return_url = data["return_url"]
151
+ end
152
+ if data.include? "cancel_url"
153
+ @cancel_url = data["cancel_url"]
154
+ end
155
+ if data.include? "custom"
156
+ @custom = data["custom"]
157
+ end
158
+ if data.include? "sandbox"
159
+ @sandbox = data["sandbox"]
160
+ end
161
+ if data.include? "created_at"
162
+ @created_at = data["created_at"]
163
+ end
164
+
165
+ self
166
+ end
167
+
168
+ # Get the customer linked to the authorization request.
169
+ # Params:
170
+ # +options+:: +Hash+ of options
171
+ def customer(options = nil)
172
+ request = Request.new(@client)
173
+ path = "/authorization-requests/" + CGI.escape(@id) + "/customers"
174
+ data = {
175
+
176
+ }
177
+
178
+ response = Response.new(request.get(path, data, options))
179
+ return_values = Array.new
180
+
181
+ body = response.body
182
+ body = body["customer"]
183
+ customer = Customer(self._client)
184
+ return_values.push(customer.fill_with_data(body))
185
+
186
+
187
+ return_values[0]
188
+ end
189
+
190
+ # Create a new authorization request for the given customer ID.
191
+ # Params:
192
+ # +customer_id+:: ID of the customer
193
+ # +options+:: +Hash+ of options
194
+ def create(customer_id, options = nil)
195
+ request = Request.new(@client)
196
+ path = "/authorization-requests"
197
+ data = {
198
+ "name": @name,
199
+ "currency": @currency,
200
+ "return_url": @return_url,
201
+ "cancel_url": @cancel_url,
202
+ "custom": @custom,
203
+ 'customer_id': customer_id
204
+ }
205
+
206
+ response = Response.new(request.post(path, data, options))
207
+ return_values = Array.new
208
+
209
+ body = response.body
210
+ body = body["authorization_request"]
211
+
212
+
213
+ return_values.push(self.fill_with_data(body))
214
+
215
+
216
+
217
+ return_values[0]
218
+ end
219
+
220
+ # Find an authorization request by its ID.
221
+ # Params:
222
+ # +authorization_request_id+:: ID of the authorization request
223
+ # +options+:: +Hash+ of options
224
+ def find(authorization_request_id, options = nil)
225
+ request = Request.new(@client)
226
+ path = "/authorization-requests/" + CGI.escape(authorization_request_id) + ""
227
+ data = {
228
+
229
+ }
230
+
231
+ response = Response.new(request.get(path, data, options))
232
+ return_values = Array.new
233
+
234
+ body = response.body
235
+ body = body["authorization_request"]
236
+
237
+
238
+ obj = AuthorizationRequest.new(@client)
239
+ return_values.push(obj.fill_with_data(body))
240
+
241
+
242
+
243
+ return_values[0]
244
+ end
245
+
246
+
247
+ end
248
+ end