Class: Reji::InvoiceLineItem
- Inherits:
-
Object
- Object
- Reji::InvoiceLineItem
- Defined in:
- lib/reji/invoice_line_item.rb
Instance Method Summary collapse
-
#as_stripe_invoice_line_item ⇒ Object
Get the underlying Stripe invoice line item.
-
#end_date ⇒ Object
Get a human readable date for the end date.
-
#exclusive_tax_percentage ⇒ Object
Get the total percentage of the default exclusive tax for the invoice line item.
-
#has_both_inclusive_and_exclusive_tax ⇒ Object
Determine if the line item has both inclusive and exclusive tax.
-
#has_tax_rates ⇒ Object
Determine if the invoice line item has tax rates.
-
#inclusive_tax_percentage ⇒ Object
Get the total percentage of the default inclusive tax for the invoice line item.
-
#initialize(invoice, item) ⇒ InvoiceLineItem
constructor
A new instance of InvoiceLineItem.
-
#invoice ⇒ Object
Get the Stripe model instance.
-
#is_subscription ⇒ Object
Determine if the invoice line item is for a subscription.
-
#method_missing(key) ⇒ Object
Dynamically access the Stripe invoice line item instance.
-
#start_date ⇒ Object
Get a human readable date for the start date.
-
#total ⇒ Object
Get the total for the invoice line item.
Constructor Details
#initialize(invoice, item) ⇒ InvoiceLineItem
Returns a new instance of InvoiceLineItem.
5 6 7 8 |
# File 'lib/reji/invoice_line_item.rb', line 5 def initialize(invoice, item) @invoice = invoice @item = item end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key) ⇒ Object
Dynamically access the Stripe invoice line item instance.
67 68 69 |
# File 'lib/reji/invoice_line_item.rb', line 67 def method_missing(key) @item[key] end |
Instance Method Details
#as_stripe_invoice_line_item ⇒ Object
Get the underlying Stripe invoice line item.
62 63 64 |
# File 'lib/reji/invoice_line_item.rb', line 62 def as_stripe_invoice_line_item @item end |
#end_date ⇒ Object
Get a human readable date for the end date.
47 48 49 |
# File 'lib/reji/invoice_line_item.rb', line 47 def end_date self.is_subscription ? Time.at(@item.period.end).strftime('%b %d, %Y') : nil end |
#exclusive_tax_percentage ⇒ Object
Get the total percentage of the default exclusive tax for the invoice line item.
28 29 30 31 32 |
# File 'lib/reji/invoice_line_item.rb', line 28 def exclusive_tax_percentage @invoice.is_not_tax_exempt ? self.calculate_tax_percentage_by_tax_amount(false) : self.calculate_tax_percentage_by_tax_rate(false) end |
#has_both_inclusive_and_exclusive_tax ⇒ Object
Determine if the line item has both inclusive and exclusive tax.
16 17 18 |
# File 'lib/reji/invoice_line_item.rb', line 16 def has_both_inclusive_and_exclusive_tax self.inclusive_tax_percentage > 0 && self.exclusive_tax_percentage > 0 end |
#has_tax_rates ⇒ Object
Determine if the invoice line item has tax rates.
35 36 37 38 39 |
# File 'lib/reji/invoice_line_item.rb', line 35 def has_tax_rates @invoice.is_not_tax_exempt ? ! @item.tax_amounts.empty? : ! @item.tax_rates.empty? end |
#inclusive_tax_percentage ⇒ Object
Get the total percentage of the default inclusive tax for the invoice line item.
21 22 23 24 25 |
# File 'lib/reji/invoice_line_item.rb', line 21 def inclusive_tax_percentage @invoice.is_not_tax_exempt ? self.calculate_tax_percentage_by_tax_amount(true) : self.calculate_tax_percentage_by_tax_rate(true) end |
#invoice ⇒ Object
Get the Stripe model instance.
57 58 59 |
# File 'lib/reji/invoice_line_item.rb', line 57 def invoice @invoice end |
#is_subscription ⇒ Object
Determine if the invoice line item is for a subscription.
52 53 54 |
# File 'lib/reji/invoice_line_item.rb', line 52 def is_subscription @item.type == 'subscription' end |
#start_date ⇒ Object
Get a human readable date for the start date.
42 43 44 |
# File 'lib/reji/invoice_line_item.rb', line 42 def start_date self.is_subscription ? Time.at(@item.period.start).strftime('%b %d, %Y') : nil end |
#total ⇒ Object
Get the total for the invoice line item.
11 12 13 |
# File 'lib/reji/invoice_line_item.rb', line 11 def total self.format_amount(@item.amount) end |