Class: ModernTreasury::InvoiceLineItem

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/modern_treasury/models/invoice_line_item.rb

Overview

InvoiceLineItem Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(id:, object:, live_mode:, created_at:, updated_at:, name:, description:, quantity:, unit_amount:, direction:, amount:) ⇒ InvoiceLineItem

Returns a new instance of InvoiceLineItem.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 92

def initialize(id:, object:, live_mode:, created_at:, updated_at:, name:,
               description:, quantity:, unit_amount:, direction:, amount:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @name = name
  @description = description
  @quantity = quantity
  @unit_amount = unit_amount
  @direction = direction
  @amount = amount
end

Instance Attribute Details

#amountInteger

The total amount for this line item specified in the invoice currency’s smallest unit.

Returns:

  • (Integer)


63
64
65
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 63

def amount
  @amount
end

#created_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


29
30
31
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 29

def created_at
  @created_at
end

#descriptionString

An optional free-form description of the line item.

Returns:

  • (String)


42
43
44
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 42

def description
  @description
end

#directionString

Either ‘debit` or `credit`. `debit` indicates that a client owes the business money and increases the invoice’s ‘total_amount` due. `credit` has the opposite intention and effect.

Returns:

  • (String)


58
59
60
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 58

def direction
  @direction
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


15
16
17
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 15

def id
  @id
end

#live_modeTrueClass | FalseClass

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (TrueClass | FalseClass)


24
25
26
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 24

def live_mode
  @live_mode
end

#nameString

The name of the line item, typically a product or SKU name.

Returns:

  • (String)


38
39
40
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 38

def name
  @name
end

#objectString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 19

def object
  @object
end

#quantityInteger

The number of units of a product or service that this line item is for.

Must be a whole number. Defaults to 1 if not provided.

Returns:

  • (Integer)


47
48
49
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 47

def quantity
  @quantity
end

#unit_amountInteger

The cost per unit of the product or service that this line item is for,

specified in the invoice currency's smallest unit.

Returns:

  • (Integer)


52
53
54
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 52

def unit_amount
  @unit_amount
end

#updated_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


34
35
36
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 34

def updated_at
  @updated_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 108

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  object = hash.key?('object') ? hash['object'] : nil
  live_mode = hash.key?('live_mode') ? hash['live_mode'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               end
  name = hash.key?('name') ? hash['name'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  unit_amount = hash.key?('unit_amount') ? hash['unit_amount'] : nil
  direction = hash.key?('direction') ? hash['direction'] : nil
  amount = hash.key?('amount') ? hash['amount'] : nil

  # Create object from extracted values.
  InvoiceLineItem.new(id: id,
                      object: object,
                      live_mode: live_mode,
                      created_at: created_at,
                      updated_at: updated_at,
                      name: name,
                      description: description,
                      quantity: quantity,
                      unit_amount: unit_amount,
                      direction: direction,
                      amount: amount)
end

.namesObject

A mapping from model property names to API property names.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 66

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['object'] = 'object'
  @_hash['live_mode'] = 'live_mode'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['name'] = 'name'
  @_hash['description'] = 'description'
  @_hash['quantity'] = 'quantity'
  @_hash['unit_amount'] = 'unit_amount'
  @_hash['direction'] = 'direction'
  @_hash['amount'] = 'amount'
  @_hash
end

.nullablesObject

An array for nullable fields



88
89
90
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 88

def self.nullables
  []
end

.optionalsObject

An array for optional fields



83
84
85
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 83

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



160
161
162
163
164
165
166
167
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 160

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, object: #{@object.inspect}, live_mode:"\
  " #{@live_mode.inspect}, created_at: #{@created_at.inspect}, updated_at:"\
  " #{@updated_at.inspect}, name: #{@name.inspect}, description: #{@description.inspect},"\
  " quantity: #{@quantity.inspect}, unit_amount: #{@unit_amount.inspect}, direction:"\
  " #{@direction.inspect}, amount: #{@amount.inspect}>"
end

#to_custom_created_atObject



142
143
144
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 142

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



146
147
148
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 146

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



151
152
153
154
155
156
157
# File 'lib/modern_treasury/models/invoice_line_item.rb', line 151

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, object: #{@object}, live_mode: #{@live_mode}, created_at:"\
  " #{@created_at}, updated_at: #{@updated_at}, name: #{@name}, description: #{@description},"\
  " quantity: #{@quantity}, unit_amount: #{@unit_amount}, direction: #{@direction}, amount:"\
  " #{@amount}>"
end