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, public_url_expires_on: SKIP, additional_properties: {}) ⇒ Invoice

Returns a new instance of Invoice.



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
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/advanced_billing/models/invoice.rb', line 413

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,
               public_url_expires_on: SKIP, additional_properties: {})
  @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
  @public_url_expires_on = public_url_expires_on unless public_url_expires_on == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#billing_addressInvoiceAddress

The invoice billing address.

Returns:



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

def billing_address
  @billing_address
end

#collection_methodCollectionMethod

The type of payment collection to be used in the subscription. For legacy Statements Architecture valid options are - ‘invoice`, `automatic`. For current Relationship Invoicing Architecture valid options are - `remittance`, `automatic`, `prepaid`.

Returns:



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

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](maxio.zendesk.com/hc/en-us/articles/24252269909389- Invoice-Consolidation).



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

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)


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

def credit_amount
  @credit_amount
end

#creditsArray[InvoiceCredit]

Line items on the invoice.

Returns:



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

def credits
  @credits
end

#currencyString

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

Returns:

  • (String)


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

def currency
  @currency
end

#custom_fieldsArray[InvoiceCustomField]

Line items on the invoice.

Returns:



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

def custom_fields
  @custom_fields
end

#customerInvoiceCustomer

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

Returns:



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

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)


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

def discount_amount
  @discount_amount
end

#discountsArray[InvoiceDiscount]

Line items on the invoice.

Returns:



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

def discounts
  @discounts
end

#display_settingsInvoiceDisplaySettings

Line items on the invoice.



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

def display_settings
  @display_settings
end

#due_amountString

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

Returns:

  • (String)


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

def due_amount
  @due_amount
end

#due_dateDate

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

Returns:

  • (Date)


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)


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

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_dateDate

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:

  • (Date)


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:



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

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)


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

def memo
  @memo
end

#net_termsInteger

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

Returns:

  • (Integer)


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

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)


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

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:

  • (Date)


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](maxio.zendesk.com/hc/en-us/articles/24252287829645-Advan ced-Billing-Invoices-Overview#invoice-statuses) 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)


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

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)


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

def parent_invoice_uid
  @parent_invoice_uid
end

#payerInvoicePayer

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

Returns:



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

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)


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

def payment_instructions
  @payment_instructions
end

#paymentsArray[InvoicePayment]

Line items on the invoice.

Returns:



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

def payments
  @payments
end

#previous_balance_dataInvoicePreviousBalance

The public URL of the invoice



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

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)


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

def product_family_name
  @product_family_name
end

#product_nameString

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

Returns:

  • (String)


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

def product_name
  @product_name
end

#public_urlString

The public URL of the invoice

Returns:

  • (String)


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

def public_url
  @public_url
end

#public_url_expires_onDate

The format is ‘“YYYY-MM-DD”`.

Returns:

  • (Date)


280
281
282
# File 'lib/advanced_billing/models/invoice.rb', line 280

def public_url_expires_on
  @public_url_expires_on
end

#recipient_emailsArray[String]

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

Returns:

  • (Array[String])


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

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)


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

def refund_amount
  @refund_amount
end

#refundsArray[InvoiceRefund]

Line items on the invoice.

Returns:



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

def refunds
  @refunds
end

#roleInvoiceRole

The current status of the invoice. See [Invoice Statuses](maxio.zendesk.com/hc/en-us/articles/24252287829645-Advan ced-Billing-Invoices-Overview#invoice-statuses) for more.

Returns:



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:



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

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:



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

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

#statusInvoiceStatus

The current status of the invoice. See [Invoice Statuses](maxio.zendesk.com/hc/en-us/articles/24252287829645-Advan ced-Billing-Invoices-Overview#invoice-statuses) 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)


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

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)


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

def subtotal_amount
  @subtotal_amount
end

#tax_amountString

Total tax on the invoice.

Returns:

  • (String)


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

def tax_amount
  @tax_amount
end

#taxesArray[InvoiceTax]

Line items on the invoice.

Returns:



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

def taxes
  @taxes
end

#total_amountString

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

Returns:

  • (String)


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

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.



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
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
# File 'lib/advanced_billing/models/invoice.rb', line 498

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']
  public_url_expires_on =
    hash.key?('public_url_expires_on') ? hash['public_url_expires_on'] : SKIP

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

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

.namesObject

A mapping from model property names to API property names.



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
335
336
337
338
339
340
# File 'lib/advanced_billing/models/invoice.rb', line 283

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['public_url_expires_on'] = 'public_url_expires_on'
  @_hash
end

.nullablesObject

An array for nullable fields



402
403
404
405
406
407
408
409
410
411
# File 'lib/advanced_billing/models/invoice.rb', line 402

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



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
393
394
395
396
397
398
399
# File 'lib/advanced_billing/models/invoice.rb', line 343

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
    public_url_expires_on
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Invoice | Hash)

    value against the validation is performed.



724
725
726
727
728
729
730
# File 'lib/advanced_billing/models/invoice.rb', line 724

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



714
715
716
# File 'lib/advanced_billing/models/invoice.rb', line 714

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_transaction_timeObject



710
711
712
# File 'lib/advanced_billing/models/invoice.rb', line 710

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end

#to_custom_updated_atObject



718
719
720
# File 'lib/advanced_billing/models/invoice.rb', line 718

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end