Class: AdvancedBilling::InvoiceCredit

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

Overview

InvoiceCredit Model.

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, transaction_time: SKIP, memo: SKIP, original_amount: SKIP, applied_amount: SKIP, additional_properties: {}) ⇒ InvoiceCredit

Returns a new instance of InvoiceCredit.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/advanced_billing/models/invoice_credit.rb', line 72

def initialize(uid: SKIP, credit_note_number: SKIP, credit_note_uid: SKIP,
               transaction_time: SKIP, memo: SKIP, original_amount: SKIP,
               applied_amount: SKIP, additional_properties: {})
  @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
  @transaction_time = transaction_time unless transaction_time == SKIP
  @memo = memo unless memo == SKIP
  @original_amount = original_amount unless original_amount == SKIP
  @applied_amount = applied_amount unless applied_amount == 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

TODO: Write general description for this method

Returns:

  • (String)


39
40
41
# File 'lib/advanced_billing/models/invoice_credit.rb', line 39

def applied_amount
  @applied_amount
end

#credit_note_numberString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/advanced_billing/models/invoice_credit.rb', line 19

def credit_note_number
  @credit_note_number
end

#credit_note_uidString

TODO: Write general description for this method

Returns:

  • (String)


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

def credit_note_uid
  @credit_note_uid
end

#memoString

TODO: Write general description for this method

Returns:

  • (String)


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

def memo
  @memo
end

#original_amountString

TODO: Write general description for this method

Returns:

  • (String)


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

def original_amount
  @original_amount
end

#transaction_timeDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


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

def transaction_time
  @transaction_time
end

#uidString

TODO: Write general description for this method

Returns:

  • (String)


15
16
17
# File 'lib/advanced_billing/models/invoice_credit.rb', line 15

def uid
  @uid
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
116
117
118
119
120
121
122
# File 'lib/advanced_billing/models/invoice_credit.rb', line 90

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
  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
  original_amount =
    hash.key?('original_amount') ? hash['original_amount'] : SKIP
  applied_amount =
    hash.key?('applied_amount') ? hash['applied_amount'] : SKIP

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

  # Create object from extracted values.
  InvoiceCredit.new(uid: uid,
                    credit_note_number: credit_note_number,
                    credit_note_uid: credit_note_uid,
                    transaction_time: transaction_time,
                    memo: memo,
                    original_amount: original_amount,
                    applied_amount: applied_amount,
                    additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



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

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['transaction_time'] = 'transaction_time'
  @_hash['memo'] = 'memo'
  @_hash['original_amount'] = 'original_amount'
  @_hash['applied_amount'] = 'applied_amount'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/advanced_billing/models/invoice_credit.rb', line 55

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

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (InvoiceCredit | Hash)

    value against the validation is performed.



130
131
132
133
134
135
136
# File 'lib/advanced_billing/models/invoice_credit.rb', line 130

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



124
125
126
# File 'lib/advanced_billing/models/invoice_credit.rb', line 124

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end