processout 0.2.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 (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,167 @@
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 Token
9
+
10
+ attr_reader :id
11
+ attr_reader :customer
12
+ attr_reader :metadata
13
+ attr_reader :is_subscription_only
14
+ attr_reader :created_at
15
+
16
+
17
+ def id=(val)
18
+ @id = val
19
+ end
20
+
21
+ def customer=(val)
22
+ if val.instance_of? Customer
23
+ @customer = val
24
+ else
25
+ obj = Customer.new(@client)
26
+ obj.fill_with_data(val)
27
+ @customer = obj
28
+ end
29
+
30
+ end
31
+
32
+ def metadata=(val)
33
+ @metadata = val
34
+ end
35
+
36
+ def is_subscription_only=(val)
37
+ @is_subscription_only = val
38
+ end
39
+
40
+ def created_at=(val)
41
+ @created_at = val
42
+ end
43
+
44
+
45
+ # Initializes the Token object
46
+ # Params:
47
+ # +client+:: +ProcessOut+ client instance
48
+ def initialize(client)
49
+ @client = client
50
+
51
+ @id = ""
52
+ @customer = nil
53
+ @metadata = Hash.new
54
+ @is_subscription_only = false
55
+ @created_at = ""
56
+
57
+ end
58
+
59
+ # Fills the object with data coming from the API
60
+ # Params:
61
+ # +data+:: +Hash+ of data coming from the API
62
+ def fill_with_data(data)
63
+ if data.include? "id"
64
+ @id = data["id"]
65
+ end
66
+ if data.include? "customer"
67
+ @customer = data["customer"]
68
+ end
69
+ if data.include? "metadata"
70
+ @metadata = data["metadata"]
71
+ end
72
+ if data.include? "is_subscription_only"
73
+ @is_subscription_only = data["is_subscription_only"]
74
+ end
75
+ if data.include? "created_at"
76
+ @created_at = data["created_at"]
77
+ end
78
+
79
+ self
80
+ end
81
+
82
+ # Find a customer's token by its ID.
83
+ # Params:
84
+ # +customer_id+:: ID of the customer
85
+ # +token_id+:: ID of the token
86
+ # +options+:: +Hash+ of options
87
+ def find(customer_id, token_id, options = nil)
88
+ request = Request.new(@client)
89
+ path = "/customers/" + CGI.escape(customer_id) + "/tokens/" + CGI.escape(token_id) + ""
90
+ data = {
91
+
92
+ }
93
+
94
+ response = Response.new(request.get(path, data, options))
95
+ return_values = Array.new
96
+
97
+ body = response.body
98
+ body = body["token"]
99
+
100
+
101
+ obj = Token.new(@client)
102
+ return_values.push(obj.fill_with_data(body))
103
+
104
+
105
+
106
+ return_values[0]
107
+ end
108
+
109
+ # Create a new token for the given customer ID.
110
+ # Params:
111
+ # +customer_id+:: ID of the customer
112
+ # +source+:: Source used to create the token (most likely a card token generated by ProcessOut.js)
113
+ # +options+:: +Hash+ of options
114
+ def create(customer_id, source, options = nil)
115
+ request = Request.new(@client)
116
+ path = "/customers/" + CGI.escape(customer_id) + "/tokens"
117
+ data = {
118
+ "metadata": @metadata,
119
+ 'source': source
120
+ }
121
+
122
+ response = Response.new(request.post(path, data, options))
123
+ return_values = Array.new
124
+
125
+ body = response.body
126
+ body = body["token"]
127
+
128
+
129
+ return_values.push(self.fill_with_data(body))
130
+
131
+
132
+
133
+ return_values[0]
134
+ end
135
+
136
+ # Create a new token for the given customer ID from an authorization request
137
+ # Params:
138
+ # +customer_id+:: ID of the customer
139
+ # +source+:: Source used to create the token (most likely a card token generated by ProcessOut.js)
140
+ # +target+:: Authorization request ID
141
+ # +options+:: +Hash+ of options
142
+ def create_from_request(customer_id, source, target, options = nil)
143
+ request = Request.new(@client)
144
+ path = "/customers/" + CGI.escape(customer_id) + "/tokens"
145
+ data = {
146
+ "metadata": @metadata,
147
+ 'source': source,
148
+ 'target': target
149
+ }
150
+
151
+ response = Response.new(request.post(path, data, options))
152
+ return_values = Array.new
153
+
154
+ body = response.body
155
+ body = body["token"]
156
+
157
+
158
+ return_values.push(self.fill_with_data(body))
159
+
160
+
161
+
162
+ return_values[0]
163
+ end
164
+
165
+
166
+ end
167
+ end
@@ -0,0 +1,302 @@
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 Transaction
9
+
10
+ attr_reader :id
11
+ attr_reader :project
12
+ attr_reader :subscription
13
+ attr_reader :customer
14
+ attr_reader :token
15
+ attr_reader :card
16
+ attr_reader :name
17
+ attr_reader :authorized_amount
18
+ attr_reader :captured_amount
19
+ attr_reader :currency
20
+ attr_reader :status
21
+ attr_reader :authorized
22
+ attr_reader :captured
23
+ attr_reader :processout_fee
24
+ attr_reader :metadata
25
+ attr_reader :sandbox
26
+ attr_reader :created_at
27
+
28
+
29
+ def id=(val)
30
+ @id = val
31
+ end
32
+
33
+ def project=(val)
34
+ if val.instance_of? Project
35
+ @project = val
36
+ else
37
+ obj = Project.new(@client)
38
+ obj.fill_with_data(val)
39
+ @project = obj
40
+ end
41
+
42
+ end
43
+
44
+ def subscription=(val)
45
+ if val.instance_of? Subscription
46
+ @subscription = val
47
+ else
48
+ obj = Subscription.new(@client)
49
+ obj.fill_with_data(val)
50
+ @subscription = obj
51
+ end
52
+
53
+ end
54
+
55
+ def customer=(val)
56
+ if val.instance_of? Customer
57
+ @customer = val
58
+ else
59
+ obj = Customer.new(@client)
60
+ obj.fill_with_data(val)
61
+ @customer = obj
62
+ end
63
+
64
+ end
65
+
66
+ def token=(val)
67
+ if val.instance_of? Token
68
+ @token = val
69
+ else
70
+ obj = Token.new(@client)
71
+ obj.fill_with_data(val)
72
+ @token = obj
73
+ end
74
+
75
+ end
76
+
77
+ def card=(val)
78
+ if val.instance_of? Card
79
+ @card = val
80
+ else
81
+ obj = Card.new(@client)
82
+ obj.fill_with_data(val)
83
+ @card = obj
84
+ end
85
+
86
+ end
87
+
88
+ def name=(val)
89
+ @name = val
90
+ end
91
+
92
+ def authorized_amount=(val)
93
+ @authorized_amount = val
94
+ end
95
+
96
+ def captured_amount=(val)
97
+ @captured_amount = val
98
+ end
99
+
100
+ def currency=(val)
101
+ @currency = val
102
+ end
103
+
104
+ def status=(val)
105
+ @status = val
106
+ end
107
+
108
+ def authorized=(val)
109
+ @authorized = val
110
+ end
111
+
112
+ def captured=(val)
113
+ @captured = val
114
+ end
115
+
116
+ def processout_fee=(val)
117
+ @processout_fee = val
118
+ end
119
+
120
+ def metadata=(val)
121
+ @metadata = val
122
+ end
123
+
124
+ def sandbox=(val)
125
+ @sandbox = val
126
+ end
127
+
128
+ def created_at=(val)
129
+ @created_at = val
130
+ end
131
+
132
+
133
+ # Initializes the Transaction object
134
+ # Params:
135
+ # +client+:: +ProcessOut+ client instance
136
+ def initialize(client)
137
+ @client = client
138
+
139
+ @id = ""
140
+ @project = nil
141
+ @subscription = nil
142
+ @customer = nil
143
+ @token = nil
144
+ @card = nil
145
+ @name = ""
146
+ @authorized_amount = ""
147
+ @captured_amount = ""
148
+ @currency = ""
149
+ @status = ""
150
+ @authorized = false
151
+ @captured = false
152
+ @processout_fee = ""
153
+ @metadata = Hash.new
154
+ @sandbox = false
155
+ @created_at = ""
156
+
157
+ end
158
+
159
+ # Fills the object with data coming from the API
160
+ # Params:
161
+ # +data+:: +Hash+ of data coming from the API
162
+ def fill_with_data(data)
163
+ if data.include? "id"
164
+ @id = data["id"]
165
+ end
166
+ if data.include? "project"
167
+ @project = data["project"]
168
+ end
169
+ if data.include? "subscription"
170
+ @subscription = data["subscription"]
171
+ end
172
+ if data.include? "customer"
173
+ @customer = data["customer"]
174
+ end
175
+ if data.include? "token"
176
+ @token = data["token"]
177
+ end
178
+ if data.include? "card"
179
+ @card = data["card"]
180
+ end
181
+ if data.include? "name"
182
+ @name = data["name"]
183
+ end
184
+ if data.include? "authorized_amount"
185
+ @authorized_amount = data["authorized_amount"]
186
+ end
187
+ if data.include? "captured_amount"
188
+ @captured_amount = data["captured_amount"]
189
+ end
190
+ if data.include? "currency"
191
+ @currency = data["currency"]
192
+ end
193
+ if data.include? "status"
194
+ @status = data["status"]
195
+ end
196
+ if data.include? "authorized"
197
+ @authorized = data["authorized"]
198
+ end
199
+ if data.include? "captured"
200
+ @captured = data["captured"]
201
+ end
202
+ if data.include? "processout_fee"
203
+ @processout_fee = data["processout_fee"]
204
+ end
205
+ if data.include? "metadata"
206
+ @metadata = data["metadata"]
207
+ end
208
+ if data.include? "sandbox"
209
+ @sandbox = data["sandbox"]
210
+ end
211
+ if data.include? "created_at"
212
+ @created_at = data["created_at"]
213
+ end
214
+
215
+ self
216
+ end
217
+
218
+ # Get the transaction's refunds.
219
+ # Params:
220
+ # +options+:: +Hash+ of options
221
+ def refunds(options = nil)
222
+ request = Request.new(@client)
223
+ path = "/transactions/" + CGI.escape(@id) + "/refunds"
224
+ data = {
225
+
226
+ }
227
+
228
+ response = Response.new(request.get(path, data, options))
229
+ return_values = Array.new
230
+
231
+ a = Array.new
232
+ body = response.body
233
+ for v in body['refunds']
234
+ tmp = Refund(@client)
235
+ tmp.fill_with_data(v)
236
+ a.push(tmp)
237
+ end
238
+
239
+ return_values.push(a)
240
+
241
+
242
+
243
+ return_values[0]
244
+ end
245
+
246
+ # Get all the transactions.
247
+ # Params:
248
+ # +options+:: +Hash+ of options
249
+ def all(options = nil)
250
+ request = Request.new(@client)
251
+ path = "/transactions"
252
+ data = {
253
+
254
+ }
255
+
256
+ response = Response.new(request.get(path, data, options))
257
+ return_values = Array.new
258
+
259
+ a = Array.new
260
+ body = response.body
261
+ for v in body['transactions']
262
+ tmp = Transaction(@client)
263
+ tmp.fill_with_data(v)
264
+ a.push(tmp)
265
+ end
266
+
267
+ return_values.push(a)
268
+
269
+
270
+
271
+ return_values[0]
272
+ end
273
+
274
+ # Find a transaction by its ID.
275
+ # Params:
276
+ # +transaction_id+:: ID of the transaction
277
+ # +options+:: +Hash+ of options
278
+ def find(transaction_id, options = nil)
279
+ request = Request.new(@client)
280
+ path = "/transactions/" + CGI.escape(transaction_id) + ""
281
+ data = {
282
+
283
+ }
284
+
285
+ response = Response.new(request.get(path, data, options))
286
+ return_values = Array.new
287
+
288
+ body = response.body
289
+ body = body["transaction"]
290
+
291
+
292
+ obj = Transaction.new(@client)
293
+ return_values.push(obj.fill_with_data(body))
294
+
295
+
296
+
297
+ return_values[0]
298
+ end
299
+
300
+
301
+ end
302
+ end