Class: AdvancedBilling::ApplyDebitNoteEventData

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

Overview

Example schema for an ‘apply_debit_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(debit_note_number:, debit_note_uid:, original_amount:, applied_amount:, memo: SKIP, transaction_time: SKIP, additional_properties: {}) ⇒ ApplyDebitNoteEventData

Returns a new instance of ApplyDebitNoteEventData.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 68

def initialize(debit_note_number:, debit_note_uid:, original_amount:,
               applied_amount:, memo: SKIP, transaction_time: SKIP,
               additional_properties: {})
  @debit_note_number = debit_note_number
  @debit_note_uid = debit_note_uid
  @original_amount = original_amount
  @applied_amount = applied_amount
  @memo = memo unless memo == SKIP
  @transaction_time = transaction_time unless transaction_time == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#applied_amountString

The amount of the debit note applied to invoice.

Returns:

  • (String)


29
30
31
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 29

def applied_amount
  @applied_amount
end

#debit_note_numberString

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

Returns:

  • (String)


16
17
18
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 16

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)


21
22
23
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 21

def debit_note_uid
  @debit_note_uid
end

#memoString

The debit note memo.

Returns:

  • (String)


33
34
35
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 33

def memo
  @memo
end

#original_amountString

The full, original amount of the debit note.

Returns:

  • (String)


25
26
27
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 25

def original_amount
  @original_amount
end

#transaction_timeDateTime

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

Returns:

  • (DateTime)


38
39
40
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 38

def transaction_time
  @transaction_time
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 85

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  debit_note_number =
    hash.key?('debit_note_number') ? hash['debit_note_number'] : nil
  debit_note_uid =
    hash.key?('debit_note_uid') ? hash['debit_note_uid'] : nil
  original_amount =
    hash.key?('original_amount') ? hash['original_amount'] : nil
  applied_amount =
    hash.key?('applied_amount') ? hash['applied_amount'] : nil
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  transaction_time = if hash.key?('transaction_time')
                       (DateTimeHelper.from_rfc3339(hash['transaction_time']) if hash['transaction_time'])
                     else
                       SKIP
                     end

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  ApplyDebitNoteEventData.new(debit_note_number: debit_note_number,
                              debit_note_uid: debit_note_uid,
                              original_amount: original_amount,
                              applied_amount: applied_amount,
                              memo: memo,
                              transaction_time: transaction_time,
                              additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



41
42
43
44
45
46
47
48
49
50
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 41

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['debit_note_number'] = 'debit_note_number'
  @_hash['debit_note_uid'] = 'debit_note_uid'
  @_hash['original_amount'] = 'original_amount'
  @_hash['applied_amount'] = 'applied_amount'
  @_hash['memo'] = 'memo'
  @_hash['transaction_time'] = 'transaction_time'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
64
65
66
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 61

def self.nullables
  %w[
    memo
    transaction_time
  ]
end

.optionalsObject

An array for optional fields



53
54
55
56
57
58
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 53

def self.optionals
  %w[
    memo
    transaction_time
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.debit_note_number,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.debit_note_uid,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.original_amount,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.applied_amount,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['debit_note_number'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['debit_note_uid'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['original_amount'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['applied_amount'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#to_custom_transaction_timeObject



117
118
119
# File 'lib/advanced_billing/models/apply_debit_note_event_data.rb', line 117

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end