Class: ModernTreasury::Invoice

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

Overview

Invoice 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:, contact_details:, counterparty_id:, counterparty_billing_address:, counterparty_shipping_address:, currency:, description:, due_date:, invoicer_address:, originating_account_id:, receiving_account_id:, payment_effective_date:, payment_type:, payment_method:, hosted_url:, number:, payment_orders:, pdf_url:, status:, total_amount:) ⇒ Invoice

Returns a new instance of Invoice.



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/modern_treasury/models/invoice.rb', line 169

def initialize(id:, object:, live_mode:, created_at:, updated_at:,
               contact_details:, counterparty_id:,
               counterparty_billing_address:,
               counterparty_shipping_address:, currency:, description:,
               due_date:, invoicer_address:, originating_account_id:,
               receiving_account_id:, payment_effective_date:,
               payment_type:, payment_method:, hosted_url:, number:,
               payment_orders:, pdf_url:, status:, total_amount:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @contact_details = contact_details
  @counterparty_id = counterparty_id
  @counterparty_billing_address = counterparty_billing_address
  @counterparty_shipping_address = counterparty_shipping_address
  @currency = currency
  @description = description
  @due_date = due_date
  @invoicer_address = invoicer_address
  @originating_account_id = 
  @receiving_account_id = 
  @payment_effective_date = payment_effective_date
  @payment_type = payment_type
  @payment_method = payment_method
  @hosted_url = hosted_url
  @number = number
  @payment_orders = payment_orders
  @pdf_url = pdf_url
  @status = status
  @total_amount = total_amount
end

Instance Attribute Details

#contact_detailsArray[ContactDetail]

The invoicer’s contact details displayed at the top of the invoice.

Returns:



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

def contact_details
  @contact_details
end

#counterparty_billing_addressCounterpartyBillingAddress

The counterparty’s billing address.



46
47
48
# File 'lib/modern_treasury/models/invoice.rb', line 46

def counterparty_billing_address
  @counterparty_billing_address
end

#counterparty_idString

The ID of the counterparty receiving the invoice.

Returns:

  • (String)


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

def counterparty_id
  @counterparty_id
end

#counterparty_shipping_addressCounterpartyShippingAddress

The counterparty’s shipping address where physical goods should be delivered.



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

def counterparty_shipping_address
  @counterparty_shipping_address
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.rb', line 29

def created_at
  @created_at
end

#currencyCurrency

Three-letter ISO currency code.

Returns:



55
56
57
# File 'lib/modern_treasury/models/invoice.rb', line 55

def currency
  @currency
end

#descriptionString

A free-form description of the invoice.

Returns:

  • (String)


59
60
61
# File 'lib/modern_treasury/models/invoice.rb', line 59

def description
  @description
end

#due_dateDateTime

A future date by when the invoice needs to be paid.

Returns:

  • (DateTime)


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

def due_date
  @due_date
end

#hosted_urlString

The URL of the hosted web UI where the invoice can be viewed.

Returns:

  • (String)


95
96
97
# File 'lib/modern_treasury/models/invoice.rb', line 95

def hosted_url
  @hosted_url
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


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

def id
  @id
end

#invoicer_addressInvoicerAddress

The invoice issuer’s business address.

Returns:



67
68
69
# File 'lib/modern_treasury/models/invoice.rb', line 67

def invoicer_address
  @invoicer_address
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.rb', line 24

def live_mode
  @live_mode
end

#numberString

A unique record number assigned to each invoice that is issued.

Returns:

  • (String)


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

def number
  @number
end

#objectString

TODO: Write general description for this method

Returns:

  • (String)


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

def object
  @object
end

#originating_account_idString

The ID of the internal account the invoice should be paid to.

Returns:

  • (String)


71
72
73
# File 'lib/modern_treasury/models/invoice.rb', line 71

def 
  @originating_account_id
end

#payment_effective_dateDate

Date transactions are to be posted to the participants’ account. Defaults to the current business day or the next business day if the current day is a bank holiday or weekend. Format: yyyy-mm-dd.

Returns:

  • (Date)


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

def payment_effective_date
  @payment_effective_date
end

#payment_methodPaymentMethod

When opening an invoice, whether to show the embedded payment UI , automatically debit the recipient, or rely on manual payment from the recipient.

Returns:



91
92
93
# File 'lib/modern_treasury/models/invoice.rb', line 91

def payment_method
  @payment_method
end

#payment_ordersArray[PaymentOrder]

The payment orders created for paying the invoice through the invoice payment UI.

Returns:



104
105
106
# File 'lib/modern_treasury/models/invoice.rb', line 104

def payment_orders
  @payment_orders
end

#payment_typePaymentType5

One of ‘ach` or `eft`

Returns:



85
86
87
# File 'lib/modern_treasury/models/invoice.rb', line 85

def payment_type
  @payment_type
end

#pdf_urlString

The URL where the invoice PDF can be downloaded.

Returns:

  • (String)


108
109
110
# File 'lib/modern_treasury/models/invoice.rb', line 108

def pdf_url
  @pdf_url
end

#receiving_account_idUUID | String

The receiving account ID. Can be an ‘internal_account`.

Returns:

  • (UUID | String)


75
76
77
# File 'lib/modern_treasury/models/invoice.rb', line 75

def 
  @receiving_account_id
end

#statusStatus5

The status of the invoice.

Returns:



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

def status
  @status
end

#total_amountInteger

Total amount due in specified currency’s smallest unit, e.g., $10 USD would be represented as 1000.

Returns:

  • (Integer)


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

def total_amount
  @total_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.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.



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/modern_treasury/models/invoice.rb', line 204

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
  # Parameter is an array, so we need to iterate through it
  contact_details = nil
  unless hash['contact_details'].nil?
    contact_details = []
    hash['contact_details'].each do |structure|
      contact_details << (ContactDetail.from_hash(structure) if structure)
    end
  end

  contact_details = nil unless hash.key?('contact_details')
  counterparty_id =
    hash.key?('counterparty_id') ? hash['counterparty_id'] : nil
  if hash['counterparty_billing_address']
    counterparty_billing_address = CounterpartyBillingAddress.from_hash(hash['counterparty_billing_address'])
  end
  if hash['counterparty_shipping_address']
    counterparty_shipping_address = CounterpartyShippingAddress.from_hash(hash['counterparty_shipping_address'])
  end
  currency = hash.key?('currency') ? hash['currency'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  due_date = if hash.key?('due_date')
               (DateTimeHelper.from_rfc3339(hash['due_date']) if hash['due_date'])
             end
  invoicer_address = InvoicerAddress.from_hash(hash['invoicer_address']) if
    hash['invoicer_address']
   =
    hash.key?('originating_account_id') ? hash['originating_account_id'] : nil
   =
    hash.key?('receiving_account_id') ? hash['receiving_account_id'] : nil
  payment_effective_date =
    hash.key?('payment_effective_date') ? hash['payment_effective_date'] : nil
  payment_type = hash.key?('payment_type') ? hash['payment_type'] : nil
  payment_method =
    hash.key?('payment_method') ? hash['payment_method'] : nil
  hosted_url = hash.key?('hosted_url') ? hash['hosted_url'] : nil
  number = hash.key?('number') ? hash['number'] : nil
  # Parameter is an array, so we need to iterate through it
  payment_orders = nil
  unless hash['payment_orders'].nil?
    payment_orders = []
    hash['payment_orders'].each do |structure|
      payment_orders << (PaymentOrder.from_hash(structure) if structure)
    end
  end

  payment_orders = nil unless hash.key?('payment_orders')
  pdf_url = hash.key?('pdf_url') ? hash['pdf_url'] : nil
  status = hash.key?('status') ? hash['status'] : nil
  total_amount = hash.key?('total_amount') ? hash['total_amount'] : nil

  # Create object from extracted values.
  Invoice.new(id: id,
              object: object,
              live_mode: live_mode,
              created_at: created_at,
              updated_at: updated_at,
              contact_details: contact_details,
              counterparty_id: counterparty_id,
              counterparty_billing_address: counterparty_billing_address,
              counterparty_shipping_address: counterparty_shipping_address,
              currency: currency,
              description: description,
              due_date: due_date,
              invoicer_address: invoicer_address,
              originating_account_id: ,
              receiving_account_id: ,
              payment_effective_date: payment_effective_date,
              payment_type: payment_type,
              payment_method: payment_method,
              hosted_url: hosted_url,
              number: number,
              payment_orders: payment_orders,
              pdf_url: pdf_url,
              status: status,
              total_amount: total_amount)
end

.namesObject

A mapping from model property names to API property names.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/modern_treasury/models/invoice.rb', line 120

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['contact_details'] = 'contact_details'
  @_hash['counterparty_id'] = 'counterparty_id'
  @_hash['counterparty_billing_address'] = 'counterparty_billing_address'
  @_hash['counterparty_shipping_address'] =
    'counterparty_shipping_address'
  @_hash['currency'] = 'currency'
  @_hash['description'] = 'description'
  @_hash['due_date'] = 'due_date'
  @_hash['invoicer_address'] = 'invoicer_address'
  @_hash['originating_account_id'] = 'originating_account_id'
  @_hash['receiving_account_id'] = 'receiving_account_id'
  @_hash['payment_effective_date'] = 'payment_effective_date'
  @_hash['payment_type'] = 'payment_type'
  @_hash['payment_method'] = 'payment_method'
  @_hash['hosted_url'] = 'hosted_url'
  @_hash['number'] = 'number'
  @_hash['payment_orders'] = 'payment_orders'
  @_hash['pdf_url'] = 'pdf_url'
  @_hash['status'] = 'status'
  @_hash['total_amount'] = 'total_amount'
  @_hash
end

.nullablesObject

An array for nullable fields



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/modern_treasury/models/invoice.rb', line 156

def self.nullables
  %w[
    counterparty_billing_address
    counterparty_shipping_address
    invoicer_address
    receiving_account_id
    payment_effective_date
    payment_type
    payment_method
    pdf_url
  ]
end

.optionalsObject

An array for optional fields



151
152
153
# File 'lib/modern_treasury/models/invoice.rb', line 151

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/modern_treasury/models/invoice.rb', line 323

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}, contact_details: #{@contact_details.inspect}, counterparty_id:"\
  " #{@counterparty_id.inspect}, counterparty_billing_address:"\
  " #{@counterparty_billing_address.inspect}, counterparty_shipping_address:"\
  " #{@counterparty_shipping_address.inspect}, currency: #{@currency.inspect}, description:"\
  " #{@description.inspect}, due_date: #{@due_date.inspect}, invoicer_address:"\
  " #{@invoicer_address.inspect}, originating_account_id: #{@originating_account_id.inspect},"\
  " receiving_account_id: #{@receiving_account_id.inspect}, payment_effective_date:"\
  " #{@payment_effective_date.inspect}, payment_type: #{@payment_type.inspect},"\
  " payment_method: #{@payment_method.inspect}, hosted_url: #{@hosted_url.inspect}, number:"\
  " #{@number.inspect}, payment_orders: #{@payment_orders.inspect}, pdf_url:"\
  " #{@pdf_url.inspect}, status: #{@status.inspect}, total_amount: #{@total_amount.inspect}>"
end

#to_custom_created_atObject



294
295
296
# File 'lib/modern_treasury/models/invoice.rb', line 294

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_due_dateObject



302
303
304
# File 'lib/modern_treasury/models/invoice.rb', line 302

def to_custom_due_date
  DateTimeHelper.to_rfc3339(due_date)
end

#to_custom_updated_atObject



298
299
300
# File 'lib/modern_treasury/models/invoice.rb', line 298

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/modern_treasury/models/invoice.rb', line 307

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}, contact_details: #{@contact_details},"\
  " counterparty_id: #{@counterparty_id}, counterparty_billing_address:"\
  " #{@counterparty_billing_address}, counterparty_shipping_address:"\
  " #{@counterparty_shipping_address}, currency: #{@currency}, description: #{@description},"\
  " due_date: #{@due_date}, invoicer_address: #{@invoicer_address}, originating_account_id:"\
  " #{@originating_account_id}, receiving_account_id: #{@receiving_account_id},"\
  " payment_effective_date: #{@payment_effective_date}, payment_type: #{@payment_type},"\
  " payment_method: #{@payment_method}, hosted_url: #{@hosted_url}, number: #{@number},"\
  " payment_orders: #{@payment_orders}, pdf_url: #{@pdf_url}, status: #{@status},"\
  " total_amount: #{@total_amount}>"
end