Class: AdvancedBilling::InvoiceEvent1

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

Overview

The event data is the data that, when combined with the command, results in the output invoice found in the invoice field.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(uid = SKIP, credit_note_number = SKIP, credit_note_uid = SKIP, original_amount = SKIP, applied_amount = SKIP, transaction_time = SKIP, memo = SKIP, role = SKIP, consolidated_invoice = SKIP, applied_credit_notes = SKIP, debit_note_number = SKIP, debit_note_uid = SKIP, payment_method = SKIP, transaction_id = SKIP, from_collection_method = SKIP, to_collection_method = SKIP, consolidation_level = SKIP, from_status = SKIP, to_status = SKIP, due_amount = SKIP, total_amount = SKIP, apply_credit = SKIP, credit_note_attributes = SKIP, payment_id = SKIP, refund_amount = SKIP, refund_id = SKIP, prepayment = SKIP, is_advance_invoice = SKIP) ⇒ InvoiceEvent1

Returns a new instance of InvoiceEvent1.



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
# File 'lib/advanced_billing/models/invoice_event1.rb', line 224

def initialize(uid = SKIP, credit_note_number = SKIP,
               credit_note_uid = SKIP, original_amount = SKIP,
               applied_amount = SKIP, transaction_time = SKIP, memo = SKIP,
               role = SKIP, consolidated_invoice = SKIP,
               applied_credit_notes = SKIP, debit_note_number = SKIP,
               debit_note_uid = SKIP, payment_method = SKIP,
               transaction_id = SKIP, from_collection_method = SKIP,
               to_collection_method = SKIP, consolidation_level = SKIP,
               from_status = SKIP, to_status = SKIP, due_amount = SKIP,
               total_amount = SKIP, apply_credit = SKIP,
               credit_note_attributes = SKIP, payment_id = SKIP,
               refund_amount = SKIP, refund_id = SKIP, prepayment = SKIP,
               is_advance_invoice = SKIP)
  @uid = uid unless uid == SKIP
  @credit_note_number = credit_note_number unless credit_note_number == SKIP
  @credit_note_uid = credit_note_uid unless credit_note_uid == SKIP
  @original_amount = original_amount unless original_amount == SKIP
  @applied_amount = applied_amount unless applied_amount == SKIP
  @transaction_time = transaction_time unless transaction_time == SKIP
  @memo = memo unless memo == SKIP
  @role = role unless role == SKIP
  @consolidated_invoice = consolidated_invoice unless consolidated_invoice == SKIP
  @applied_credit_notes = applied_credit_notes unless applied_credit_notes == SKIP
  @debit_note_number = debit_note_number unless debit_note_number == SKIP
  @debit_note_uid = debit_note_uid unless debit_note_uid == SKIP
  @payment_method = payment_method unless payment_method == SKIP
  @transaction_id = transaction_id unless transaction_id == SKIP
  @from_collection_method = from_collection_method unless from_collection_method == SKIP
  @to_collection_method = to_collection_method unless to_collection_method == SKIP
  @consolidation_level = consolidation_level unless consolidation_level == SKIP
  @from_status = from_status unless from_status == SKIP
  @to_status = to_status unless to_status == SKIP
  @due_amount = due_amount unless due_amount == SKIP
  @total_amount = total_amount unless total_amount == SKIP
  @apply_credit = apply_credit unless apply_credit == SKIP
  @credit_note_attributes = credit_note_attributes unless credit_note_attributes == SKIP
  @payment_id = payment_id unless payment_id == SKIP
  @refund_amount = refund_amount unless refund_amount == SKIP
  @refund_id = refund_id unless refund_id == SKIP
  @prepayment = prepayment unless prepayment == SKIP
  @is_advance_invoice = is_advance_invoice unless is_advance_invoice == SKIP
end

Instance Attribute Details

#applied_amountString

The amount of the credit note applied to invoice.

Returns:

  • (String)


36
37
38
# File 'lib/advanced_billing/models/invoice_event1.rb', line 36

def applied_amount
  @applied_amount
end

#applied_credit_notesArray[AppliedCreditNote]

List of credit notes applied to children invoices (if consolidated invoice)

Returns:



58
59
60
# File 'lib/advanced_billing/models/invoice_event1.rb', line 58

def applied_credit_notes
  @applied_credit_notes
end

#apply_creditTrueClass | FalseClass

If true, credit was created and applied it to the invoice.

Returns:

  • (TrueClass | FalseClass)


125
126
127
# File 'lib/advanced_billing/models/invoice_event1.rb', line 125

def apply_credit
  @apply_credit
end

#consolidated_invoiceTrueClass | FalseClass

Shows whether it was applied to consolidated invoice or not

Returns:

  • (TrueClass | FalseClass)


53
54
55
# File 'lib/advanced_billing/models/invoice_event1.rb', line 53

def consolidated_invoice
  @consolidated_invoice
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).



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

def consolidation_level
  @consolidation_level
end

#credit_note_attributesCreditNote1

If true, credit was created and applied it to the invoice.

Returns:



129
130
131
# File 'lib/advanced_billing/models/invoice_event1.rb', line 129

def credit_note_attributes
  @credit_note_attributes
end

#credit_note_numberString

A unique, identifying string that appears on the credit note and in places it is referenced.

Returns:

  • (String)


23
24
25
# File 'lib/advanced_billing/models/invoice_event1.rb', line 23

def credit_note_number
  @credit_note_number
end

#credit_note_uidString

Unique identifier for the credit note. It is generated automatically by Chargify and has the prefix “cn_” followed by alphanumeric characters.

Returns:

  • (String)


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

def credit_note_uid
  @credit_note_uid
end

#debit_note_numberString

A unique, identifying string that appears on the debit note and in places it is referenced.

Returns:

  • (String)


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

def debit_note_number
  @debit_note_number
end

#debit_note_uidString

Unique identifier for the debit note. It is generated automatically by Chargify and has the prefix “db_” followed by alphanumeric characters.

Returns:

  • (String)


68
69
70
# File 'lib/advanced_billing/models/invoice_event1.rb', line 68

def debit_note_uid
  @debit_note_uid
end

#due_amountString

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

Returns:

  • (String)


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

def due_amount
  @due_amount
end

#from_collection_methodString

The previous collection method of the invoice.

Returns:

  • (String)


80
81
82
# File 'lib/advanced_billing/models/invoice_event1.rb', line 80

def from_collection_method
  @from_collection_method
end

#from_statusStatus

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

Returns:



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

def from_status
  @from_status
end

#is_advance_invoiceTrueClass | FalseClass

If true, the invoice is an advance invoice.

Returns:

  • (TrueClass | FalseClass)


149
150
151
# File 'lib/advanced_billing/models/invoice_event1.rb', line 149

def is_advance_invoice
  @is_advance_invoice
end

#memoString

The credit note memo.

Returns:

  • (String)


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

def memo
  @memo
end

#original_amountString

The full, original amount of the credit note.

Returns:

  • (String)


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

def original_amount
  @original_amount
end

#payment_idInteger

The ID of the payment transaction to be refunded.

Returns:

  • (Integer)


133
134
135
# File 'lib/advanced_billing/models/invoice_event1.rb', line 133

def payment_id
  @payment_id
end

#payment_methodPaymentMethodNestedData

A nested data structure detailing the method of payment



72
73
74
# File 'lib/advanced_billing/models/invoice_event1.rb', line 72

def payment_method
  @payment_method
end

#prepaymentTrueClass | FalseClass

The flag that shows whether the original payment was a prepayment or not

Returns:

  • (TrueClass | FalseClass)


145
146
147
# File 'lib/advanced_billing/models/invoice_event1.rb', line 145

def prepayment
  @prepayment
end

#refund_amountString

The amount of the refund.

Returns:

  • (String)


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

def refund_amount
  @refund_amount
end

#refund_idInteger

The ID of the refund transaction.

Returns:

  • (Integer)


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

def refund_id
  @refund_id
end

#roleString

The role of the credit note (e.g. ‘general’)

Returns:

  • (String)


49
50
51
# File 'lib/advanced_billing/models/invoice_event1.rb', line 49

def role
  @role
end

#to_collection_methodString

The new collection method of the invoice.

Returns:

  • (String)


84
85
86
# File 'lib/advanced_billing/models/invoice_event1.rb', line 84

def to_collection_method
  @to_collection_method
end

#to_statusStatus

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

Returns:



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

def to_status
  @to_status
end

#total_amountString

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

Returns:

  • (String)


121
122
123
# File 'lib/advanced_billing/models/invoice_event1.rb', line 121

def total_amount
  @total_amount
end

#transaction_idInteger

The Chargify id of the original payment

Returns:

  • (Integer)


76
77
78
# File 'lib/advanced_billing/models/invoice_event1.rb', line 76

def transaction_id
  @transaction_id
end

#transaction_timeDateTime

The time the credit note was applied, in ISO 8601 format, i.e. “2019-06-07T17:20:06Z”

Returns:

  • (DateTime)


41
42
43
# File 'lib/advanced_billing/models/invoice_event1.rb', line 41

def transaction_time
  @transaction_time
end

#uidString

Unique identifier for the credit note application. It is generated automatically by Chargify and has the prefix “cdt_” followed by alphanumeric characters.

Returns:

  • (String)


18
19
20
# File 'lib/advanced_billing/models/invoice_event1.rb', line 18

def uid
  @uid
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/advanced_billing/models/invoice_event1.rb', line 268

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  uid = hash.key?('uid') ? hash['uid'] : SKIP
  credit_note_number =
    hash.key?('credit_note_number') ? hash['credit_note_number'] : SKIP
  credit_note_uid =
    hash.key?('credit_note_uid') ? hash['credit_note_uid'] : SKIP
  original_amount =
    hash.key?('original_amount') ? hash['original_amount'] : SKIP
  applied_amount =
    hash.key?('applied_amount') ? hash['applied_amount'] : SKIP
  transaction_time = if hash.key?('transaction_time')
                       (DateTimeHelper.from_rfc3339(hash['transaction_time']) if hash['transaction_time'])
                     else
                       SKIP
                     end
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  role = hash.key?('role') ? hash['role'] : SKIP
  consolidated_invoice =
    hash.key?('consolidated_invoice') ? hash['consolidated_invoice'] : SKIP
  # Parameter is an array, so we need to iterate through it
  applied_credit_notes = nil
  unless hash['applied_credit_notes'].nil?
    applied_credit_notes = []
    hash['applied_credit_notes'].each do |structure|
      applied_credit_notes << (AppliedCreditNote.from_hash(structure) if structure)
    end
  end

  applied_credit_notes = SKIP unless hash.key?('applied_credit_notes')
  debit_note_number =
    hash.key?('debit_note_number') ? hash['debit_note_number'] : SKIP
  debit_note_uid =
    hash.key?('debit_note_uid') ? hash['debit_note_uid'] : SKIP
  payment_method = hash.key?('payment_method') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:InvoiceEvent1PaymentMethod), hash['payment_method']
  ) : SKIP
  transaction_id =
    hash.key?('transaction_id') ? hash['transaction_id'] : SKIP
  from_collection_method =
    hash.key?('from_collection_method') ? hash['from_collection_method'] : SKIP
  to_collection_method =
    hash.key?('to_collection_method') ? hash['to_collection_method'] : SKIP
  consolidation_level =
    hash.key?('consolidation_level') ? hash['consolidation_level'] : SKIP
  from_status = hash.key?('from_status') ? hash['from_status'] : SKIP
  to_status = hash.key?('to_status') ? hash['to_status'] : SKIP
  due_amount = hash.key?('due_amount') ? hash['due_amount'] : SKIP
  total_amount = hash.key?('total_amount') ? hash['total_amount'] : SKIP
  apply_credit = hash.key?('apply_credit') ? hash['apply_credit'] : SKIP
  credit_note_attributes = CreditNote1.from_hash(hash['credit_note_attributes']) if
    hash['credit_note_attributes']
  payment_id = hash.key?('payment_id') ? hash['payment_id'] : SKIP
  refund_amount = hash.key?('refund_amount') ? hash['refund_amount'] : SKIP
  refund_id = hash.key?('refund_id') ? hash['refund_id'] : SKIP
  prepayment = hash.key?('prepayment') ? hash['prepayment'] : SKIP
  is_advance_invoice =
    hash.key?('is_advance_invoice') ? hash['is_advance_invoice'] : SKIP

  # Create object from extracted values.
  InvoiceEvent1.new(uid,
                    credit_note_number,
                    credit_note_uid,
                    original_amount,
                    applied_amount,
                    transaction_time,
                    memo,
                    role,
                    consolidated_invoice,
                    applied_credit_notes,
                    debit_note_number,
                    debit_note_uid,
                    payment_method,
                    transaction_id,
                    from_collection_method,
                    to_collection_method,
                    consolidation_level,
                    from_status,
                    to_status,
                    due_amount,
                    total_amount,
                    apply_credit,
                    credit_note_attributes,
                    payment_id,
                    refund_amount,
                    refund_id,
                    prepayment,
                    is_advance_invoice)
end

.namesObject

A mapping from model property names to API property names.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/advanced_billing/models/invoice_event1.rb', line 152

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['uid'] = 'uid'
  @_hash['credit_note_number'] = 'credit_note_number'
  @_hash['credit_note_uid'] = 'credit_note_uid'
  @_hash['original_amount'] = 'original_amount'
  @_hash['applied_amount'] = 'applied_amount'
  @_hash['transaction_time'] = 'transaction_time'
  @_hash['memo'] = 'memo'
  @_hash['role'] = 'role'
  @_hash['consolidated_invoice'] = 'consolidated_invoice'
  @_hash['applied_credit_notes'] = 'applied_credit_notes'
  @_hash['debit_note_number'] = 'debit_note_number'
  @_hash['debit_note_uid'] = 'debit_note_uid'
  @_hash['payment_method'] = 'payment_method'
  @_hash['transaction_id'] = 'transaction_id'
  @_hash['from_collection_method'] = 'from_collection_method'
  @_hash['to_collection_method'] = 'to_collection_method'
  @_hash['consolidation_level'] = 'consolidation_level'
  @_hash['from_status'] = 'from_status'
  @_hash['to_status'] = 'to_status'
  @_hash['due_amount'] = 'due_amount'
  @_hash['total_amount'] = 'total_amount'
  @_hash['apply_credit'] = 'apply_credit'
  @_hash['credit_note_attributes'] = 'credit_note_attributes'
  @_hash['payment_id'] = 'payment_id'
  @_hash['refund_amount'] = 'refund_amount'
  @_hash['refund_id'] = 'refund_id'
  @_hash['prepayment'] = 'prepayment'
  @_hash['is_advance_invoice'] = 'is_advance_invoice'
  @_hash
end

.nullablesObject

An array for nullable fields



220
221
222
# File 'lib/advanced_billing/models/invoice_event1.rb', line 220

def self.nullables
  []
end

.optionalsObject

An array for optional fields



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/advanced_billing/models/invoice_event1.rb', line 186

def self.optionals
  %w[
    uid
    credit_note_number
    credit_note_uid
    original_amount
    applied_amount
    transaction_time
    memo
    role
    consolidated_invoice
    applied_credit_notes
    debit_note_number
    debit_note_uid
    payment_method
    transaction_id
    from_collection_method
    to_collection_method
    consolidation_level
    from_status
    to_status
    due_amount
    total_amount
    apply_credit
    credit_note_attributes
    payment_id
    refund_amount
    refund_id
    prepayment
    is_advance_invoice
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (InvoiceEvent1 | Hash)

    value against the validation is performed.



366
367
368
369
370
371
372
# File 'lib/advanced_billing/models/invoice_event1.rb', line 366

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_transaction_timeObject



360
361
362
# File 'lib/advanced_billing/models/invoice_event1.rb', line 360

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end