processout 2.20.0 → 2.22.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 +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,985 @@
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
+ "allow_fallback_to_sale" => options.fetch(:allow_fallback_to_sale, nil),
698
+ "auto_capture_at" => options.fetch(:auto_capture_at, nil),
699
+ "metadata" => options.fetch(:metadata, nil),
700
+ "source" => source
701
+ }
702
+
703
+ response = Response.new(request.post(path, data, options))
704
+ return_values = Array.new
705
+
706
+ body = response.body
707
+ body = body["transaction"]
708
+ transaction = Transaction.new(@client)
709
+ return_values.push(transaction.fill_with_data(body))
710
+
711
+
712
+ return_values[0]
713
+ end
714
+
715
+ # Capture the invoice using the given source (customer or token)
716
+ # Params:
717
+ # +source+:: Source used to authorization the payment. Can be a card, a token or a gateway request
718
+ # +options+:: +Hash+ of options
719
+ def capture(source, options = {})
720
+ self.prefill(options)
721
+
722
+ request = Request.new(@client)
723
+ path = "/invoices/" + CGI.escape(@id) + "/capture"
724
+ data = {
725
+ "device" => @device,
726
+ "incremental" => @incremental,
727
+ "authorize_only" => options.fetch(:authorize_only, nil),
728
+ "synchronous" => options.fetch(:synchronous, nil),
729
+ "retry_drop_liability_shift" => options.fetch(:retry_drop_liability_shift, nil),
730
+ "capture_amount" => options.fetch(:capture_amount, nil),
731
+ "auto_capture_at" => options.fetch(:auto_capture_at, nil),
732
+ "enable_three_d_s_2" => options.fetch(:enable_three_d_s_2, nil),
733
+ "metadata" => options.fetch(:metadata, nil),
734
+ "source" => source
735
+ }
736
+
737
+ response = Response.new(request.post(path, data, options))
738
+ return_values = Array.new
739
+
740
+ body = response.body
741
+ body = body["transaction"]
742
+ transaction = Transaction.new(@client)
743
+ return_values.push(transaction.fill_with_data(body))
744
+
745
+
746
+ return_values[0]
747
+ end
748
+
749
+ # Get the customer linked to the invoice.
750
+ # Params:
751
+ # +options+:: +Hash+ of options
752
+ def fetch_customer(options = {})
753
+ self.prefill(options)
754
+
755
+ request = Request.new(@client)
756
+ path = "/invoices/" + CGI.escape(@id) + "/customers"
757
+ data = {
758
+
759
+ }
760
+
761
+ response = Response.new(request.get(path, data, options))
762
+ return_values = Array.new
763
+
764
+ body = response.body
765
+ body = body["customer"]
766
+ customer = Customer.new(@client)
767
+ return_values.push(customer.fill_with_data(body))
768
+
769
+
770
+ return_values[0]
771
+ end
772
+
773
+ # Assign a customer to the invoice.
774
+ # Params:
775
+ # +customer_id+:: ID of the customer to be linked to the invoice
776
+ # +options+:: +Hash+ of options
777
+ def assign_customer(customer_id, options = {})
778
+ self.prefill(options)
779
+
780
+ request = Request.new(@client)
781
+ path = "/invoices/" + CGI.escape(@id) + "/customers"
782
+ data = {
783
+ "customer_id" => customer_id
784
+ }
785
+
786
+ response = Response.new(request.post(path, data, options))
787
+ return_values = Array.new
788
+
789
+ body = response.body
790
+ body = body["customer"]
791
+ customer = Customer.new(@client)
792
+ return_values.push(customer.fill_with_data(body))
793
+
794
+
795
+ return_values[0]
796
+ end
797
+
798
+ # Initiate a 3-D Secure authentication
799
+ # Params:
800
+ # +source+:: Source used to initiate the 3-D Secure authentication. Can be a card, or a token representing a card
801
+ # +options+:: +Hash+ of options
802
+ def initiate_three_d_s(source, options = {})
803
+ self.prefill(options)
804
+
805
+ request = Request.new(@client)
806
+ path = "/invoices/" + CGI.escape(@id) + "/three-d-s"
807
+ data = {
808
+ "enable_three_d_s_2" => options.fetch(:enable_three_d_s_2, nil),
809
+ "source" => source
810
+ }
811
+
812
+ response = Response.new(request.post(path, data, options))
813
+ return_values = Array.new
814
+
815
+ body = response.body
816
+ body = body["customer_action"]
817
+ customer_action = CustomerAction.new(@client)
818
+ return_values.push(customer_action.fill_with_data(body))
819
+
820
+
821
+ return_values[0]
822
+ end
823
+
824
+ # Get the transaction of the invoice.
825
+ # Params:
826
+ # +options+:: +Hash+ of options
827
+ def fetch_transaction(options = {})
828
+ self.prefill(options)
829
+
830
+ request = Request.new(@client)
831
+ path = "/invoices/" + CGI.escape(@id) + "/transactions"
832
+ data = {
833
+
834
+ }
835
+
836
+ response = Response.new(request.get(path, data, options))
837
+ return_values = Array.new
838
+
839
+ body = response.body
840
+ body = body["transaction"]
841
+ transaction = Transaction.new(@client)
842
+ return_values.push(transaction.fill_with_data(body))
843
+
844
+
845
+ return_values[0]
846
+ end
847
+
848
+ # Void the invoice
849
+ # Params:
850
+ # +options+:: +Hash+ of options
851
+ def void(options = {})
852
+ self.prefill(options)
853
+
854
+ request = Request.new(@client)
855
+ path = "/invoices/" + CGI.escape(@id) + "/void"
856
+ data = {
857
+ "metadata" => options.fetch(:metadata, nil)
858
+ }
859
+
860
+ response = Response.new(request.post(path, data, options))
861
+ return_values = Array.new
862
+
863
+ body = response.body
864
+ body = body["transaction"]
865
+ transaction = Transaction.new(@client)
866
+ return_values.push(transaction.fill_with_data(body))
867
+
868
+
869
+ return_values[0]
870
+ end
871
+
872
+ # Get all the invoices.
873
+ # Params:
874
+ # +options+:: +Hash+ of options
875
+ def all(options = {})
876
+ self.prefill(options)
877
+
878
+ request = Request.new(@client)
879
+ path = "/invoices"
880
+ data = {
881
+
882
+ }
883
+
884
+ response = Response.new(request.get(path, data, options))
885
+ return_values = Array.new
886
+
887
+ a = Array.new
888
+ body = response.body
889
+ for v in body['invoices']
890
+ tmp = Invoice.new(@client)
891
+ tmp.fill_with_data(v)
892
+ a.push(tmp)
893
+ end
894
+
895
+ return_values.push(a)
896
+
897
+
898
+
899
+ return_values[0]
900
+ end
901
+
902
+ # Create a new invoice.
903
+ # Params:
904
+ # +options+:: +Hash+ of options
905
+ def create(options = {})
906
+ self.prefill(options)
907
+
908
+ request = Request.new(@client)
909
+ path = "/invoices"
910
+ data = {
911
+ "customer_id" => @customer_id,
912
+ "name" => @name,
913
+ "amount" => @amount,
914
+ "currency" => @currency,
915
+ "metadata" => @metadata,
916
+ "details" => @details,
917
+ "exemption_reason_3ds2" => @exemption_reason_3ds2,
918
+ "sca_exemption_reason" => @sca_exemption_reason,
919
+ "challenge_indicator" => @challenge_indicator,
920
+ "gateway_data" => @gateway_data,
921
+ "merchant_initiator_type" => @merchant_initiator_type,
922
+ "initiation_type" => @initiation_type,
923
+ "payment_intent" => @payment_intent,
924
+ "statement_descriptor" => @statement_descriptor,
925
+ "statement_descriptor_phone" => @statement_descriptor_phone,
926
+ "statement_descriptor_city" => @statement_descriptor_city,
927
+ "statement_descriptor_company" => @statement_descriptor_company,
928
+ "statement_descriptor_url" => @statement_descriptor_url,
929
+ "return_url" => @return_url,
930
+ "cancel_url" => @cancel_url,
931
+ "webhook_url" => @webhook_url,
932
+ "risk" => @risk,
933
+ "shipping" => @shipping,
934
+ "device" => @device,
935
+ "require_backend_capture" => @require_backend_capture,
936
+ "external_fraud_tools" => @external_fraud_tools,
937
+ "tax" => @tax,
938
+ "payment_type" => @payment_type
939
+ }
940
+
941
+ response = Response.new(request.post(path, data, options))
942
+ return_values = Array.new
943
+
944
+ body = response.body
945
+ body = body["invoice"]
946
+
947
+
948
+ return_values.push(self.fill_with_data(body))
949
+
950
+
951
+
952
+ return_values[0]
953
+ end
954
+
955
+ # Find an invoice by its ID.
956
+ # Params:
957
+ # +invoice_id+:: ID of the invoice
958
+ # +options+:: +Hash+ of options
959
+ def find(invoice_id, options = {})
960
+ self.prefill(options)
961
+
962
+ request = Request.new(@client)
963
+ path = "/invoices/" + CGI.escape(invoice_id) + ""
964
+ data = {
965
+
966
+ }
967
+
968
+ response = Response.new(request.get(path, data, options))
969
+ return_values = Array.new
970
+
971
+ body = response.body
972
+ body = body["invoice"]
973
+
974
+
975
+ obj = Invoice.new(@client)
976
+ return_values.push(obj.fill_with_data(body))
977
+
978
+
979
+
980
+ return_values[0]
981
+ end
982
+
983
+
984
+ end
985
+ end