processout 2.20.0 → 2.22.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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +52 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Dockerfile +7 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/Makefile +4 -0
  9. data/README.md +12 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/processout/activity.rb +206 -0
  14. data/lib/processout/addon.rb +401 -0
  15. data/lib/processout/alternative_merchant_certificate.rb +115 -0
  16. data/lib/processout/api_request.rb +295 -0
  17. data/lib/processout/api_version.rb +92 -0
  18. data/lib/processout/apple_pay_alternative_merchant_certificates.rb +121 -0
  19. data/lib/processout/balance.rb +92 -0
  20. data/lib/processout/balances.rb +111 -0
  21. data/lib/processout/card.rb +503 -0
  22. data/lib/processout/card_information.rb +164 -0
  23. data/lib/processout/coupon.rb +352 -0
  24. data/lib/processout/customer.rb +755 -0
  25. data/lib/processout/customer_action.rb +81 -0
  26. data/lib/processout/discount.rb +360 -0
  27. data/lib/processout/dunning_action.rb +81 -0
  28. data/lib/processout/errors/authentication_error.rb +9 -0
  29. data/lib/processout/errors/generic_error.rb +9 -0
  30. data/lib/processout/errors/internal_error.rb +9 -0
  31. data/lib/processout/errors/notfound_error.rb +9 -0
  32. data/lib/processout/errors/validation_error.rb +9 -0
  33. data/lib/processout/event.rb +237 -0
  34. data/lib/processout/gateway.rb +210 -0
  35. data/lib/processout/gateway_configuration.rb +346 -0
  36. data/lib/processout/gateway_request.rb +26 -0
  37. data/lib/processout/invoice.rb +985 -0
  38. data/lib/processout/invoice_detail.rb +235 -0
  39. data/lib/processout/invoice_device.rb +92 -0
  40. data/lib/processout/invoice_external_fraud_tools.rb +70 -0
  41. data/lib/processout/invoice_risk.rb +81 -0
  42. data/lib/processout/invoice_shipping.rb +202 -0
  43. data/lib/processout/invoice_tax.rb +81 -0
  44. data/lib/processout/networking/request.rb +102 -0
  45. data/lib/processout/networking/response.rb +67 -0
  46. data/lib/processout/payment_data_network_authentication.rb +70 -0
  47. data/lib/processout/payment_data_three_ds_authentication.rb +70 -0
  48. data/lib/processout/payment_data_three_ds_request.rb +103 -0
  49. data/lib/processout/payout.rb +379 -0
  50. data/lib/processout/payout_item.rb +238 -0
  51. data/lib/processout/plan.rb +368 -0
  52. data/lib/processout/product.rb +368 -0
  53. data/lib/processout/project.rb +353 -0
  54. data/lib/processout/refund.rb +277 -0
  55. data/lib/processout/subscription.rb +910 -0
  56. data/lib/processout/three_ds.rb +158 -0
  57. data/lib/processout/token.rb +493 -0
  58. data/lib/processout/transaction.rb +905 -0
  59. data/lib/processout/transaction_operation.rb +418 -0
  60. data/lib/processout/version.rb +3 -0
  61. data/lib/processout/webhook.rb +237 -0
  62. data/lib/processout/webhook_endpoint.rb +149 -0
  63. data/lib/processout.rb +263 -0
  64. data/processout.gemspec +26 -0
  65. metadata +66 -3
@@ -0,0 +1,352 @@
1
+ # The content of this file was automatically generated
2
+
3
+ require "cgi"
4
+ require "json"
5
+ require "processout/networking/request"
6
+ require "processout/networking/response"
7
+
8
+ module ProcessOut
9
+ class Coupon
10
+
11
+ attr_reader :id
12
+ attr_reader :project
13
+ attr_reader :project_id
14
+ attr_reader :amount_off
15
+ attr_reader :percent_off
16
+ attr_reader :currency
17
+ attr_reader :iteration_count
18
+ attr_reader :max_redemptions
19
+ attr_reader :expires_at
20
+ attr_reader :metadata
21
+ attr_reader :redeemed_number
22
+ attr_reader :sandbox
23
+ attr_reader :created_at
24
+
25
+
26
+ def id=(val)
27
+ @id = val
28
+ end
29
+
30
+ def project=(val)
31
+ if val.nil?
32
+ @project = val
33
+ return
34
+ end
35
+
36
+ if val.instance_of? Project
37
+ @project = val
38
+ else
39
+ obj = Project.new(@client)
40
+ obj.fill_with_data(val)
41
+ @project = obj
42
+ end
43
+
44
+ end
45
+
46
+ def project_id=(val)
47
+ @project_id = val
48
+ end
49
+
50
+ def amount_off=(val)
51
+ @amount_off = val
52
+ end
53
+
54
+ def percent_off=(val)
55
+ @percent_off = val
56
+ end
57
+
58
+ def currency=(val)
59
+ @currency = val
60
+ end
61
+
62
+ def iteration_count=(val)
63
+ @iteration_count = val
64
+ end
65
+
66
+ def max_redemptions=(val)
67
+ @max_redemptions = val
68
+ end
69
+
70
+ def expires_at=(val)
71
+ @expires_at = val
72
+ end
73
+
74
+ def metadata=(val)
75
+ @metadata = val
76
+ end
77
+
78
+ def redeemed_number=(val)
79
+ @redeemed_number = val
80
+ end
81
+
82
+ def sandbox=(val)
83
+ @sandbox = val
84
+ end
85
+
86
+ def created_at=(val)
87
+ @created_at = val
88
+ end
89
+
90
+
91
+ # Initializes the Coupon object
92
+ # Params:
93
+ # +client+:: +ProcessOut+ client instance
94
+ # +data+:: data that can be used to fill the object
95
+ def initialize(client, data = {})
96
+ @client = client
97
+
98
+ self.id = data.fetch(:id, nil)
99
+ self.project = data.fetch(:project, nil)
100
+ self.project_id = data.fetch(:project_id, nil)
101
+ self.amount_off = data.fetch(:amount_off, nil)
102
+ self.percent_off = data.fetch(:percent_off, nil)
103
+ self.currency = data.fetch(:currency, nil)
104
+ self.iteration_count = data.fetch(:iteration_count, nil)
105
+ self.max_redemptions = data.fetch(:max_redemptions, nil)
106
+ self.expires_at = data.fetch(:expires_at, nil)
107
+ self.metadata = data.fetch(:metadata, nil)
108
+ self.redeemed_number = data.fetch(:redeemed_number, nil)
109
+ self.sandbox = data.fetch(:sandbox, nil)
110
+ self.created_at = data.fetch(:created_at, nil)
111
+
112
+ end
113
+
114
+ # Create a new Coupon using the current client
115
+ def new(data = {})
116
+ Coupon.new(@client, data)
117
+ end
118
+
119
+ # Overrides the JSON marshaller to only send the fields we want
120
+ def to_json(options)
121
+ {
122
+ "id": self.id,
123
+ "project": self.project,
124
+ "project_id": self.project_id,
125
+ "amount_off": self.amount_off,
126
+ "percent_off": self.percent_off,
127
+ "currency": self.currency,
128
+ "iteration_count": self.iteration_count,
129
+ "max_redemptions": self.max_redemptions,
130
+ "expires_at": self.expires_at,
131
+ "metadata": self.metadata,
132
+ "redeemed_number": self.redeemed_number,
133
+ "sandbox": self.sandbox,
134
+ "created_at": self.created_at,
135
+ }.to_json
136
+ end
137
+
138
+ # Fills the object with data coming from the API
139
+ # Params:
140
+ # +data+:: +Hash+ of data coming from the API
141
+ def fill_with_data(data)
142
+ if data.nil?
143
+ return self
144
+ end
145
+ if data.include? "id"
146
+ self.id = data["id"]
147
+ end
148
+ if data.include? "project"
149
+ self.project = data["project"]
150
+ end
151
+ if data.include? "project_id"
152
+ self.project_id = data["project_id"]
153
+ end
154
+ if data.include? "amount_off"
155
+ self.amount_off = data["amount_off"]
156
+ end
157
+ if data.include? "percent_off"
158
+ self.percent_off = data["percent_off"]
159
+ end
160
+ if data.include? "currency"
161
+ self.currency = data["currency"]
162
+ end
163
+ if data.include? "iteration_count"
164
+ self.iteration_count = data["iteration_count"]
165
+ end
166
+ if data.include? "max_redemptions"
167
+ self.max_redemptions = data["max_redemptions"]
168
+ end
169
+ if data.include? "expires_at"
170
+ self.expires_at = data["expires_at"]
171
+ end
172
+ if data.include? "metadata"
173
+ self.metadata = data["metadata"]
174
+ end
175
+ if data.include? "redeemed_number"
176
+ self.redeemed_number = data["redeemed_number"]
177
+ end
178
+ if data.include? "sandbox"
179
+ self.sandbox = data["sandbox"]
180
+ end
181
+ if data.include? "created_at"
182
+ self.created_at = data["created_at"]
183
+ end
184
+
185
+ self
186
+ end
187
+
188
+ # Prefills the object with the data passed as parameters
189
+ # Params:
190
+ # +data+:: +Hash+ of data
191
+ def prefill(data)
192
+ if data.nil?
193
+ return self
194
+ end
195
+ self.id = data.fetch(:id, self.id)
196
+ self.project = data.fetch(:project, self.project)
197
+ self.project_id = data.fetch(:project_id, self.project_id)
198
+ self.amount_off = data.fetch(:amount_off, self.amount_off)
199
+ self.percent_off = data.fetch(:percent_off, self.percent_off)
200
+ self.currency = data.fetch(:currency, self.currency)
201
+ self.iteration_count = data.fetch(:iteration_count, self.iteration_count)
202
+ self.max_redemptions = data.fetch(:max_redemptions, self.max_redemptions)
203
+ self.expires_at = data.fetch(:expires_at, self.expires_at)
204
+ self.metadata = data.fetch(:metadata, self.metadata)
205
+ self.redeemed_number = data.fetch(:redeemed_number, self.redeemed_number)
206
+ self.sandbox = data.fetch(:sandbox, self.sandbox)
207
+ self.created_at = data.fetch(:created_at, self.created_at)
208
+
209
+ self
210
+ end
211
+
212
+ # Get all the coupons.
213
+ # Params:
214
+ # +options+:: +Hash+ of options
215
+ def all(options = {})
216
+ self.prefill(options)
217
+
218
+ request = Request.new(@client)
219
+ path = "/coupons"
220
+ data = {
221
+
222
+ }
223
+
224
+ response = Response.new(request.get(path, data, options))
225
+ return_values = Array.new
226
+
227
+ a = Array.new
228
+ body = response.body
229
+ for v in body['coupons']
230
+ tmp = Coupon.new(@client)
231
+ tmp.fill_with_data(v)
232
+ a.push(tmp)
233
+ end
234
+
235
+ return_values.push(a)
236
+
237
+
238
+
239
+ return_values[0]
240
+ end
241
+
242
+ # Create a new coupon.
243
+ # Params:
244
+ # +options+:: +Hash+ of options
245
+ def create(options = {})
246
+ self.prefill(options)
247
+
248
+ request = Request.new(@client)
249
+ path = "/coupons"
250
+ data = {
251
+ "id" => @id,
252
+ "amount_off" => @amount_off,
253
+ "percent_off" => @percent_off,
254
+ "currency" => @currency,
255
+ "iteration_count" => @iteration_count,
256
+ "max_redemptions" => @max_redemptions,
257
+ "expires_at" => @expires_at,
258
+ "metadata" => @metadata
259
+ }
260
+
261
+ response = Response.new(request.post(path, data, options))
262
+ return_values = Array.new
263
+
264
+ body = response.body
265
+ body = body["coupon"]
266
+
267
+
268
+ return_values.push(self.fill_with_data(body))
269
+
270
+
271
+
272
+ return_values[0]
273
+ end
274
+
275
+ # Find a coupon by its ID.
276
+ # Params:
277
+ # +coupon_id+:: ID of the coupon
278
+ # +options+:: +Hash+ of options
279
+ def find(coupon_id, options = {})
280
+ self.prefill(options)
281
+
282
+ request = Request.new(@client)
283
+ path = "/coupons/" + CGI.escape(coupon_id) + ""
284
+ data = {
285
+
286
+ }
287
+
288
+ response = Response.new(request.get(path, data, options))
289
+ return_values = Array.new
290
+
291
+ body = response.body
292
+ body = body["coupon"]
293
+
294
+
295
+ obj = Coupon.new(@client)
296
+ return_values.push(obj.fill_with_data(body))
297
+
298
+
299
+
300
+ return_values[0]
301
+ end
302
+
303
+ # Save the updated coupon attributes.
304
+ # Params:
305
+ # +options+:: +Hash+ of options
306
+ def save(options = {})
307
+ self.prefill(options)
308
+
309
+ request = Request.new(@client)
310
+ path = "/coupons/" + CGI.escape(@id) + ""
311
+ data = {
312
+ "metadata" => @metadata
313
+ }
314
+
315
+ response = Response.new(request.put(path, data, options))
316
+ return_values = Array.new
317
+
318
+ body = response.body
319
+ body = body["coupon"]
320
+
321
+
322
+ return_values.push(self.fill_with_data(body))
323
+
324
+
325
+
326
+ return_values[0]
327
+ end
328
+
329
+ # Delete the coupon.
330
+ # Params:
331
+ # +options+:: +Hash+ of options
332
+ def delete(options = {})
333
+ self.prefill(options)
334
+
335
+ request = Request.new(@client)
336
+ path = "/coupons/" + CGI.escape(@id) + ""
337
+ data = {
338
+
339
+ }
340
+
341
+ response = Response.new(request.delete(path, data, options))
342
+ return_values = Array.new
343
+
344
+ return_values.push(response.success)
345
+
346
+
347
+ return_values[0]
348
+ end
349
+
350
+
351
+ end
352
+ end