Class: ModernTreasury::Return

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/modern_treasury/models/mreturn.rb

Overview

Return 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:, object:, live_mode:, created_at:, updated_at:, returnable_id:, returnable_type:, code:, reason:, date_of_death:, additional_information:, status:, transaction_line_item_id:, transaction_id:, internal_account_id:, type:, amount:, currency:, failure_reason:, role:, current_return:, reference_numbers:, ledger_transaction_id:) ⇒ Return

Returns a new instance of Return.



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
# File 'lib/modern_treasury/models/mreturn.rb', line 165

def initialize(id:, object:, live_mode:, created_at:, updated_at:,
               returnable_id:, returnable_type:, code:, reason:,
               date_of_death:, additional_information:, status:,
               transaction_line_item_id:, transaction_id:,
               internal_account_id:, type:, amount:, currency:,
               failure_reason:, role:, current_return:, reference_numbers:,
               ledger_transaction_id:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @returnable_id = returnable_id
  @returnable_type = returnable_type
  @code = code
  @reason = reason
  @date_of_death = date_of_death
  @additional_information = additional_information
  @status = status
  @transaction_line_item_id = transaction_line_item_id
  @transaction_id = transaction_id
  @internal_account_id = 
  @type = type
  @amount = amount
  @currency = currency
  @failure_reason = failure_reason
  @role = role
  @current_return = current_return
  @reference_numbers = reference_numbers
  @ledger_transaction_id = ledger_transaction_id
end

Instance Attribute Details

#additional_informationString

Some returns may include additional information from the bank. In these cases, this string will be present.

Returns:

  • (String)


61
62
63
# File 'lib/modern_treasury/models/mreturn.rb', line 61

def additional_information
  @additional_information
end

#amountInteger

Value in specified currency’s smallest unit. e.g. $10 would be represented as 1000.

Returns:

  • (Integer)


87
88
89
# File 'lib/modern_treasury/models/mreturn.rb', line 87

def amount
  @amount
end

#codeCode1

The return code. For ACH returns, this is the required ACH return code.

Returns:



46
47
48
# File 'lib/modern_treasury/models/mreturn.rb', line 46

def code
  @code
end

#created_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


29
30
31
# File 'lib/modern_treasury/models/mreturn.rb', line 29

def created_at
  @created_at
end

#currencyCurrency

Three-letter ISO currency code.

Returns:



91
92
93
# File 'lib/modern_treasury/models/mreturn.rb', line 91

def currency
  @currency
end

#current_returnReturn

The role of the return, can be ‘originating` or `receiving`.

Returns:



104
105
106
# File 'lib/modern_treasury/models/mreturn.rb', line 104

def current_return
  @current_return
end

#date_of_deathDate

If the return code is ‘R14` or `R15` this is the date the deceased counterparty passed away.

Returns:

  • (Date)


56
57
58
# File 'lib/modern_treasury/models/mreturn.rb', line 56

def date_of_death
  @date_of_death
end

#failure_reasonString

If an originating return failed to be processed by the bank, a description of the failure reason will be available.

Returns:

  • (String)


96
97
98
# File 'lib/modern_treasury/models/mreturn.rb', line 96

def failure_reason
  @failure_reason
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


15
16
17
# File 'lib/modern_treasury/models/mreturn.rb', line 15

def id
  @id
end

#internal_account_idUUID | String

The ID of the relevant Internal Account.

Returns:

  • (UUID | String)


77
78
79
# File 'lib/modern_treasury/models/mreturn.rb', line 77

def 
  @internal_account_id
end

#ledger_transaction_idUUID | String

The ID of the ledger transaction linked to the return.

Returns:

  • (UUID | String)


112
113
114
# File 'lib/modern_treasury/models/mreturn.rb', line 112

def ledger_transaction_id
  @ledger_transaction_id
end

#live_modeTrueClass | FalseClass

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (TrueClass | FalseClass)


24
25
26
# File 'lib/modern_treasury/models/mreturn.rb', line 24

def live_mode
  @live_mode
end

#objectString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/modern_treasury/models/mreturn.rb', line 19

def object
  @object
end

#reasonString

Often the bank will provide an explanation for the return, which is a short human readable string.

Returns:

  • (String)


51
52
53
# File 'lib/modern_treasury/models/mreturn.rb', line 51

def reason
  @reason
end

#reference_numbersArray[PaymentReference]

An array of Payment Reference objects.

Returns:



108
109
110
# File 'lib/modern_treasury/models/mreturn.rb', line 108

def reference_numbers
  @reference_numbers
end

#returnable_idUUID | String

The ID of the object being returned or ‘null`.

Returns:

  • (UUID | String)


38
39
40
# File 'lib/modern_treasury/models/mreturn.rb', line 38

def returnable_id
  @returnable_id
end

#returnable_typeReturnableType

The type of object being returned or ‘null`.

Returns:



42
43
44
# File 'lib/modern_treasury/models/mreturn.rb', line 42

def returnable_type
  @returnable_type
end

#roleRole

The role of the return, can be ‘originating` or `receiving`.

Returns:



100
101
102
# File 'lib/modern_treasury/models/mreturn.rb', line 100

def role
  @role
end

#statusStatus4

The current status of the return.

Returns:



65
66
67
# File 'lib/modern_treasury/models/mreturn.rb', line 65

def status
  @status
end

#transaction_idUUID | String

The ID of the relevant Transaction or ‘null`.

Returns:

  • (UUID | String)


73
74
75
# File 'lib/modern_treasury/models/mreturn.rb', line 73

def transaction_id
  @transaction_id
end

#transaction_line_item_idUUID | String

The ID of the relevant Transaction Line Item or ‘null`.

Returns:

  • (UUID | String)


69
70
71
# File 'lib/modern_treasury/models/mreturn.rb', line 69

def transaction_line_item_id
  @transaction_line_item_id
end

#typeType6

The type of return. Can be one of: ‘ach`, `ach_noc`, `au_becs`, `bacs`, `eft`, `interac`, `manual`, `paper_item`, `wire`.

Returns:



82
83
84
# File 'lib/modern_treasury/models/mreturn.rb', line 82

def type
  @type
end

#updated_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


34
35
36
# File 'lib/modern_treasury/models/mreturn.rb', line 34

def updated_at
  @updated_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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
266
267
268
269
270
# File 'lib/modern_treasury/models/mreturn.rb', line 198

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  object = hash.key?('object') ? hash['object'] : nil
  live_mode = hash.key?('live_mode') ? hash['live_mode'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               end
  returnable_id = hash.key?('returnable_id') ? hash['returnable_id'] : nil
  returnable_type =
    hash.key?('returnable_type') ? hash['returnable_type'] : nil
  code = hash.key?('code') ? hash['code'] : nil
  reason = hash.key?('reason') ? hash['reason'] : nil
  date_of_death = hash.key?('date_of_death') ? hash['date_of_death'] : nil
  additional_information =
    hash.key?('additional_information') ? hash['additional_information'] : nil
  status = hash.key?('status') ? hash['status'] : nil
  transaction_line_item_id =
    hash.key?('transaction_line_item_id') ? hash['transaction_line_item_id'] : nil
  transaction_id =
    hash.key?('transaction_id') ? hash['transaction_id'] : nil
   =
    hash.key?('internal_account_id') ? hash['internal_account_id'] : nil
  type = hash.key?('type') ? hash['type'] : nil
  amount = hash.key?('amount') ? hash['amount'] : nil
  currency = hash.key?('currency') ? hash['currency'] : nil
  failure_reason =
    hash.key?('failure_reason') ? hash['failure_reason'] : nil
  role = hash.key?('role') ? hash['role'] : nil
  current_return = Return.from_hash(hash['current_return']) if hash['current_return']
  # Parameter is an array, so we need to iterate through it
  reference_numbers = nil
  unless hash['reference_numbers'].nil?
    reference_numbers = []
    hash['reference_numbers'].each do |structure|
      reference_numbers << (PaymentReference.from_hash(structure) if structure)
    end
  end

  reference_numbers = nil unless hash.key?('reference_numbers')
  ledger_transaction_id =
    hash.key?('ledger_transaction_id') ? hash['ledger_transaction_id'] : nil

  # Create object from extracted values.
  Return.new(id: id,
             object: object,
             live_mode: live_mode,
             created_at: created_at,
             updated_at: updated_at,
             returnable_id: returnable_id,
             returnable_type: returnable_type,
             code: code,
             reason: reason,
             date_of_death: date_of_death,
             additional_information: additional_information,
             status: status,
             transaction_line_item_id: transaction_line_item_id,
             transaction_id: transaction_id,
             internal_account_id: ,
             type: type,
             amount: amount,
             currency: currency,
             failure_reason: failure_reason,
             role: role,
             current_return: current_return,
             reference_numbers: reference_numbers,
             ledger_transaction_id: ledger_transaction_id)
end

.namesObject

A mapping from model property names to API property names.



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
# File 'lib/modern_treasury/models/mreturn.rb', line 115

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['object'] = 'object'
  @_hash['live_mode'] = 'live_mode'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['returnable_id'] = 'returnable_id'
  @_hash['returnable_type'] = 'returnable_type'
  @_hash['code'] = 'code'
  @_hash['reason'] = 'reason'
  @_hash['date_of_death'] = 'date_of_death'
  @_hash['additional_information'] = 'additional_information'
  @_hash['status'] = 'status'
  @_hash['transaction_line_item_id'] = 'transaction_line_item_id'
  @_hash['transaction_id'] = 'transaction_id'
  @_hash['internal_account_id'] = 'internal_account_id'
  @_hash['type'] = 'type'
  @_hash['amount'] = 'amount'
  @_hash['currency'] = 'currency'
  @_hash['failure_reason'] = 'failure_reason'
  @_hash['role'] = 'role'
  @_hash['current_return'] = 'current_return'
  @_hash['reference_numbers'] = 'reference_numbers'
  @_hash['ledger_transaction_id'] = 'ledger_transaction_id'
  @_hash
end

.nullablesObject

An array for nullable fields



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/modern_treasury/models/mreturn.rb', line 149

def self.nullables
  %w[
    returnable_id
    returnable_type
    code
    reason
    date_of_death
    additional_information
    transaction_line_item_id
    transaction_id
    internal_account_id
    failure_reason
    ledger_transaction_id
  ]
end

.optionalsObject

An array for optional fields



144
145
146
# File 'lib/modern_treasury/models/mreturn.rb', line 144

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Return | Hash)

    value against the validation is performed.



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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/modern_treasury/models/mreturn.rb', line 282

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.object,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.live_mode,
                              ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
        APIHelper.valid_type?(value.created_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.updated_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.returnable_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.returnable_type,
                              ->(val) { ReturnableType.validate(val) }) and
        APIHelper.valid_type?(value.code,
                              ->(val) { Code1.validate(val) }) and
        APIHelper.valid_type?(value.reason,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.date_of_death,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.additional_information,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.status,
                              ->(val) { Status4.validate(val) }) and
        APIHelper.valid_type?(value.transaction_line_item_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.transaction_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.type,
                              ->(val) { Type6.validate(val) }) and
        APIHelper.valid_type?(value.amount,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.currency,
                              ->(val) { Currency.validate(val) }) and
        APIHelper.valid_type?(value.failure_reason,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.role,
                              ->(val) { Role.validate(val) }) and
        APIHelper.valid_type?(value.current_return,
                              ->(val) { Return.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.reference_numbers,
                              ->(val) { PaymentReference.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true) and
        APIHelper.valid_type?(value.ledger_transaction_id,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['object'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['live_mode'],
                            ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
      APIHelper.valid_type?(value['created_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['updated_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['returnable_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['returnable_type'],
                            ->(val) { ReturnableType.validate(val) }) and
      APIHelper.valid_type?(value['code'],
                            ->(val) { Code1.validate(val) }) and
      APIHelper.valid_type?(value['reason'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['date_of_death'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['additional_information'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['status'],
                            ->(val) { Status4.validate(val) }) and
      APIHelper.valid_type?(value['transaction_line_item_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['transaction_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['internal_account_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['type'],
                            ->(val) { Type6.validate(val) }) and
      APIHelper.valid_type?(value['amount'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['currency'],
                            ->(val) { Currency.validate(val) }) and
      APIHelper.valid_type?(value['failure_reason'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['role'],
                            ->(val) { Role.validate(val) }) and
      APIHelper.valid_type?(value['current_return'],
                            ->(val) { Return.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['reference_numbers'],
                            ->(val) { PaymentReference.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) and
      APIHelper.valid_type?(value['ledger_transaction_id'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/modern_treasury/models/mreturn.rb', line 407

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, object: #{@object.inspect}, live_mode:"\
  " #{@live_mode.inspect}, created_at: #{@created_at.inspect}, updated_at:"\
  " #{@updated_at.inspect}, returnable_id: #{@returnable_id.inspect}, returnable_type:"\
  " #{@returnable_type.inspect}, code: #{@code.inspect}, reason: #{@reason.inspect},"\
  " date_of_death: #{@date_of_death.inspect}, additional_information:"\
  " #{@additional_information.inspect}, status: #{@status.inspect}, transaction_line_item_id:"\
  " #{@transaction_line_item_id.inspect}, transaction_id: #{@transaction_id.inspect},"\
  " internal_account_id: #{@internal_account_id.inspect}, type: #{@type.inspect}, amount:"\
  " #{@amount.inspect}, currency: #{@currency.inspect}, failure_reason:"\
  " #{@failure_reason.inspect}, role: #{@role.inspect}, current_return:"\
  " #{@current_return.inspect}, reference_numbers: #{@reference_numbers.inspect},"\
  " ledger_transaction_id: #{@ledger_transaction_id.inspect}>"
end

#to_custom_created_atObject



272
273
274
# File 'lib/modern_treasury/models/mreturn.rb', line 272

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



276
277
278
# File 'lib/modern_treasury/models/mreturn.rb', line 276

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/modern_treasury/models/mreturn.rb', line 393

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, object: #{@object}, live_mode: #{@live_mode}, created_at:"\
  " #{@created_at}, updated_at: #{@updated_at}, returnable_id: #{@returnable_id},"\
  " returnable_type: #{@returnable_type}, code: #{@code}, reason: #{@reason}, date_of_death:"\
  " #{@date_of_death}, additional_information: #{@additional_information}, status: #{@status},"\
  " transaction_line_item_id: #{@transaction_line_item_id}, transaction_id:"\
  " #{@transaction_id}, internal_account_id: #{@internal_account_id}, type: #{@type}, amount:"\
  " #{@amount}, currency: #{@currency}, failure_reason: #{@failure_reason}, role: #{@role},"\
  " current_return: #{@current_return}, reference_numbers: #{@reference_numbers},"\
  " ledger_transaction_id: #{@ledger_transaction_id}>"
end