Class: AdvancedBilling::Invoice

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/invoice.rb

Overview

Invoice Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(id = SKIP, uid = SKIP, site_id = SKIP, customer_id = SKIP, subscription_id = SKIP, number = SKIP, sequence_number = SKIP, transaction_time = SKIP, created_at = SKIP, updated_at = SKIP, issue_date = SKIP, due_date = SKIP, paid_date = SKIP, status = SKIP, role = SKIP, parent_invoice_id = SKIP, collection_method = SKIP, payment_instructions = SKIP, currency = SKIP, consolidation_level = SKIP, parent_invoice_uid = SKIP, subscription_group_id = SKIP, parent_invoice_number = SKIP, group_primary_subscription_id = SKIP, product_name = SKIP, product_family_name = SKIP, seller = SKIP, customer = SKIP, payer = SKIP, recipient_emails = SKIP, net_terms = SKIP, memo = SKIP, billing_address = SKIP, shipping_address = SKIP, subtotal_amount = SKIP, discount_amount = SKIP, tax_amount = SKIP, total_amount = SKIP, credit_amount = SKIP, refund_amount = SKIP, paid_amount = SKIP, due_amount = SKIP, line_items = SKIP, discounts = SKIP, taxes = SKIP, credits = SKIP, refunds = SKIP, payments = SKIP, custom_fields = SKIP, display_settings = SKIP, public_url = SKIP, previous_balance_data = SKIP) ⇒ Invoice

Returns a new instance of Invoice.



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/advanced_billing/models/invoice.rb', line 406

def initialize(id = SKIP, uid = SKIP, site_id = SKIP, customer_id = SKIP,
               subscription_id = SKIP, number = SKIP,
               sequence_number = SKIP, transaction_time = SKIP,
               created_at = SKIP, updated_at = SKIP, issue_date = SKIP,
               due_date = SKIP, paid_date = SKIP, status = SKIP,
               role = SKIP, parent_invoice_id = SKIP,
               collection_method = SKIP, payment_instructions = SKIP,
               currency = SKIP, consolidation_level = SKIP,
               parent_invoice_uid = SKIP, subscription_group_id = SKIP,
               parent_invoice_number = SKIP,
               group_primary_subscription_id = SKIP, product_name = SKIP,
               product_family_name = SKIP, seller = SKIP, customer = SKIP,
               payer = SKIP, recipient_emails = SKIP, net_terms = SKIP,
               memo = SKIP, billing_address = SKIP, shipping_address = SKIP,
               subtotal_amount = SKIP, discount_amount = SKIP,
               tax_amount = SKIP, total_amount = SKIP, credit_amount = SKIP,
               refund_amount = SKIP, paid_amount = SKIP, due_amount = SKIP,
               line_items = SKIP, discounts = SKIP, taxes = SKIP,
               credits = SKIP, refunds = SKIP, payments = SKIP,
               custom_fields = SKIP, display_settings = SKIP,
               public_url = SKIP, previous_balance_data = SKIP)
  @id = id unless id == SKIP
  @uid = uid unless uid == SKIP
  @site_id = site_id unless site_id == SKIP
  @customer_id = customer_id unless customer_id == SKIP
  @subscription_id = subscription_id unless subscription_id == SKIP
  @number = number unless number == SKIP
  @sequence_number = sequence_number unless sequence_number == SKIP
  @transaction_time = transaction_time unless transaction_time == SKIP
  @created_at = created_at unless created_at == SKIP
  @updated_at = updated_at unless updated_at == SKIP
  @issue_date = issue_date unless issue_date == SKIP
  @due_date = due_date unless due_date == SKIP
  @paid_date = paid_date unless paid_date == SKIP
  @status = status unless status == SKIP
  @role = role unless role == SKIP
  @parent_invoice_id = parent_invoice_id unless parent_invoice_id == SKIP
  @collection_method = collection_method unless collection_method == SKIP
  @payment_instructions = payment_instructions unless payment_instructions == SKIP
  @currency = currency unless currency == SKIP
  @consolidation_level = consolidation_level unless consolidation_level == SKIP
  @parent_invoice_uid = parent_invoice_uid unless parent_invoice_uid == SKIP
  @subscription_group_id = subscription_group_id unless subscription_group_id == SKIP
  @parent_invoice_number = parent_invoice_number unless parent_invoice_number == SKIP
  unless group_primary_subscription_id == SKIP
    @group_primary_subscription_id =
      group_primary_subscription_id
  end
  @product_name = product_name unless product_name == SKIP
  @product_family_name = product_family_name unless product_family_name == SKIP
  @seller = seller unless seller == SKIP
  @customer = customer unless customer == SKIP
  @payer = payer unless payer == SKIP
  @recipient_emails = recipient_emails unless recipient_emails == SKIP
  @net_terms = net_terms unless net_terms == SKIP
  @memo = memo unless memo == SKIP
  @billing_address = billing_address unless billing_address == SKIP
  @shipping_address = shipping_address unless shipping_address == SKIP
  @subtotal_amount = subtotal_amount unless subtotal_amount == SKIP
  @discount_amount = discount_amount unless discount_amount == SKIP
  @tax_amount = tax_amount unless tax_amount == SKIP
  @total_amount = total_amount unless total_amount == SKIP
  @credit_amount = credit_amount unless credit_amount == SKIP
  @refund_amount = refund_amount unless refund_amount == SKIP
  @paid_amount = paid_amount unless paid_amount == SKIP
  @due_amount = due_amount unless due_amount == SKIP
  @line_items = line_items unless line_items == SKIP
  @discounts = discounts unless discounts == SKIP
  @taxes = taxes unless taxes == SKIP
  @credits = credits unless credits == SKIP
  @refunds = refunds unless refunds == SKIP
  @payments = payments unless payments == SKIP
  @custom_fields = custom_fields unless custom_fields == SKIP
  @display_settings = display_settings unless display_settings == SKIP
  @public_url = public_url unless public_url == SKIP
  @previous_balance_data = previous_balance_data unless previous_balance_data == SKIP
end

Instance Attribute Details

#billing_addressInvoiceAddress

The invoice billing address.

Returns:



194
195
196
# File 'lib/advanced_billing/models/invoice.rb', line 194

def billing_address
  @billing_address
end

#collection_methodString

The collection method of the invoice, which is either “automatic” (tried and retried on an existing payment method by Chargify) or “remittance” (payment must be remitted by the customer or keyed in by the merchant).

Returns:

  • (String)


105
106
107
# File 'lib/advanced_billing/models/invoice.rb', line 105

def collection_method
  @collection_method
end

#consolidation_levelInvoiceConsolidationLevel

Consolidation level of the invoice, which is applicable to invoice consolidation. It will hold one of the following values:

  • “none”: A normal invoice with no consolidation.

  • “child”: An invoice segment which has been combined into a consolidated

invoice.

  • “parent”: A consolidated invoice, whose contents are composed of invoice

segments. “Parent” invoices do not have lines of their own, but they have subtotals and totals which aggregate the member invoice segments. See also the [invoice consolidation documentation](chargify.zendesk.com/hc/en-us/articles/440774639183 5).



131
132
133
# File 'lib/advanced_billing/models/invoice.rb', line 131

def consolidation_level
  @consolidation_level
end

#created_atDateTime

A monotonically increasing number assigned to invoices as they are created. This number is unique within a site and can be used to sort and order invoices.

Returns:

  • (DateTime)


57
58
59
# File 'lib/advanced_billing/models/invoice.rb', line 57

def created_at
  @created_at
end

#credit_amountString

The amount of credit (from credit notes) applied to this invoice. Credits offset the amount due from the customer.

Returns:

  • (String)


221
222
223
# File 'lib/advanced_billing/models/invoice.rb', line 221

def credit_amount
  @credit_amount
end

#creditsArray[InvoiceCredit]

Line items on the invoice.

Returns:



251
252
253
# File 'lib/advanced_billing/models/invoice.rb', line 251

def credits
  @credits
end

#currencyString

The ISO 4217 currency code (3 character string) representing the currency of invoice transaction.

Returns:

  • (String)


116
117
118
# File 'lib/advanced_billing/models/invoice.rb', line 116

def currency
  @currency
end

#custom_fieldsArray[InvoiceCustomField]

Line items on the invoice.

Returns:



263
264
265
# File 'lib/advanced_billing/models/invoice.rb', line 263

def custom_fields
  @custom_fields
end

#customerInvoiceCustomer

Information about the customer who is owner or recipient the invoiced subscription.

Returns:



170
171
172
# File 'lib/advanced_billing/models/invoice.rb', line 170

def customer
  @customer
end

#customer_idInteger

ID of the customer to which the invoice belongs.

Returns:

  • (Integer)


28
29
30
# File 'lib/advanced_billing/models/invoice.rb', line 28

def customer_id
  @customer_id
end

#discount_amountString

Total discount applied to the invoice.

Returns:

  • (String)


207
208
209
# File 'lib/advanced_billing/models/invoice.rb', line 207

def discount_amount
  @discount_amount
end

#discountsArray[InvoiceDiscount]

Line items on the invoice.

Returns:



243
244
245
# File 'lib/advanced_billing/models/invoice.rb', line 243

def discounts
  @discounts
end

#display_settingsInvoiceDisplaySettings

Line items on the invoice.



267
268
269
# File 'lib/advanced_billing/models/invoice.rb', line 267

def display_settings
  @display_settings
end

#due_amountString

Amount due on the invoice, which is ‘total_amount - credit_amount - paid_amount`.

Returns:

  • (String)


235
236
237
# File 'lib/advanced_billing/models/invoice.rb', line 235

def due_amount
  @due_amount
end

#due_dateString

Date the invoice is due. The format is ‘“YYYY-MM-DD”`.

Returns:

  • (String)


74
75
76
# File 'lib/advanced_billing/models/invoice.rb', line 74

def due_date
  @due_date
end

#group_primary_subscription_idInteger

For invoices with ‘consolidation_level` of `parent`, this specifies the ID of the subscription which was the primary subscription of the subscription group that generated the invoice.

Returns:

  • (Integer)


152
153
154
# File 'lib/advanced_billing/models/invoice.rb', line 152

def group_primary_subscription_id
  @group_primary_subscription_id
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


15
16
17
# File 'lib/advanced_billing/models/invoice.rb', line 15

def id
  @id
end

#issue_dateString

Date the invoice was issued to the customer. This is the date that the invoice was made available for payment. The format is ‘“YYYY-MM-DD”`.

Returns:

  • (String)


69
70
71
# File 'lib/advanced_billing/models/invoice.rb', line 69

def issue_date
  @issue_date
end

#line_itemsArray[InvoiceLineItem]

Line items on the invoice.

Returns:



239
240
241
# File 'lib/advanced_billing/models/invoice.rb', line 239

def line_items
  @line_items
end

#memoString

The memo printed on invoices of any collection type. This message is in control of the merchant.

Returns:

  • (String)


190
191
192
# File 'lib/advanced_billing/models/invoice.rb', line 190

def memo
  @memo
end

#net_termsInteger

Information about the customer who is owner or recipient the invoiced subscription.

Returns:

  • (Integer)


185
186
187
# File 'lib/advanced_billing/models/invoice.rb', line 185

def net_terms
  @net_terms
end

#numberString

A unique, identifying string that appears on the invoice and in places the invoice is referenced. While the UID is long and not appropriate to show to customers, the number is usually shorter and consumable by the customer and the merchant alike.

Returns:

  • (String)


39
40
41
# File 'lib/advanced_billing/models/invoice.rb', line 39

def number
  @number
end

The amount paid on the invoice by the customer.

Returns:

  • (String)


230
231
232
# File 'lib/advanced_billing/models/invoice.rb', line 230

def paid_amount
  @paid_amount
end

Date the invoice became fully paid. If partial payments are applied to the invoice, this date will not be present until payment has been made in full. The format is ‘“YYYY-MM-DD”`.

Returns:

  • (String)


81
82
83
# File 'lib/advanced_billing/models/invoice.rb', line 81

def paid_date
  @paid_date
end

#parent_invoice_idInteger

The current status of the invoice. See [Invoice Statuses](chargify.zendesk.com/hc/en-us/articles/4407737494171#lin e-item-breakdowns) for more.

Returns:

  • (Integer)


99
100
101
# File 'lib/advanced_billing/models/invoice.rb', line 99

def parent_invoice_id
  @parent_invoice_id
end

#parent_invoice_numberInteger

For invoices with ‘consolidation_level` of `child`, this specifies the number of the parent (consolidated) invoice.

Returns:

  • (Integer)


146
147
148
# File 'lib/advanced_billing/models/invoice.rb', line 146

def parent_invoice_number
  @parent_invoice_number
end

#parent_invoice_uidString

For invoices with ‘consolidation_level` of `child`, this specifies the UID of the parent (consolidated) invoice.

Returns:

  • (String)


136
137
138
# File 'lib/advanced_billing/models/invoice.rb', line 136

def parent_invoice_uid
  @parent_invoice_uid
end

#payerInvoicePayer

Information about the customer who is owner or recipient the invoiced subscription.

Returns:



175
176
177
# File 'lib/advanced_billing/models/invoice.rb', line 175

def payer
  @payer
end

#payment_instructionsString

A message that is printed on the invoice when it is marked for remittance collection. It is intended to describe to the customer how they may make payment, and is configured by the merchant.

Returns:

  • (String)


111
112
113
# File 'lib/advanced_billing/models/invoice.rb', line 111

def payment_instructions
  @payment_instructions
end

#paymentsArray[InvoicePayment]

Line items on the invoice.

Returns:



259
260
261
# File 'lib/advanced_billing/models/invoice.rb', line 259

def payments
  @payments
end

#previous_balance_dataInvoicePreviousBalance

The public URL of the invoice



275
276
277
# File 'lib/advanced_billing/models/invoice.rb', line 275

def previous_balance_data
  @previous_balance_data
end

#product_family_nameString

The name of the product family subscribed when the invoice was generated.

Returns:

  • (String)


160
161
162
# File 'lib/advanced_billing/models/invoice.rb', line 160

def product_family_name
  @product_family_name
end

#product_nameString

The name of the product subscribed when the invoice was generated.

Returns:

  • (String)


156
157
158
# File 'lib/advanced_billing/models/invoice.rb', line 156

def product_name
  @product_name
end

#public_urlString

The public URL of the invoice

Returns:

  • (String)


271
272
273
# File 'lib/advanced_billing/models/invoice.rb', line 271

def public_url
  @public_url
end

#recipient_emailsArray[String]

Information about the customer who is owner or recipient the invoiced subscription.

Returns:

  • (Array[String])


180
181
182
# File 'lib/advanced_billing/models/invoice.rb', line 180

def recipient_emails
  @recipient_emails
end

#refund_amountString

The amount of credit (from credit notes) applied to this invoice. Credits offset the amount due from the customer.

Returns:

  • (String)


226
227
228
# File 'lib/advanced_billing/models/invoice.rb', line 226

def refund_amount
  @refund_amount
end

#refundsArray[InvoiceRefund]

Line items on the invoice.

Returns:



255
256
257
# File 'lib/advanced_billing/models/invoice.rb', line 255

def refunds
  @refunds
end

#roleString

The current status of the invoice. See [Invoice Statuses](chargify.zendesk.com/hc/en-us/articles/4407737494171#lin e-item-breakdowns) for more.

Returns:

  • (String)


93
94
95
# File 'lib/advanced_billing/models/invoice.rb', line 93

def role
  @role
end

#sellerInvoiceSeller

Information about the seller (merchant) listed on the masthead of the invoice.

Returns:



165
166
167
# File 'lib/advanced_billing/models/invoice.rb', line 165

def seller
  @seller
end

#sequence_numberInteger

A monotonically increasing number assigned to invoices as they are created. This number is unique within a site and can be used to sort and order invoices.

Returns:

  • (Integer)


45
46
47
# File 'lib/advanced_billing/models/invoice.rb', line 45

def sequence_number
  @sequence_number
end

#shipping_addressInvoiceAddress

The invoice shipping address.

Returns:



198
199
200
# File 'lib/advanced_billing/models/invoice.rb', line 198

def shipping_address
  @shipping_address
end

#site_idInteger

ID of the site to which the invoice belongs.

Returns:

  • (Integer)


24
25
26
# File 'lib/advanced_billing/models/invoice.rb', line 24

def site_id
  @site_id
end

#statusStatus

The current status of the invoice. See [Invoice Statuses](chargify.zendesk.com/hc/en-us/articles/4407737494171#lin e-item-breakdowns) for more.

Returns:



87
88
89
# File 'lib/advanced_billing/models/invoice.rb', line 87

def status
  @status
end

#subscription_group_idInteger

For invoices with ‘consolidation_level` of `child`, this specifies the UID of the parent (consolidated) invoice.

Returns:

  • (Integer)


141
142
143
# File 'lib/advanced_billing/models/invoice.rb', line 141

def subscription_group_id
  @subscription_group_id
end

#subscription_idInteger

ID of the subscription that generated the invoice.

Returns:

  • (Integer)


32
33
34
# File 'lib/advanced_billing/models/invoice.rb', line 32

def subscription_id
  @subscription_id
end

#subtotal_amountString

Subtotal of the invoice, which is the sum of all line items before discounts or taxes.

Returns:

  • (String)


203
204
205
# File 'lib/advanced_billing/models/invoice.rb', line 203

def subtotal_amount
  @subtotal_amount
end

#tax_amountString

Total tax on the invoice.

Returns:

  • (String)


211
212
213
# File 'lib/advanced_billing/models/invoice.rb', line 211

def tax_amount
  @tax_amount
end

#taxesArray[InvoiceTax]

Line items on the invoice.

Returns:



247
248
249
# File 'lib/advanced_billing/models/invoice.rb', line 247

def taxes
  @taxes
end

#total_amountString

The invoice total, which is ‘subtotal_amount - discount_amount + tax_amount`.’

Returns:

  • (String)


216
217
218
# File 'lib/advanced_billing/models/invoice.rb', line 216

def total_amount
  @total_amount
end

#transaction_timeDateTime

A monotonically increasing number assigned to invoices as they are created. This number is unique within a site and can be used to sort and order invoices.

Returns:

  • (DateTime)


51
52
53
# File 'lib/advanced_billing/models/invoice.rb', line 51

def transaction_time
  @transaction_time
end

#uidString

Unique identifier for the invoice. It is generated automatically by Chargify and has the prefix “inv_” followed by alphanumeric characters.

Returns:

  • (String)


20
21
22
# File 'lib/advanced_billing/models/invoice.rb', line 20

def uid
  @uid
end

#updated_atDateTime

A monotonically increasing number assigned to invoices as they are created. This number is unique within a site and can be used to sort and order invoices.

Returns:

  • (DateTime)


63
64
65
# File 'lib/advanced_billing/models/invoice.rb', line 63

def updated_at
  @updated_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/advanced_billing/models/invoice.rb', line 485

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  uid = hash.key?('uid') ? hash['uid'] : SKIP
  site_id = hash.key?('site_id') ? hash['site_id'] : SKIP
  customer_id = hash.key?('customer_id') ? hash['customer_id'] : SKIP
  subscription_id =
    hash.key?('subscription_id') ? hash['subscription_id'] : SKIP
  number = hash.key?('number') ? hash['number'] : SKIP
  sequence_number =
    hash.key?('sequence_number') ? hash['sequence_number'] : SKIP
  transaction_time = if hash.key?('transaction_time')
                       (DateTimeHelper.from_rfc3339(hash['transaction_time']) if hash['transaction_time'])
                     else
                       SKIP
                     end
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               else
                 SKIP
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               else
                 SKIP
               end
  issue_date = hash.key?('issue_date') ? hash['issue_date'] : SKIP
  due_date = hash.key?('due_date') ? hash['due_date'] : SKIP
  paid_date = hash.key?('paid_date') ? hash['paid_date'] : SKIP
  status = hash.key?('status') ? hash['status'] : SKIP
  role = hash.key?('role') ? hash['role'] : SKIP
  parent_invoice_id =
    hash.key?('parent_invoice_id') ? hash['parent_invoice_id'] : SKIP
  collection_method =
    hash.key?('collection_method') ? hash['collection_method'] : SKIP
  payment_instructions =
    hash.key?('payment_instructions') ? hash['payment_instructions'] : SKIP
  currency = hash.key?('currency') ? hash['currency'] : SKIP
  consolidation_level =
    hash.key?('consolidation_level') ? hash['consolidation_level'] : SKIP
  parent_invoice_uid =
    hash.key?('parent_invoice_uid') ? hash['parent_invoice_uid'] : SKIP
  subscription_group_id =
    hash.key?('subscription_group_id') ? hash['subscription_group_id'] : SKIP
  parent_invoice_number =
    hash.key?('parent_invoice_number') ? hash['parent_invoice_number'] : SKIP
  group_primary_subscription_id =
    hash.key?('group_primary_subscription_id') ? hash['group_primary_subscription_id'] : SKIP
  product_name = hash.key?('product_name') ? hash['product_name'] : SKIP
  product_family_name =
    hash.key?('product_family_name') ? hash['product_family_name'] : SKIP
  seller = InvoiceSeller.from_hash(hash['seller']) if hash['seller']
  customer = InvoiceCustomer.from_hash(hash['customer']) if hash['customer']
  payer = InvoicePayer.from_hash(hash['payer']) if hash['payer']
  recipient_emails =
    hash.key?('recipient_emails') ? hash['recipient_emails'] : SKIP
  net_terms = hash.key?('net_terms') ? hash['net_terms'] : SKIP
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  billing_address = InvoiceAddress.from_hash(hash['billing_address']) if
    hash['billing_address']
  shipping_address = InvoiceAddress.from_hash(hash['shipping_address']) if
    hash['shipping_address']
  subtotal_amount =
    hash.key?('subtotal_amount') ? hash['subtotal_amount'] : SKIP
  discount_amount =
    hash.key?('discount_amount') ? hash['discount_amount'] : SKIP
  tax_amount = hash.key?('tax_amount') ? hash['tax_amount'] : SKIP
  total_amount = hash.key?('total_amount') ? hash['total_amount'] : SKIP
  credit_amount = hash.key?('credit_amount') ? hash['credit_amount'] : SKIP
  refund_amount = hash.key?('refund_amount') ? hash['refund_amount'] : SKIP
  paid_amount = hash.key?('paid_amount') ? hash['paid_amount'] : SKIP
  due_amount = hash.key?('due_amount') ? hash['due_amount'] : SKIP
  # Parameter is an array, so we need to iterate through it
  line_items = nil
  unless hash['line_items'].nil?
    line_items = []
    hash['line_items'].each do |structure|
      line_items << (InvoiceLineItem.from_hash(structure) if structure)
    end
  end

  line_items = SKIP unless hash.key?('line_items')
  # Parameter is an array, so we need to iterate through it
  discounts = nil
  unless hash['discounts'].nil?
    discounts = []
    hash['discounts'].each do |structure|
      discounts << (InvoiceDiscount.from_hash(structure) if structure)
    end
  end

  discounts = SKIP unless hash.key?('discounts')
  # Parameter is an array, so we need to iterate through it
  taxes = nil
  unless hash['taxes'].nil?
    taxes = []
    hash['taxes'].each do |structure|
      taxes << (InvoiceTax.from_hash(structure) if structure)
    end
  end

  taxes = SKIP unless hash.key?('taxes')
  # Parameter is an array, so we need to iterate through it
  credits = nil
  unless hash['credits'].nil?
    credits = []
    hash['credits'].each do |structure|
      credits << (InvoiceCredit.from_hash(structure) if structure)
    end
  end

  credits = SKIP unless hash.key?('credits')
  # Parameter is an array, so we need to iterate through it
  refunds = nil
  unless hash['refunds'].nil?
    refunds = []
    hash['refunds'].each do |structure|
      refunds << (InvoiceRefund.from_hash(structure) if structure)
    end
  end

  refunds = SKIP unless hash.key?('refunds')
  # Parameter is an array, so we need to iterate through it
  payments = nil
  unless hash['payments'].nil?
    payments = []
    hash['payments'].each do |structure|
      payments << (InvoicePayment.from_hash(structure) if structure)
    end
  end

  payments = SKIP unless hash.key?('payments')
  # Parameter is an array, so we need to iterate through it
  custom_fields = nil
  unless hash['custom_fields'].nil?
    custom_fields = []
    hash['custom_fields'].each do |structure|
      custom_fields << (InvoiceCustomField.from_hash(structure) if structure)
    end
  end

  custom_fields = SKIP unless hash.key?('custom_fields')
  display_settings = InvoiceDisplaySettings.from_hash(hash['display_settings']) if
    hash['display_settings']
  public_url = hash.key?('public_url') ? hash['public_url'] : SKIP
  previous_balance_data = InvoicePreviousBalance.from_hash(hash['previous_balance_data']) if
    hash['previous_balance_data']

  # Create object from extracted values.
  Invoice.new(id,
              uid,
              site_id,
              customer_id,
              subscription_id,
              number,
              sequence_number,
              transaction_time,
              created_at,
              updated_at,
              issue_date,
              due_date,
              paid_date,
              status,
              role,
              parent_invoice_id,
              collection_method,
              payment_instructions,
              currency,
              consolidation_level,
              parent_invoice_uid,
              subscription_group_id,
              parent_invoice_number,
              group_primary_subscription_id,
              product_name,
              product_family_name,
              seller,
              customer,
              payer,
              recipient_emails,
              net_terms,
              memo,
              billing_address,
              shipping_address,
              subtotal_amount,
              discount_amount,
              tax_amount,
              total_amount,
              credit_amount,
              refund_amount,
              paid_amount,
              due_amount,
              line_items,
              discounts,
              taxes,
              credits,
              refunds,
              payments,
              custom_fields,
              display_settings,
              public_url,
              previous_balance_data)
end

.namesObject

A mapping from model property names to API property names.



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/advanced_billing/models/invoice.rb', line 278

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['uid'] = 'uid'
  @_hash['site_id'] = 'site_id'
  @_hash['customer_id'] = 'customer_id'
  @_hash['subscription_id'] = 'subscription_id'
  @_hash['number'] = 'number'
  @_hash['sequence_number'] = 'sequence_number'
  @_hash['transaction_time'] = 'transaction_time'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['issue_date'] = 'issue_date'
  @_hash['due_date'] = 'due_date'
  @_hash['paid_date'] = 'paid_date'
  @_hash['status'] = 'status'
  @_hash['role'] = 'role'
  @_hash['parent_invoice_id'] = 'parent_invoice_id'
  @_hash['collection_method'] = 'collection_method'
  @_hash['payment_instructions'] = 'payment_instructions'
  @_hash['currency'] = 'currency'
  @_hash['consolidation_level'] = 'consolidation_level'
  @_hash['parent_invoice_uid'] = 'parent_invoice_uid'
  @_hash['subscription_group_id'] = 'subscription_group_id'
  @_hash['parent_invoice_number'] = 'parent_invoice_number'
  @_hash['group_primary_subscription_id'] =
    'group_primary_subscription_id'
  @_hash['product_name'] = 'product_name'
  @_hash['product_family_name'] = 'product_family_name'
  @_hash['seller'] = 'seller'
  @_hash['customer'] = 'customer'
  @_hash['payer'] = 'payer'
  @_hash['recipient_emails'] = 'recipient_emails'
  @_hash['net_terms'] = 'net_terms'
  @_hash['memo'] = 'memo'
  @_hash['billing_address'] = 'billing_address'
  @_hash['shipping_address'] = 'shipping_address'
  @_hash['subtotal_amount'] = 'subtotal_amount'
  @_hash['discount_amount'] = 'discount_amount'
  @_hash['tax_amount'] = 'tax_amount'
  @_hash['total_amount'] = 'total_amount'
  @_hash['credit_amount'] = 'credit_amount'
  @_hash['refund_amount'] = 'refund_amount'
  @_hash['paid_amount'] = 'paid_amount'
  @_hash['due_amount'] = 'due_amount'
  @_hash['line_items'] = 'line_items'
  @_hash['discounts'] = 'discounts'
  @_hash['taxes'] = 'taxes'
  @_hash['credits'] = 'credits'
  @_hash['refunds'] = 'refunds'
  @_hash['payments'] = 'payments'
  @_hash['custom_fields'] = 'custom_fields'
  @_hash['display_settings'] = 'display_settings'
  @_hash['public_url'] = 'public_url'
  @_hash['previous_balance_data'] = 'previous_balance_data'
  @_hash
end

.nullablesObject

An array for nullable fields



395
396
397
398
399
400
401
402
403
404
# File 'lib/advanced_billing/models/invoice.rb', line 395

def self.nullables
  %w[
    paid_date
    parent_invoice_id
    parent_invoice_uid
    subscription_group_id
    parent_invoice_number
    group_primary_subscription_id
  ]
end

.optionalsObject

An array for optional fields



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/advanced_billing/models/invoice.rb', line 337

def self.optionals
  %w[
    id
    uid
    site_id
    customer_id
    subscription_id
    number
    sequence_number
    transaction_time
    created_at
    updated_at
    issue_date
    due_date
    paid_date
    status
    role
    parent_invoice_id
    collection_method
    payment_instructions
    currency
    consolidation_level
    parent_invoice_uid
    subscription_group_id
    parent_invoice_number
    group_primary_subscription_id
    product_name
    product_family_name
    seller
    customer
    payer
    recipient_emails
    net_terms
    memo
    billing_address
    shipping_address
    subtotal_amount
    discount_amount
    tax_amount
    total_amount
    credit_amount
    refund_amount
    paid_amount
    due_amount
    line_items
    discounts
    taxes
    credits
    refunds
    payments
    custom_fields
    display_settings
    public_url
    previous_balance_data
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Invoice | Hash)

    value against the validation is performed.



704
705
706
707
708
709
710
# File 'lib/advanced_billing/models/invoice.rb', line 704

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#to_custom_created_atObject



694
695
696
# File 'lib/advanced_billing/models/invoice.rb', line 694

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_transaction_timeObject



690
691
692
# File 'lib/advanced_billing/models/invoice.rb', line 690

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end

#to_custom_updated_atObject



698
699
700
# File 'lib/advanced_billing/models/invoice.rb', line 698

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end