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,104 @@
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 Gateway
9
+
10
+ attr_reader :id
11
+ attr_reader :name
12
+ attr_reader :display_name
13
+ attr_reader :logo_url
14
+ attr_reader :url
15
+ attr_reader :flows
16
+ attr_reader :tags
17
+ attr_reader :description
18
+
19
+
20
+ def id=(val)
21
+ @id = val
22
+ end
23
+
24
+ def name=(val)
25
+ @name = val
26
+ end
27
+
28
+ def display_name=(val)
29
+ @display_name = val
30
+ end
31
+
32
+ def logo_url=(val)
33
+ @logo_url = val
34
+ end
35
+
36
+ def url=(val)
37
+ @url = val
38
+ end
39
+
40
+ def flows=(val)
41
+ @flows = val
42
+ end
43
+
44
+ def tags=(val)
45
+ @tags = val
46
+ end
47
+
48
+ def description=(val)
49
+ @description = val
50
+ end
51
+
52
+
53
+ # Initializes the Gateway object
54
+ # Params:
55
+ # +client+:: +ProcessOut+ client instance
56
+ def initialize(client)
57
+ @client = client
58
+
59
+ @id = ""
60
+ @name = ""
61
+ @display_name = ""
62
+ @logo_url = ""
63
+ @url = ""
64
+ @flows = Array.new
65
+ @tags = Array.new
66
+ @description = ""
67
+
68
+ end
69
+
70
+ # Fills the object with data coming from the API
71
+ # Params:
72
+ # +data+:: +Hash+ of data coming from the API
73
+ def fill_with_data(data)
74
+ if data.include? "id"
75
+ @id = data["id"]
76
+ end
77
+ if data.include? "name"
78
+ @name = data["name"]
79
+ end
80
+ if data.include? "display_name"
81
+ @display_name = data["display_name"]
82
+ end
83
+ if data.include? "logo_url"
84
+ @logo_url = data["logo_url"]
85
+ end
86
+ if data.include? "url"
87
+ @url = data["url"]
88
+ end
89
+ if data.include? "flows"
90
+ @flows = data["flows"]
91
+ end
92
+ if data.include? "tags"
93
+ @tags = data["tags"]
94
+ end
95
+ if data.include? "description"
96
+ @description = data["description"]
97
+ end
98
+
99
+ self
100
+ end
101
+
102
+
103
+ end
104
+ end
@@ -0,0 +1,91 @@
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 GatewayConfiguration
9
+
10
+ attr_reader :id
11
+ attr_reader :project
12
+ attr_reader :gateway
13
+ attr_reader :enabled
14
+ attr_reader :public_keys
15
+
16
+
17
+ def id=(val)
18
+ @id = val
19
+ end
20
+
21
+ def project=(val)
22
+ if val.instance_of? Project
23
+ @project = val
24
+ else
25
+ obj = Project.new(@client)
26
+ obj.fill_with_data(val)
27
+ @project = obj
28
+ end
29
+
30
+ end
31
+
32
+ def gateway=(val)
33
+ if val.instance_of? Gateway
34
+ @gateway = val
35
+ else
36
+ obj = Gateway.new(@client)
37
+ obj.fill_with_data(val)
38
+ @gateway = obj
39
+ end
40
+
41
+ end
42
+
43
+ def enabled=(val)
44
+ @enabled = val
45
+ end
46
+
47
+ def public_keys=(val)
48
+ @public_keys = val
49
+ end
50
+
51
+
52
+ # Initializes the GatewayConfiguration object
53
+ # Params:
54
+ # +client+:: +ProcessOut+ client instance
55
+ def initialize(client)
56
+ @client = client
57
+
58
+ @id = ""
59
+ @project = nil
60
+ @gateway = nil
61
+ @enabled = false
62
+ @public_keys = Hash.new
63
+
64
+ end
65
+
66
+ # Fills the object with data coming from the API
67
+ # Params:
68
+ # +data+:: +Hash+ of data coming from the API
69
+ def fill_with_data(data)
70
+ if data.include? "id"
71
+ @id = data["id"]
72
+ end
73
+ if data.include? "project"
74
+ @project = data["project"]
75
+ end
76
+ if data.include? "gateway"
77
+ @gateway = data["gateway"]
78
+ end
79
+ if data.include? "enabled"
80
+ @enabled = data["enabled"]
81
+ end
82
+ if data.include? "public_keys"
83
+ @public_keys = data["public_keys"]
84
+ end
85
+
86
+ self
87
+ end
88
+
89
+
90
+ end
91
+ end
@@ -0,0 +1,457 @@
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 Invoice
9
+
10
+ attr_reader :id
11
+ attr_reader :project
12
+ attr_reader :transaction
13
+ attr_reader :customer
14
+ attr_reader :subscription
15
+ attr_reader :url
16
+ attr_reader :name
17
+ attr_reader :amount
18
+ attr_reader :currency
19
+ attr_reader :metadata
20
+ attr_reader :request_email
21
+ attr_reader :request_shipping
22
+ attr_reader :return_url
23
+ attr_reader :cancel_url
24
+ attr_reader :sandbox
25
+ attr_reader :created_at
26
+
27
+
28
+ def id=(val)
29
+ @id = val
30
+ end
31
+
32
+ def project=(val)
33
+ if val.instance_of? Project
34
+ @project = val
35
+ else
36
+ obj = Project.new(@client)
37
+ obj.fill_with_data(val)
38
+ @project = obj
39
+ end
40
+
41
+ end
42
+
43
+ def transaction=(val)
44
+ if val.instance_of? Transaction
45
+ @transaction = val
46
+ else
47
+ obj = Transaction.new(@client)
48
+ obj.fill_with_data(val)
49
+ @transaction = obj
50
+ end
51
+
52
+ end
53
+
54
+ def customer=(val)
55
+ if val.instance_of? Customer
56
+ @customer = val
57
+ else
58
+ obj = Customer.new(@client)
59
+ obj.fill_with_data(val)
60
+ @customer = obj
61
+ end
62
+
63
+ end
64
+
65
+ def subscription=(val)
66
+ if val.instance_of? Subscription
67
+ @subscription = val
68
+ else
69
+ obj = Subscription.new(@client)
70
+ obj.fill_with_data(val)
71
+ @subscription = obj
72
+ end
73
+
74
+ end
75
+
76
+ def url=(val)
77
+ @url = val
78
+ end
79
+
80
+ def name=(val)
81
+ @name = val
82
+ end
83
+
84
+ def amount=(val)
85
+ @amount = val
86
+ end
87
+
88
+ def currency=(val)
89
+ @currency = val
90
+ end
91
+
92
+ def metadata=(val)
93
+ @metadata = val
94
+ end
95
+
96
+ def request_email=(val)
97
+ @request_email = val
98
+ end
99
+
100
+ def request_shipping=(val)
101
+ @request_shipping = val
102
+ end
103
+
104
+ def return_url=(val)
105
+ @return_url = val
106
+ end
107
+
108
+ def cancel_url=(val)
109
+ @cancel_url = val
110
+ end
111
+
112
+ def sandbox=(val)
113
+ @sandbox = val
114
+ end
115
+
116
+ def created_at=(val)
117
+ @created_at = val
118
+ end
119
+
120
+
121
+ # Initializes the Invoice object
122
+ # Params:
123
+ # +client+:: +ProcessOut+ client instance
124
+ def initialize(client)
125
+ @client = client
126
+
127
+ @id = ""
128
+ @project = nil
129
+ @transaction = nil
130
+ @customer = nil
131
+ @subscription = nil
132
+ @url = ""
133
+ @name = ""
134
+ @amount = ""
135
+ @currency = ""
136
+ @metadata = Hash.new
137
+ @request_email = false
138
+ @request_shipping = false
139
+ @return_url = ""
140
+ @cancel_url = ""
141
+ @sandbox = false
142
+ @created_at = ""
143
+
144
+ end
145
+
146
+ # Fills the object with data coming from the API
147
+ # Params:
148
+ # +data+:: +Hash+ of data coming from the API
149
+ def fill_with_data(data)
150
+ if data.include? "id"
151
+ @id = data["id"]
152
+ end
153
+ if data.include? "project"
154
+ @project = data["project"]
155
+ end
156
+ if data.include? "transaction"
157
+ @transaction = data["transaction"]
158
+ end
159
+ if data.include? "customer"
160
+ @customer = data["customer"]
161
+ end
162
+ if data.include? "subscription"
163
+ @subscription = data["subscription"]
164
+ end
165
+ if data.include? "url"
166
+ @url = data["url"]
167
+ end
168
+ if data.include? "name"
169
+ @name = data["name"]
170
+ end
171
+ if data.include? "amount"
172
+ @amount = data["amount"]
173
+ end
174
+ if data.include? "currency"
175
+ @currency = data["currency"]
176
+ end
177
+ if data.include? "metadata"
178
+ @metadata = data["metadata"]
179
+ end
180
+ if data.include? "request_email"
181
+ @request_email = data["request_email"]
182
+ end
183
+ if data.include? "request_shipping"
184
+ @request_shipping = data["request_shipping"]
185
+ end
186
+ if data.include? "return_url"
187
+ @return_url = data["return_url"]
188
+ end
189
+ if data.include? "cancel_url"
190
+ @cancel_url = data["cancel_url"]
191
+ end
192
+ if data.include? "sandbox"
193
+ @sandbox = data["sandbox"]
194
+ end
195
+ if data.include? "created_at"
196
+ @created_at = data["created_at"]
197
+ end
198
+
199
+ self
200
+ end
201
+
202
+ # Authorize the invoice using the given source (customer or token)
203
+ # Params:
204
+ # +source+:: Source used to authorization the payment. Can be a card, a token or a gateway request
205
+ # +options+:: +Hash+ of options
206
+ def authorize(source, options = nil)
207
+ request = Request.new(@client)
208
+ path = "/invoices/" + CGI.escape(@id) + "/authorize"
209
+ data = {
210
+ 'source': source
211
+ }
212
+
213
+ response = Response.new(request.post(path, data, options))
214
+ return_values = Array.new
215
+
216
+ body = response.body
217
+ body = body["transaction"]
218
+ transaction = Transaction(self._client)
219
+ return_values.push(transaction.fill_with_data(body))
220
+
221
+
222
+ return_values[0]
223
+ end
224
+
225
+ # Capture the invoice using the given source (customer or token)
226
+ # Params:
227
+ # +source+:: Source used to authorization the payment. Can be a card, a token or a gateway request
228
+ # +options+:: +Hash+ of options
229
+ def capture(source, options = nil)
230
+ request = Request.new(@client)
231
+ path = "/invoices/" + CGI.escape(@id) + "/capture"
232
+ data = {
233
+ 'source': source
234
+ }
235
+
236
+ response = Response.new(request.post(path, data, options))
237
+ return_values = Array.new
238
+
239
+ body = response.body
240
+ body = body["transaction"]
241
+ transaction = Transaction(self._client)
242
+ return_values.push(transaction.fill_with_data(body))
243
+
244
+
245
+ return_values[0]
246
+ end
247
+
248
+ # Get the customer linked to the invoice.
249
+ # Params:
250
+ # +options+:: +Hash+ of options
251
+ def customer(options = nil)
252
+ request = Request.new(@client)
253
+ path = "/invoices/" + CGI.escape(@id) + "/customers"
254
+ data = {
255
+
256
+ }
257
+
258
+ response = Response.new(request.get(path, data, options))
259
+ return_values = Array.new
260
+
261
+ body = response.body
262
+ body = body["customer"]
263
+ customer = Customer(self._client)
264
+ return_values.push(customer.fill_with_data(body))
265
+
266
+
267
+ return_values[0]
268
+ end
269
+
270
+ # Assign a customer to the invoice.
271
+ # Params:
272
+ # +customer_id+:: ID of the customer to be linked to the invoice
273
+ # +options+:: +Hash+ of options
274
+ def assign_customer(customer_id, options = nil)
275
+ request = Request.new(@client)
276
+ path = "/invoices/" + CGI.escape(@id) + "/customers"
277
+ data = {
278
+ 'customer_id': customer_id
279
+ }
280
+
281
+ response = Response.new(request.post(path, data, options))
282
+ return_values = Array.new
283
+
284
+ body = response.body
285
+ body = body["customer"]
286
+ customer = Customer(self._client)
287
+ return_values.push(customer.fill_with_data(body))
288
+
289
+
290
+ return_values[0]
291
+ end
292
+
293
+ # Get the transaction of the invoice.
294
+ # Params:
295
+ # +options+:: +Hash+ of options
296
+ def transaction(options = nil)
297
+ request = Request.new(@client)
298
+ path = "/invoices/" + CGI.escape(@id) + "/transactions"
299
+ data = {
300
+
301
+ }
302
+
303
+ response = Response.new(request.get(path, data, options))
304
+ return_values = Array.new
305
+
306
+ body = response.body
307
+ body = body["transaction"]
308
+ transaction = Transaction(self._client)
309
+ return_values.push(transaction.fill_with_data(body))
310
+
311
+
312
+ return_values[0]
313
+ end
314
+
315
+ # Void the invoice
316
+ # Params:
317
+ # +options+:: +Hash+ of options
318
+ def void(options = nil)
319
+ request = Request.new(@client)
320
+ path = "/invoices/" + CGI.escape(@id) + "/void"
321
+ data = {
322
+
323
+ }
324
+
325
+ response = Response.new(request.post(path, data, options))
326
+ return_values = Array.new
327
+
328
+ body = response.body
329
+ body = body["transaction"]
330
+ transaction = Transaction(self._client)
331
+ return_values.push(transaction.fill_with_data(body))
332
+
333
+
334
+ return_values[0]
335
+ end
336
+
337
+ # Get all the invoices.
338
+ # Params:
339
+ # +options+:: +Hash+ of options
340
+ def all(options = nil)
341
+ request = Request.new(@client)
342
+ path = "/invoices"
343
+ data = {
344
+
345
+ }
346
+
347
+ response = Response.new(request.get(path, data, options))
348
+ return_values = Array.new
349
+
350
+ a = Array.new
351
+ body = response.body
352
+ for v in body['invoices']
353
+ tmp = Invoice(@client)
354
+ tmp.fill_with_data(v)
355
+ a.push(tmp)
356
+ end
357
+
358
+ return_values.push(a)
359
+
360
+
361
+
362
+ return_values[0]
363
+ end
364
+
365
+ # Create a new invoice.
366
+ # Params:
367
+ # +options+:: +Hash+ of options
368
+ def create(options = nil)
369
+ request = Request.new(@client)
370
+ path = "/invoices"
371
+ data = {
372
+ "name": @name,
373
+ "amount": @amount,
374
+ "currency": @currency,
375
+ "metadata": @metadata,
376
+ "request_email": @request_email,
377
+ "request_shipping": @request_shipping,
378
+ "return_url": @return_url,
379
+ "cancel_url": @cancel_url
380
+ }
381
+
382
+ response = Response.new(request.post(path, data, options))
383
+ return_values = Array.new
384
+
385
+ body = response.body
386
+ body = body["invoice"]
387
+
388
+
389
+ return_values.push(self.fill_with_data(body))
390
+
391
+
392
+
393
+ return_values[0]
394
+ end
395
+
396
+ # Create a new invoice for the given customer ID.
397
+ # Params:
398
+ # +customer_id+:: ID of the customer
399
+ # +options+:: +Hash+ of options
400
+ def create_for_customer(customer_id, options = nil)
401
+ request = Request.new(@client)
402
+ path = "/invoices"
403
+ data = {
404
+ "name": @name,
405
+ "amount": @amount,
406
+ "currency": @currency,
407
+ "metadata": @metadata,
408
+ "request_email": @request_email,
409
+ "request_shipping": @request_shipping,
410
+ "return_url": @return_url,
411
+ "cancel_url": @cancel_url,
412
+ 'customer_id': customer_id
413
+ }
414
+
415
+ response = Response.new(request.post(path, data, options))
416
+ return_values = Array.new
417
+
418
+ body = response.body
419
+ body = body["invoice"]
420
+
421
+
422
+ return_values.push(self.fill_with_data(body))
423
+
424
+
425
+
426
+ return_values[0]
427
+ end
428
+
429
+ # Find an invoice by its ID.
430
+ # Params:
431
+ # +invoice_id+:: ID of the invoice
432
+ # +options+:: +Hash+ of options
433
+ def find(invoice_id, options = nil)
434
+ request = Request.new(@client)
435
+ path = "/invoices/" + CGI.escape(invoice_id) + ""
436
+ data = {
437
+
438
+ }
439
+
440
+ response = Response.new(request.get(path, data, options))
441
+ return_values = Array.new
442
+
443
+ body = response.body
444
+ body = body["invoice"]
445
+
446
+
447
+ obj = Invoice.new(@client)
448
+ return_values.push(obj.fill_with_data(body))
449
+
450
+
451
+
452
+ return_values[0]
453
+ end
454
+
455
+
456
+ end
457
+ end