processout 2.20.0 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
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 +984 -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,984 @@
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 Invoice
10
+
11
+ attr_reader :id
12
+ attr_reader :project
13
+ attr_reader :project_id
14
+ attr_reader :transaction
15
+ attr_reader :transaction_id
16
+ attr_reader :customer
17
+ attr_reader :customer_id
18
+ attr_reader :subscription
19
+ attr_reader :subscription_id
20
+ attr_reader :token
21
+ attr_reader :token_id
22
+ attr_reader :details
23
+ attr_reader :url
24
+ attr_reader :name
25
+ attr_reader :amount
26
+ attr_reader :currency
27
+ attr_reader :merchant_initiator_type
28
+ attr_reader :statement_descriptor
29
+ attr_reader :statement_descriptor_phone
30
+ attr_reader :statement_descriptor_city
31
+ attr_reader :statement_descriptor_company
32
+ attr_reader :statement_descriptor_url
33
+ attr_reader :metadata
34
+ attr_reader :gateway_data
35
+ attr_reader :return_url
36
+ attr_reader :cancel_url
37
+ attr_reader :webhook_url
38
+ attr_reader :require_backend_capture
39
+ attr_reader :sandbox
40
+ attr_reader :created_at
41
+ attr_reader :risk
42
+ attr_reader :shipping
43
+ attr_reader :device
44
+ attr_reader :external_fraud_tools
45
+ attr_reader :exemption_reason_3ds2
46
+ attr_reader :sca_exemption_reason
47
+ attr_reader :challenge_indicator
48
+ attr_reader :incremental
49
+ attr_reader :tax
50
+ attr_reader :payment_type
51
+ attr_reader :initiation_type
52
+ attr_reader :payment_intent
53
+
54
+
55
+ def id=(val)
56
+ @id = val
57
+ end
58
+
59
+ def project=(val)
60
+ if val.nil?
61
+ @project = val
62
+ return
63
+ end
64
+
65
+ if val.instance_of? Project
66
+ @project = val
67
+ else
68
+ obj = Project.new(@client)
69
+ obj.fill_with_data(val)
70
+ @project = obj
71
+ end
72
+
73
+ end
74
+
75
+ def project_id=(val)
76
+ @project_id = val
77
+ end
78
+
79
+ def transaction=(val)
80
+ if val.nil?
81
+ @transaction = val
82
+ return
83
+ end
84
+
85
+ if val.instance_of? Transaction
86
+ @transaction = val
87
+ else
88
+ obj = Transaction.new(@client)
89
+ obj.fill_with_data(val)
90
+ @transaction = obj
91
+ end
92
+
93
+ end
94
+
95
+ def transaction_id=(val)
96
+ @transaction_id = val
97
+ end
98
+
99
+ def customer=(val)
100
+ if val.nil?
101
+ @customer = val
102
+ return
103
+ end
104
+
105
+ if val.instance_of? Customer
106
+ @customer = val
107
+ else
108
+ obj = Customer.new(@client)
109
+ obj.fill_with_data(val)
110
+ @customer = obj
111
+ end
112
+
113
+ end
114
+
115
+ def customer_id=(val)
116
+ @customer_id = val
117
+ end
118
+
119
+ def subscription=(val)
120
+ if val.nil?
121
+ @subscription = val
122
+ return
123
+ end
124
+
125
+ if val.instance_of? Subscription
126
+ @subscription = val
127
+ else
128
+ obj = Subscription.new(@client)
129
+ obj.fill_with_data(val)
130
+ @subscription = obj
131
+ end
132
+
133
+ end
134
+
135
+ def subscription_id=(val)
136
+ @subscription_id = val
137
+ end
138
+
139
+ def token=(val)
140
+ if val.nil?
141
+ @token = val
142
+ return
143
+ end
144
+
145
+ if val.instance_of? Token
146
+ @token = val
147
+ else
148
+ obj = Token.new(@client)
149
+ obj.fill_with_data(val)
150
+ @token = obj
151
+ end
152
+
153
+ end
154
+
155
+ def token_id=(val)
156
+ @token_id = val
157
+ end
158
+
159
+ def details=(val)
160
+ if val.nil?
161
+ @details = []
162
+ return
163
+ end
164
+
165
+ if val.length > 0 and val[0].instance_of? InvoiceDetail
166
+ @details = val
167
+ else
168
+ l = Array.new
169
+ for v in val
170
+ obj = InvoiceDetail.new(@client)
171
+ obj.fill_with_data(v)
172
+ l.push(obj)
173
+ end
174
+ @details = l
175
+ end
176
+
177
+ end
178
+
179
+ def url=(val)
180
+ @url = val
181
+ end
182
+
183
+ def name=(val)
184
+ @name = val
185
+ end
186
+
187
+ def amount=(val)
188
+ @amount = val
189
+ end
190
+
191
+ def currency=(val)
192
+ @currency = val
193
+ end
194
+
195
+ def merchant_initiator_type=(val)
196
+ @merchant_initiator_type = val
197
+ end
198
+
199
+ def statement_descriptor=(val)
200
+ @statement_descriptor = val
201
+ end
202
+
203
+ def statement_descriptor_phone=(val)
204
+ @statement_descriptor_phone = val
205
+ end
206
+
207
+ def statement_descriptor_city=(val)
208
+ @statement_descriptor_city = val
209
+ end
210
+
211
+ def statement_descriptor_company=(val)
212
+ @statement_descriptor_company = val
213
+ end
214
+
215
+ def statement_descriptor_url=(val)
216
+ @statement_descriptor_url = val
217
+ end
218
+
219
+ def metadata=(val)
220
+ @metadata = val
221
+ end
222
+
223
+ def gateway_data=(val)
224
+ @gateway_data = val
225
+ end
226
+
227
+ def return_url=(val)
228
+ @return_url = val
229
+ end
230
+
231
+ def cancel_url=(val)
232
+ @cancel_url = val
233
+ end
234
+
235
+ def webhook_url=(val)
236
+ @webhook_url = val
237
+ end
238
+
239
+ def require_backend_capture=(val)
240
+ @require_backend_capture = val
241
+ end
242
+
243
+ def sandbox=(val)
244
+ @sandbox = val
245
+ end
246
+
247
+ def created_at=(val)
248
+ @created_at = val
249
+ end
250
+
251
+ def risk=(val)
252
+ if val.nil?
253
+ @risk = val
254
+ return
255
+ end
256
+
257
+ if val.instance_of? InvoiceRisk
258
+ @risk = val
259
+ else
260
+ obj = InvoiceRisk.new(@client)
261
+ obj.fill_with_data(val)
262
+ @risk = obj
263
+ end
264
+
265
+ end
266
+
267
+ def shipping=(val)
268
+ if val.nil?
269
+ @shipping = val
270
+ return
271
+ end
272
+
273
+ if val.instance_of? InvoiceShipping
274
+ @shipping = val
275
+ else
276
+ obj = InvoiceShipping.new(@client)
277
+ obj.fill_with_data(val)
278
+ @shipping = obj
279
+ end
280
+
281
+ end
282
+
283
+ def device=(val)
284
+ if val.nil?
285
+ @device = val
286
+ return
287
+ end
288
+
289
+ if val.instance_of? InvoiceDevice
290
+ @device = val
291
+ else
292
+ obj = InvoiceDevice.new(@client)
293
+ obj.fill_with_data(val)
294
+ @device = obj
295
+ end
296
+
297
+ end
298
+
299
+ def external_fraud_tools=(val)
300
+ if val.nil?
301
+ @external_fraud_tools = val
302
+ return
303
+ end
304
+
305
+ if val.instance_of? InvoiceExternalFraudTools
306
+ @external_fraud_tools = val
307
+ else
308
+ obj = InvoiceExternalFraudTools.new(@client)
309
+ obj.fill_with_data(val)
310
+ @external_fraud_tools = obj
311
+ end
312
+
313
+ end
314
+
315
+ def exemption_reason_3ds2=(val)
316
+ @exemption_reason_3ds2 = val
317
+ end
318
+
319
+ def sca_exemption_reason=(val)
320
+ @sca_exemption_reason = val
321
+ end
322
+
323
+ def challenge_indicator=(val)
324
+ @challenge_indicator = val
325
+ end
326
+
327
+ def incremental=(val)
328
+ @incremental = val
329
+ end
330
+
331
+ def tax=(val)
332
+ if val.nil?
333
+ @tax = val
334
+ return
335
+ end
336
+
337
+ if val.instance_of? InvoiceTax
338
+ @tax = val
339
+ else
340
+ obj = InvoiceTax.new(@client)
341
+ obj.fill_with_data(val)
342
+ @tax = obj
343
+ end
344
+
345
+ end
346
+
347
+ def payment_type=(val)
348
+ @payment_type = val
349
+ end
350
+
351
+ def initiation_type=(val)
352
+ @initiation_type = val
353
+ end
354
+
355
+ def payment_intent=(val)
356
+ @payment_intent = val
357
+ end
358
+
359
+
360
+ # Initializes the Invoice object
361
+ # Params:
362
+ # +client+:: +ProcessOut+ client instance
363
+ # +data+:: data that can be used to fill the object
364
+ def initialize(client, data = {})
365
+ @client = client
366
+
367
+ self.id = data.fetch(:id, nil)
368
+ self.project = data.fetch(:project, nil)
369
+ self.project_id = data.fetch(:project_id, nil)
370
+ self.transaction = data.fetch(:transaction, nil)
371
+ self.transaction_id = data.fetch(:transaction_id, nil)
372
+ self.customer = data.fetch(:customer, nil)
373
+ self.customer_id = data.fetch(:customer_id, nil)
374
+ self.subscription = data.fetch(:subscription, nil)
375
+ self.subscription_id = data.fetch(:subscription_id, nil)
376
+ self.token = data.fetch(:token, nil)
377
+ self.token_id = data.fetch(:token_id, nil)
378
+ self.details = data.fetch(:details, nil)
379
+ self.url = data.fetch(:url, nil)
380
+ self.name = data.fetch(:name, nil)
381
+ self.amount = data.fetch(:amount, nil)
382
+ self.currency = data.fetch(:currency, nil)
383
+ self.merchant_initiator_type = data.fetch(:merchant_initiator_type, nil)
384
+ self.statement_descriptor = data.fetch(:statement_descriptor, nil)
385
+ self.statement_descriptor_phone = data.fetch(:statement_descriptor_phone, nil)
386
+ self.statement_descriptor_city = data.fetch(:statement_descriptor_city, nil)
387
+ self.statement_descriptor_company = data.fetch(:statement_descriptor_company, nil)
388
+ self.statement_descriptor_url = data.fetch(:statement_descriptor_url, nil)
389
+ self.metadata = data.fetch(:metadata, nil)
390
+ self.gateway_data = data.fetch(:gateway_data, nil)
391
+ self.return_url = data.fetch(:return_url, nil)
392
+ self.cancel_url = data.fetch(:cancel_url, nil)
393
+ self.webhook_url = data.fetch(:webhook_url, nil)
394
+ self.require_backend_capture = data.fetch(:require_backend_capture, nil)
395
+ self.sandbox = data.fetch(:sandbox, nil)
396
+ self.created_at = data.fetch(:created_at, nil)
397
+ self.risk = data.fetch(:risk, nil)
398
+ self.shipping = data.fetch(:shipping, nil)
399
+ self.device = data.fetch(:device, nil)
400
+ self.external_fraud_tools = data.fetch(:external_fraud_tools, nil)
401
+ self.exemption_reason_3ds2 = data.fetch(:exemption_reason_3ds2, nil)
402
+ self.sca_exemption_reason = data.fetch(:sca_exemption_reason, nil)
403
+ self.challenge_indicator = data.fetch(:challenge_indicator, nil)
404
+ self.incremental = data.fetch(:incremental, nil)
405
+ self.tax = data.fetch(:tax, nil)
406
+ self.payment_type = data.fetch(:payment_type, nil)
407
+ self.initiation_type = data.fetch(:initiation_type, nil)
408
+ self.payment_intent = data.fetch(:payment_intent, nil)
409
+
410
+ end
411
+
412
+ # Create a new Invoice using the current client
413
+ def new(data = {})
414
+ Invoice.new(@client, data)
415
+ end
416
+
417
+ # Overrides the JSON marshaller to only send the fields we want
418
+ def to_json(options)
419
+ {
420
+ "id": self.id,
421
+ "project": self.project,
422
+ "project_id": self.project_id,
423
+ "transaction": self.transaction,
424
+ "transaction_id": self.transaction_id,
425
+ "customer": self.customer,
426
+ "customer_id": self.customer_id,
427
+ "subscription": self.subscription,
428
+ "subscription_id": self.subscription_id,
429
+ "token": self.token,
430
+ "token_id": self.token_id,
431
+ "details": self.details,
432
+ "url": self.url,
433
+ "name": self.name,
434
+ "amount": self.amount,
435
+ "currency": self.currency,
436
+ "merchant_initiator_type": self.merchant_initiator_type,
437
+ "statement_descriptor": self.statement_descriptor,
438
+ "statement_descriptor_phone": self.statement_descriptor_phone,
439
+ "statement_descriptor_city": self.statement_descriptor_city,
440
+ "statement_descriptor_company": self.statement_descriptor_company,
441
+ "statement_descriptor_url": self.statement_descriptor_url,
442
+ "metadata": self.metadata,
443
+ "gateway_data": self.gateway_data,
444
+ "return_url": self.return_url,
445
+ "cancel_url": self.cancel_url,
446
+ "webhook_url": self.webhook_url,
447
+ "require_backend_capture": self.require_backend_capture,
448
+ "sandbox": self.sandbox,
449
+ "created_at": self.created_at,
450
+ "risk": self.risk,
451
+ "shipping": self.shipping,
452
+ "device": self.device,
453
+ "external_fraud_tools": self.external_fraud_tools,
454
+ "exemption_reason_3ds2": self.exemption_reason_3ds2,
455
+ "sca_exemption_reason": self.sca_exemption_reason,
456
+ "challenge_indicator": self.challenge_indicator,
457
+ "incremental": self.incremental,
458
+ "tax": self.tax,
459
+ "payment_type": self.payment_type,
460
+ "initiation_type": self.initiation_type,
461
+ "payment_intent": self.payment_intent,
462
+ }.to_json
463
+ end
464
+
465
+ # Fills the object with data coming from the API
466
+ # Params:
467
+ # +data+:: +Hash+ of data coming from the API
468
+ def fill_with_data(data)
469
+ if data.nil?
470
+ return self
471
+ end
472
+ if data.include? "id"
473
+ self.id = data["id"]
474
+ end
475
+ if data.include? "project"
476
+ self.project = data["project"]
477
+ end
478
+ if data.include? "project_id"
479
+ self.project_id = data["project_id"]
480
+ end
481
+ if data.include? "transaction"
482
+ self.transaction = data["transaction"]
483
+ end
484
+ if data.include? "transaction_id"
485
+ self.transaction_id = data["transaction_id"]
486
+ end
487
+ if data.include? "customer"
488
+ self.customer = data["customer"]
489
+ end
490
+ if data.include? "customer_id"
491
+ self.customer_id = data["customer_id"]
492
+ end
493
+ if data.include? "subscription"
494
+ self.subscription = data["subscription"]
495
+ end
496
+ if data.include? "subscription_id"
497
+ self.subscription_id = data["subscription_id"]
498
+ end
499
+ if data.include? "token"
500
+ self.token = data["token"]
501
+ end
502
+ if data.include? "token_id"
503
+ self.token_id = data["token_id"]
504
+ end
505
+ if data.include? "details"
506
+ self.details = data["details"]
507
+ end
508
+ if data.include? "url"
509
+ self.url = data["url"]
510
+ end
511
+ if data.include? "name"
512
+ self.name = data["name"]
513
+ end
514
+ if data.include? "amount"
515
+ self.amount = data["amount"]
516
+ end
517
+ if data.include? "currency"
518
+ self.currency = data["currency"]
519
+ end
520
+ if data.include? "merchant_initiator_type"
521
+ self.merchant_initiator_type = data["merchant_initiator_type"]
522
+ end
523
+ if data.include? "statement_descriptor"
524
+ self.statement_descriptor = data["statement_descriptor"]
525
+ end
526
+ if data.include? "statement_descriptor_phone"
527
+ self.statement_descriptor_phone = data["statement_descriptor_phone"]
528
+ end
529
+ if data.include? "statement_descriptor_city"
530
+ self.statement_descriptor_city = data["statement_descriptor_city"]
531
+ end
532
+ if data.include? "statement_descriptor_company"
533
+ self.statement_descriptor_company = data["statement_descriptor_company"]
534
+ end
535
+ if data.include? "statement_descriptor_url"
536
+ self.statement_descriptor_url = data["statement_descriptor_url"]
537
+ end
538
+ if data.include? "metadata"
539
+ self.metadata = data["metadata"]
540
+ end
541
+ if data.include? "gateway_data"
542
+ self.gateway_data = data["gateway_data"]
543
+ end
544
+ if data.include? "return_url"
545
+ self.return_url = data["return_url"]
546
+ end
547
+ if data.include? "cancel_url"
548
+ self.cancel_url = data["cancel_url"]
549
+ end
550
+ if data.include? "webhook_url"
551
+ self.webhook_url = data["webhook_url"]
552
+ end
553
+ if data.include? "require_backend_capture"
554
+ self.require_backend_capture = data["require_backend_capture"]
555
+ end
556
+ if data.include? "sandbox"
557
+ self.sandbox = data["sandbox"]
558
+ end
559
+ if data.include? "created_at"
560
+ self.created_at = data["created_at"]
561
+ end
562
+ if data.include? "risk"
563
+ self.risk = data["risk"]
564
+ end
565
+ if data.include? "shipping"
566
+ self.shipping = data["shipping"]
567
+ end
568
+ if data.include? "device"
569
+ self.device = data["device"]
570
+ end
571
+ if data.include? "external_fraud_tools"
572
+ self.external_fraud_tools = data["external_fraud_tools"]
573
+ end
574
+ if data.include? "exemption_reason_3ds2"
575
+ self.exemption_reason_3ds2 = data["exemption_reason_3ds2"]
576
+ end
577
+ if data.include? "sca_exemption_reason"
578
+ self.sca_exemption_reason = data["sca_exemption_reason"]
579
+ end
580
+ if data.include? "challenge_indicator"
581
+ self.challenge_indicator = data["challenge_indicator"]
582
+ end
583
+ if data.include? "incremental"
584
+ self.incremental = data["incremental"]
585
+ end
586
+ if data.include? "tax"
587
+ self.tax = data["tax"]
588
+ end
589
+ if data.include? "payment_type"
590
+ self.payment_type = data["payment_type"]
591
+ end
592
+ if data.include? "initiation_type"
593
+ self.initiation_type = data["initiation_type"]
594
+ end
595
+ if data.include? "payment_intent"
596
+ self.payment_intent = data["payment_intent"]
597
+ end
598
+
599
+ self
600
+ end
601
+
602
+ # Prefills the object with the data passed as parameters
603
+ # Params:
604
+ # +data+:: +Hash+ of data
605
+ def prefill(data)
606
+ if data.nil?
607
+ return self
608
+ end
609
+ self.id = data.fetch(:id, self.id)
610
+ self.project = data.fetch(:project, self.project)
611
+ self.project_id = data.fetch(:project_id, self.project_id)
612
+ self.transaction = data.fetch(:transaction, self.transaction)
613
+ self.transaction_id = data.fetch(:transaction_id, self.transaction_id)
614
+ self.customer = data.fetch(:customer, self.customer)
615
+ self.customer_id = data.fetch(:customer_id, self.customer_id)
616
+ self.subscription = data.fetch(:subscription, self.subscription)
617
+ self.subscription_id = data.fetch(:subscription_id, self.subscription_id)
618
+ self.token = data.fetch(:token, self.token)
619
+ self.token_id = data.fetch(:token_id, self.token_id)
620
+ self.details = data.fetch(:details, self.details)
621
+ self.url = data.fetch(:url, self.url)
622
+ self.name = data.fetch(:name, self.name)
623
+ self.amount = data.fetch(:amount, self.amount)
624
+ self.currency = data.fetch(:currency, self.currency)
625
+ self.merchant_initiator_type = data.fetch(:merchant_initiator_type, self.merchant_initiator_type)
626
+ self.statement_descriptor = data.fetch(:statement_descriptor, self.statement_descriptor)
627
+ self.statement_descriptor_phone = data.fetch(:statement_descriptor_phone, self.statement_descriptor_phone)
628
+ self.statement_descriptor_city = data.fetch(:statement_descriptor_city, self.statement_descriptor_city)
629
+ self.statement_descriptor_company = data.fetch(:statement_descriptor_company, self.statement_descriptor_company)
630
+ self.statement_descriptor_url = data.fetch(:statement_descriptor_url, self.statement_descriptor_url)
631
+ self.metadata = data.fetch(:metadata, self.metadata)
632
+ self.gateway_data = data.fetch(:gateway_data, self.gateway_data)
633
+ self.return_url = data.fetch(:return_url, self.return_url)
634
+ self.cancel_url = data.fetch(:cancel_url, self.cancel_url)
635
+ self.webhook_url = data.fetch(:webhook_url, self.webhook_url)
636
+ self.require_backend_capture = data.fetch(:require_backend_capture, self.require_backend_capture)
637
+ self.sandbox = data.fetch(:sandbox, self.sandbox)
638
+ self.created_at = data.fetch(:created_at, self.created_at)
639
+ self.risk = data.fetch(:risk, self.risk)
640
+ self.shipping = data.fetch(:shipping, self.shipping)
641
+ self.device = data.fetch(:device, self.device)
642
+ self.external_fraud_tools = data.fetch(:external_fraud_tools, self.external_fraud_tools)
643
+ self.exemption_reason_3ds2 = data.fetch(:exemption_reason_3ds2, self.exemption_reason_3ds2)
644
+ self.sca_exemption_reason = data.fetch(:sca_exemption_reason, self.sca_exemption_reason)
645
+ self.challenge_indicator = data.fetch(:challenge_indicator, self.challenge_indicator)
646
+ self.incremental = data.fetch(:incremental, self.incremental)
647
+ self.tax = data.fetch(:tax, self.tax)
648
+ self.payment_type = data.fetch(:payment_type, self.payment_type)
649
+ self.initiation_type = data.fetch(:initiation_type, self.initiation_type)
650
+ self.payment_intent = data.fetch(:payment_intent, self.payment_intent)
651
+
652
+ self
653
+ end
654
+
655
+ # Create an incremental authorization
656
+ # Params:
657
+ # +amount+:: Amount to increment authorization by
658
+ # +options+:: +Hash+ of options
659
+ def increment_authorization(amount, options = {})
660
+ self.prefill(options)
661
+
662
+ request = Request.new(@client)
663
+ path = "/invoices/" + CGI.escape(@id) + "/increment_authorization"
664
+ data = {
665
+ "metadata" => options.fetch(:metadata, nil),
666
+ "amount" => amount
667
+ }
668
+
669
+ response = Response.new(request.post(path, data, options))
670
+ return_values = Array.new
671
+
672
+ body = response.body
673
+ body = body["transaction"]
674
+ transaction = Transaction.new(@client)
675
+ return_values.push(transaction.fill_with_data(body))
676
+
677
+
678
+ return_values[0]
679
+ end
680
+
681
+ # Authorize the invoice using the given source (customer or token)
682
+ # Params:
683
+ # +source+:: Source used to authorization the payment. Can be a card, a token or a gateway request
684
+ # +options+:: +Hash+ of options
685
+ def authorize(source, options = {})
686
+ self.prefill(options)
687
+
688
+ request = Request.new(@client)
689
+ path = "/invoices/" + CGI.escape(@id) + "/authorize"
690
+ data = {
691
+ "device" => @device,
692
+ "incremental" => @incremental,
693
+ "synchronous" => options.fetch(:synchronous, nil),
694
+ "retry_drop_liability_shift" => options.fetch(:retry_drop_liability_shift, nil),
695
+ "capture_amount" => options.fetch(:capture_amount, nil),
696
+ "enable_three_d_s_2" => options.fetch(:enable_three_d_s_2, nil),
697
+ "auto_capture_at" => options.fetch(:auto_capture_at, nil),
698
+ "metadata" => options.fetch(:metadata, nil),
699
+ "source" => source
700
+ }
701
+
702
+ response = Response.new(request.post(path, data, options))
703
+ return_values = Array.new
704
+
705
+ body = response.body
706
+ body = body["transaction"]
707
+ transaction = Transaction.new(@client)
708
+ return_values.push(transaction.fill_with_data(body))
709
+
710
+
711
+ return_values[0]
712
+ end
713
+
714
+ # Capture the invoice using the given source (customer or token)
715
+ # Params:
716
+ # +source+:: Source used to authorization the payment. Can be a card, a token or a gateway request
717
+ # +options+:: +Hash+ of options
718
+ def capture(source, options = {})
719
+ self.prefill(options)
720
+
721
+ request = Request.new(@client)
722
+ path = "/invoices/" + CGI.escape(@id) + "/capture"
723
+ data = {
724
+ "device" => @device,
725
+ "incremental" => @incremental,
726
+ "authorize_only" => options.fetch(:authorize_only, nil),
727
+ "synchronous" => options.fetch(:synchronous, nil),
728
+ "retry_drop_liability_shift" => options.fetch(:retry_drop_liability_shift, nil),
729
+ "capture_amount" => options.fetch(:capture_amount, nil),
730
+ "auto_capture_at" => options.fetch(:auto_capture_at, nil),
731
+ "enable_three_d_s_2" => options.fetch(:enable_three_d_s_2, nil),
732
+ "metadata" => options.fetch(:metadata, nil),
733
+ "source" => source
734
+ }
735
+
736
+ response = Response.new(request.post(path, data, options))
737
+ return_values = Array.new
738
+
739
+ body = response.body
740
+ body = body["transaction"]
741
+ transaction = Transaction.new(@client)
742
+ return_values.push(transaction.fill_with_data(body))
743
+
744
+
745
+ return_values[0]
746
+ end
747
+
748
+ # Get the customer linked to the invoice.
749
+ # Params:
750
+ # +options+:: +Hash+ of options
751
+ def fetch_customer(options = {})
752
+ self.prefill(options)
753
+
754
+ request = Request.new(@client)
755
+ path = "/invoices/" + CGI.escape(@id) + "/customers"
756
+ data = {
757
+
758
+ }
759
+
760
+ response = Response.new(request.get(path, data, options))
761
+ return_values = Array.new
762
+
763
+ body = response.body
764
+ body = body["customer"]
765
+ customer = Customer.new(@client)
766
+ return_values.push(customer.fill_with_data(body))
767
+
768
+
769
+ return_values[0]
770
+ end
771
+
772
+ # Assign a customer to the invoice.
773
+ # Params:
774
+ # +customer_id+:: ID of the customer to be linked to the invoice
775
+ # +options+:: +Hash+ of options
776
+ def assign_customer(customer_id, options = {})
777
+ self.prefill(options)
778
+
779
+ request = Request.new(@client)
780
+ path = "/invoices/" + CGI.escape(@id) + "/customers"
781
+ data = {
782
+ "customer_id" => customer_id
783
+ }
784
+
785
+ response = Response.new(request.post(path, data, options))
786
+ return_values = Array.new
787
+
788
+ body = response.body
789
+ body = body["customer"]
790
+ customer = Customer.new(@client)
791
+ return_values.push(customer.fill_with_data(body))
792
+
793
+
794
+ return_values[0]
795
+ end
796
+
797
+ # Initiate a 3-D Secure authentication
798
+ # Params:
799
+ # +source+:: Source used to initiate the 3-D Secure authentication. Can be a card, or a token representing a card
800
+ # +options+:: +Hash+ of options
801
+ def initiate_three_d_s(source, options = {})
802
+ self.prefill(options)
803
+
804
+ request = Request.new(@client)
805
+ path = "/invoices/" + CGI.escape(@id) + "/three-d-s"
806
+ data = {
807
+ "enable_three_d_s_2" => options.fetch(:enable_three_d_s_2, nil),
808
+ "source" => source
809
+ }
810
+
811
+ response = Response.new(request.post(path, data, options))
812
+ return_values = Array.new
813
+
814
+ body = response.body
815
+ body = body["customer_action"]
816
+ customer_action = CustomerAction.new(@client)
817
+ return_values.push(customer_action.fill_with_data(body))
818
+
819
+
820
+ return_values[0]
821
+ end
822
+
823
+ # Get the transaction of the invoice.
824
+ # Params:
825
+ # +options+:: +Hash+ of options
826
+ def fetch_transaction(options = {})
827
+ self.prefill(options)
828
+
829
+ request = Request.new(@client)
830
+ path = "/invoices/" + CGI.escape(@id) + "/transactions"
831
+ data = {
832
+
833
+ }
834
+
835
+ response = Response.new(request.get(path, data, options))
836
+ return_values = Array.new
837
+
838
+ body = response.body
839
+ body = body["transaction"]
840
+ transaction = Transaction.new(@client)
841
+ return_values.push(transaction.fill_with_data(body))
842
+
843
+
844
+ return_values[0]
845
+ end
846
+
847
+ # Void the invoice
848
+ # Params:
849
+ # +options+:: +Hash+ of options
850
+ def void(options = {})
851
+ self.prefill(options)
852
+
853
+ request = Request.new(@client)
854
+ path = "/invoices/" + CGI.escape(@id) + "/void"
855
+ data = {
856
+ "metadata" => options.fetch(:metadata, nil)
857
+ }
858
+
859
+ response = Response.new(request.post(path, data, options))
860
+ return_values = Array.new
861
+
862
+ body = response.body
863
+ body = body["transaction"]
864
+ transaction = Transaction.new(@client)
865
+ return_values.push(transaction.fill_with_data(body))
866
+
867
+
868
+ return_values[0]
869
+ end
870
+
871
+ # Get all the invoices.
872
+ # Params:
873
+ # +options+:: +Hash+ of options
874
+ def all(options = {})
875
+ self.prefill(options)
876
+
877
+ request = Request.new(@client)
878
+ path = "/invoices"
879
+ data = {
880
+
881
+ }
882
+
883
+ response = Response.new(request.get(path, data, options))
884
+ return_values = Array.new
885
+
886
+ a = Array.new
887
+ body = response.body
888
+ for v in body['invoices']
889
+ tmp = Invoice.new(@client)
890
+ tmp.fill_with_data(v)
891
+ a.push(tmp)
892
+ end
893
+
894
+ return_values.push(a)
895
+
896
+
897
+
898
+ return_values[0]
899
+ end
900
+
901
+ # Create a new invoice.
902
+ # Params:
903
+ # +options+:: +Hash+ of options
904
+ def create(options = {})
905
+ self.prefill(options)
906
+
907
+ request = Request.new(@client)
908
+ path = "/invoices"
909
+ data = {
910
+ "customer_id" => @customer_id,
911
+ "name" => @name,
912
+ "amount" => @amount,
913
+ "currency" => @currency,
914
+ "metadata" => @metadata,
915
+ "details" => @details,
916
+ "exemption_reason_3ds2" => @exemption_reason_3ds2,
917
+ "sca_exemption_reason" => @sca_exemption_reason,
918
+ "challenge_indicator" => @challenge_indicator,
919
+ "gateway_data" => @gateway_data,
920
+ "merchant_initiator_type" => @merchant_initiator_type,
921
+ "initiation_type" => @initiation_type,
922
+ "payment_intent" => @payment_intent,
923
+ "statement_descriptor" => @statement_descriptor,
924
+ "statement_descriptor_phone" => @statement_descriptor_phone,
925
+ "statement_descriptor_city" => @statement_descriptor_city,
926
+ "statement_descriptor_company" => @statement_descriptor_company,
927
+ "statement_descriptor_url" => @statement_descriptor_url,
928
+ "return_url" => @return_url,
929
+ "cancel_url" => @cancel_url,
930
+ "webhook_url" => @webhook_url,
931
+ "risk" => @risk,
932
+ "shipping" => @shipping,
933
+ "device" => @device,
934
+ "require_backend_capture" => @require_backend_capture,
935
+ "external_fraud_tools" => @external_fraud_tools,
936
+ "tax" => @tax,
937
+ "payment_type" => @payment_type
938
+ }
939
+
940
+ response = Response.new(request.post(path, data, options))
941
+ return_values = Array.new
942
+
943
+ body = response.body
944
+ body = body["invoice"]
945
+
946
+
947
+ return_values.push(self.fill_with_data(body))
948
+
949
+
950
+
951
+ return_values[0]
952
+ end
953
+
954
+ # Find an invoice by its ID.
955
+ # Params:
956
+ # +invoice_id+:: ID of the invoice
957
+ # +options+:: +Hash+ of options
958
+ def find(invoice_id, options = {})
959
+ self.prefill(options)
960
+
961
+ request = Request.new(@client)
962
+ path = "/invoices/" + CGI.escape(invoice_id) + ""
963
+ data = {
964
+
965
+ }
966
+
967
+ response = Response.new(request.get(path, data, options))
968
+ return_values = Array.new
969
+
970
+ body = response.body
971
+ body = body["invoice"]
972
+
973
+
974
+ obj = Invoice.new(@client)
975
+ return_values.push(obj.fill_with_data(body))
976
+
977
+
978
+
979
+ return_values[0]
980
+ end
981
+
982
+
983
+ end
984
+ end