Class: AdvancedBilling::ApplyCreditNoteEventData

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

Overview

Example schema for an ‘apply_credit_note` event

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) ⇒ ApplyCreditNoteEventData

Returns a new instance of ApplyCreditNoteEventData.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 96

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)
  @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
end

Instance Attribute Details

#applied_amountString

The amount of the credit note applied to invoice.

Returns:

  • (String)


35
36
37
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 35

def applied_amount
  @applied_amount
end

#applied_credit_notesArray[AppliedCreditNote]

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

Returns:



57
58
59
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 57

def applied_credit_notes
  @applied_credit_notes
end

#consolidated_invoiceTrueClass | FalseClass

Shows whether it was applied to consolidated invoice or not

Returns:

  • (TrueClass | FalseClass)


52
53
54
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 52

def consolidated_invoice
  @consolidated_invoice
end

#credit_note_numberString

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

Returns:

  • (String)


22
23
24
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 22

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)


27
28
29
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 27

def credit_note_uid
  @credit_note_uid
end

#memoString

The credit note memo.

Returns:

  • (String)


44
45
46
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 44

def memo
  @memo
end

#original_amountString

The full, original amount of the credit note.

Returns:

  • (String)


31
32
33
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 31

def original_amount
  @original_amount
end

#roleString

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

Returns:

  • (String)


48
49
50
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 48

def role
  @role
end

#transaction_timeDateTime

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

Returns:

  • (DateTime)


40
41
42
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 40

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)


17
18
19
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 17

def uid
  @uid
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 114

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')

  # Create object from extracted values.
  ApplyCreditNoteEventData.new(uid,
                               credit_note_number,
                               credit_note_uid,
                               original_amount,
                               applied_amount,
                               transaction_time,
                               memo,
                               role,
                               consolidated_invoice,
                               applied_credit_notes)
end

.namesObject

A mapping from model property names to API property names.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 60

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
end

.nullablesObject

An array for nullable fields



92
93
94
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 92

def self.nullables
  []
end

.optionalsObject

An array for optional fields



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 76

def self.optionals
  %w[
    uid
    credit_note_number
    credit_note_uid
    original_amount
    applied_amount
    transaction_time
    memo
    role
    consolidated_invoice
    applied_credit_notes
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



166
167
168
169
170
171
172
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 166

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



160
161
162
# File 'lib/advanced_billing/models/apply_credit_note_event_data.rb', line 160

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end