Class: ApiReference::CustomerBalanceTransaction

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/customer_balance_transaction.rb

Overview

CustomerBalanceTransaction 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:, created_at:, starting_balance:, ending_balance:, amount:, action:, description:, invoice:, type:, credit_note:, additional_properties: nil) ⇒ CustomerBalanceTransaction

Returns a new instance of CustomerBalanceTransaction.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 85

def initialize(id:, created_at:, starting_balance:, ending_balance:,
               amount:, action:, description:, invoice:, type:,
               credit_note:, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @id = id
  @created_at = created_at
  @starting_balance = starting_balance
  @ending_balance = ending_balance
  @amount = amount
  @action = action
  @description = description
  @invoice = invoice
  @type = type
  @credit_note = credit_note
  @additional_properties = additional_properties
end

Instance Attribute Details

#actionAction

The value of the amount changed in the transaction.

Returns:



37
38
39
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 37

def action
  @action
end

#amountString

The value of the amount changed in the transaction.

Returns:

  • (String)


33
34
35
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 33

def amount
  @amount
end

#created_atDateTime

The creation time of this transaction.

Returns:

  • (DateTime)


19
20
21
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 19

def created_at
  @created_at
end

#credit_noteCreditNoteTiny

An optional description provided for manual customer balance adjustments.

Returns:



53
54
55
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 53

def credit_note
  @credit_note
end

#descriptionString

An optional description provided for manual customer balance adjustments.

Returns:

  • (String)


41
42
43
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 41

def description
  @description
end

#ending_balanceString

The new value of the customer's balance prior to the transaction, in the customer's currency.

Returns:

  • (String)


29
30
31
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 29

def ending_balance
  @ending_balance
end

#idString

A unique id for this transaction.

Returns:

  • (String)


15
16
17
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 15

def id
  @id
end

#invoiceInvoiceTiny

An optional description provided for manual customer balance adjustments.

Returns:



45
46
47
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 45

def invoice
  @invoice
end

#starting_balanceString

The original value of the customer's balance prior to the transaction, in the customer's currency.

Returns:

  • (String)


24
25
26
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 24

def starting_balance
  @starting_balance
end

#typeType4

An optional description provided for manual customer balance adjustments.

Returns:



49
50
51
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 49

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



105
106
107
108
109
110
111
112
113
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
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 105

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  starting_balance =
    hash.key?('starting_balance') ? hash['starting_balance'] : nil
  ending_balance =
    hash.key?('ending_balance') ? hash['ending_balance'] : nil
  amount = hash.key?('amount') ? hash['amount'] : nil
  action = hash.key?('action') ? hash['action'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  invoice = InvoiceTiny.from_hash(hash['invoice']) if hash['invoice']
  type = hash.key?('type') ? hash['type'] : nil
  credit_note = CreditNoteTiny.from_hash(hash['credit_note']) if hash['credit_note']

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  CustomerBalanceTransaction.new(id: id,
                                 created_at: created_at,
                                 starting_balance: starting_balance,
                                 ending_balance: ending_balance,
                                 amount: amount,
                                 action: action,
                                 description: description,
                                 invoice: invoice,
                                 type: type,
                                 credit_note: credit_note,
                                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 56

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['created_at'] = 'created_at'
  @_hash['starting_balance'] = 'starting_balance'
  @_hash['ending_balance'] = 'ending_balance'
  @_hash['amount'] = 'amount'
  @_hash['action'] = 'action'
  @_hash['description'] = 'description'
  @_hash['invoice'] = 'invoice'
  @_hash['type'] = 'type'
  @_hash['credit_note'] = 'credit_note'
  @_hash
end

.nullablesObject

An array for nullable fields



77
78
79
80
81
82
83
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 77

def self.nullables
  %w[
    description
    invoice
    credit_note
  ]
end

.optionalsObject

An array for optional fields



72
73
74
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 72

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



151
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 151

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.created_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.starting_balance,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.ending_balance,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.amount,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.action,
                              ->(val) { Action.validate(val) }) and
        APIHelper.valid_type?(value.description,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.invoice,
                              ->(val) { InvoiceTiny.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.type,
                              ->(val) { Type4.validate(val) }) and
        APIHelper.valid_type?(value.credit_note,
                              ->(val) { CreditNoteTiny.validate(val) },
                              is_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['created_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['starting_balance'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['ending_balance'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['amount'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['action'],
                            ->(val) { Action.validate(val) }) and
      APIHelper.valid_type?(value['description'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['invoice'],
                            ->(val) { InvoiceTiny.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['type'],
                            ->(val) { Type4.validate(val) }) and
      APIHelper.valid_type?(value['credit_note'],
                            ->(val) { CreditNoteTiny.validate(val) },
                            is_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



217
218
219
220
221
222
223
224
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 217

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, created_at: #{@created_at.inspect}, starting_balance:"\
  " #{@starting_balance.inspect}, ending_balance: #{@ending_balance.inspect}, amount:"\
  " #{@amount.inspect}, action: #{@action.inspect}, description: #{@description.inspect},"\
  " invoice: #{@invoice.inspect}, type: #{@type.inspect}, credit_note:"\
  " #{@credit_note.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_created_atObject



145
146
147
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 145

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_sObject

Provides a human-readable string representation of the object.



208
209
210
211
212
213
214
# File 'lib/api_reference/models/customer_balance_transaction.rb', line 208

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, created_at: #{@created_at}, starting_balance:"\
  " #{@starting_balance}, ending_balance: #{@ending_balance}, amount: #{@amount}, action:"\
  " #{@action}, description: #{@description}, invoice: #{@invoice}, type: #{@type},"\
  " credit_note: #{@credit_note}, additional_properties: #{@additional_properties}>"
end