Class: GriffNode::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/griffnode/models/transaction.rb

Overview

The canonical, curated public view of a transaction (same shape from create, get and list). Internal fields (capability tokens, client_ip, address_index, derivation/db internals) are deliberately NOT exposed.

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Transaction

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



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
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
271
272
273
274
275
276
277
278
279
280
281
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
# File 'lib/griffnode/models/transaction.rb', line 174

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `GriffNode::Transaction` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `GriffNode::Transaction`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'transaction_id')
    self.transaction_id = attributes[:'transaction_id']
  else
    self.transaction_id = nil
  end

  if attributes.key?(:'status')
    self.status = attributes[:'status']
  else
    self.status = nil
  end

  if attributes.key?(:'type')
    self.type = attributes[:'type']
  end

  if attributes.key?(:'crypto')
    self.crypto = attributes[:'crypto']
  else
    self.crypto = nil
  end

  if attributes.key?(:'deposit_address')
    self.deposit_address = attributes[:'deposit_address']
  end

  if attributes.key?(:'amount_crypto')
    self.amount_crypto = attributes[:'amount_crypto']
  end

  if attributes.key?(:'amount_fiat')
    self.amount_fiat = attributes[:'amount_fiat']
  else
    self.amount_fiat = nil
  end

  if attributes.key?(:'amount_usd')
    self.amount_usd = attributes[:'amount_usd']
  else
    self.amount_usd = nil
  end

  if attributes.key?(:'amount_paid')
    self.amount_paid = attributes[:'amount_paid']
  end

  if attributes.key?(:'amount_remaining')
    self.amount_remaining = attributes[:'amount_remaining']
  end

  if attributes.key?(:'currency_fiat')
    self.currency_fiat = attributes[:'currency_fiat']
  else
    self.currency_fiat = 'USD'
  end

  if attributes.key?(:'fiat_to_usd_rate')
    self.fiat_to_usd_rate = attributes[:'fiat_to_usd_rate']
  end

  if attributes.key?(:'exchange_rate')
    self.exchange_rate = attributes[:'exchange_rate']
  end

  if attributes.key?(:'confirmations_required')
    self.confirmations_required = attributes[:'confirmations_required']
  end

  if attributes.key?(:'payment_url')
    self.payment_url = attributes[:'payment_url']
  end

  if attributes.key?(:'order_id')
    self.order_id = attributes[:'order_id']
  end

  if attributes.key?(:'customer_email')
    self.customer_email = attributes[:'customer_email']
  end

  if attributes.key?(:'items')
    if (value = attributes[:'items']).is_a?(Array)
      self.items = value
    end
  end

  if attributes.key?(:'payments')
    if (value = attributes[:'payments']).is_a?(Array)
      self.payments = value
    end
  end

  if attributes.key?(:'metadata')
    if (value = attributes[:'metadata']).is_a?(Hash)
      self. = value
    end
  end

  if attributes.key?(:'success_url')
    self.success_url = attributes[:'success_url']
  end

  if attributes.key?(:'cancel_url')
    self.cancel_url = attributes[:'cancel_url']
  end

  if attributes.key?(:'created_at')
    self.created_at = attributes[:'created_at']
  else
    self.created_at = nil
  end

  if attributes.key?(:'updated_at')
    self.updated_at = attributes[:'updated_at']
  end

  if attributes.key?(:'expires_at')
    self.expires_at = attributes[:'expires_at']
  else
    self.expires_at = nil
  end
end

Instance Attribute Details

#amount_cryptoObject

Returns the value of attribute amount_crypto.



29
30
31
# File 'lib/griffnode/models/transaction.rb', line 29

def amount_crypto
  @amount_crypto
end

#amount_fiatObject

Returns the value of attribute amount_fiat.



31
32
33
# File 'lib/griffnode/models/transaction.rb', line 31

def amount_fiat
  @amount_fiat
end

#amount_paidObject

Returns the value of attribute amount_paid.



35
36
37
# File 'lib/griffnode/models/transaction.rb', line 35

def amount_paid
  @amount_paid
end

#amount_remainingObject

Returns the value of attribute amount_remaining.



37
38
39
# File 'lib/griffnode/models/transaction.rb', line 37

def amount_remaining
  @amount_remaining
end

#amount_usdObject

Returns the value of attribute amount_usd.



33
34
35
# File 'lib/griffnode/models/transaction.rb', line 33

def amount_usd
  @amount_usd
end

#cancel_urlObject

Returns the value of attribute cancel_url.



64
65
66
# File 'lib/griffnode/models/transaction.rb', line 64

def cancel_url
  @cancel_url
end

#confirmations_requiredObject

Returns the value of attribute confirmations_required.



46
47
48
# File 'lib/griffnode/models/transaction.rb', line 46

def confirmations_required
  @confirmations_required
end

#created_atObject

Returns the value of attribute created_at.



66
67
68
# File 'lib/griffnode/models/transaction.rb', line 66

def created_at
  @created_at
end

#cryptoObject

Returns the value of attribute crypto.



25
26
27
# File 'lib/griffnode/models/transaction.rb', line 25

def crypto
  @crypto
end

#currency_fiatObject

Returns the value of attribute currency_fiat.



39
40
41
# File 'lib/griffnode/models/transaction.rb', line 39

def currency_fiat
  @currency_fiat
end

#customer_emailObject

Returns the value of attribute customer_email.



52
53
54
# File 'lib/griffnode/models/transaction.rb', line 52

def customer_email
  @customer_email
end

#deposit_addressObject

Returns the value of attribute deposit_address.



27
28
29
# File 'lib/griffnode/models/transaction.rb', line 27

def deposit_address
  @deposit_address
end

#exchange_rateObject

USD per unit of crypto, locked at creation.



44
45
46
# File 'lib/griffnode/models/transaction.rb', line 44

def exchange_rate
  @exchange_rate
end

#expires_atObject

Returns the value of attribute expires_at.



70
71
72
# File 'lib/griffnode/models/transaction.rb', line 70

def expires_at
  @expires_at
end

#fiat_to_usd_rateObject

Returns the value of attribute fiat_to_usd_rate.



41
42
43
# File 'lib/griffnode/models/transaction.rb', line 41

def fiat_to_usd_rate
  @fiat_to_usd_rate
end

#itemsObject

Returns the value of attribute items.



54
55
56
# File 'lib/griffnode/models/transaction.rb', line 54

def items
  @items
end

#metadataObject

Free-form key/value (≤20 keys, string values ≤500 chars, ≤4 KB total).



60
61
62
# File 'lib/griffnode/models/transaction.rb', line 60

def 
  @metadata
end

#order_idObject

Returns the value of attribute order_id.



50
51
52
# File 'lib/griffnode/models/transaction.rb', line 50

def order_id
  @order_id
end

#payment_urlObject

Returns the value of attribute payment_url.



48
49
50
# File 'lib/griffnode/models/transaction.rb', line 48

def payment_url
  @payment_url
end

#paymentsObject

On-chain payments detected toward this transaction.



57
58
59
# File 'lib/griffnode/models/transaction.rb', line 57

def payments
  @payments
end

#statusObject

Returns the value of attribute status.



21
22
23
# File 'lib/griffnode/models/transaction.rb', line 21

def status
  @status
end

#success_urlObject

Returns the value of attribute success_url.



62
63
64
# File 'lib/griffnode/models/transaction.rb', line 62

def success_url
  @success_url
end

#transaction_idObject

Returns the value of attribute transaction_id.



19
20
21
# File 'lib/griffnode/models/transaction.rb', line 19

def transaction_id
  @transaction_id
end

#typeObject

Returns the value of attribute type.



23
24
25
# File 'lib/griffnode/models/transaction.rb', line 23

def type
  @type
end

#updated_atObject

Returns the value of attribute updated_at.



68
69
70
# File 'lib/griffnode/models/transaction.rb', line 68

def updated_at
  @updated_at
end

Class Method Details

._deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/griffnode/models/transaction.rb', line 448

def self._deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = GriffNode.const_get(type)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



126
127
128
# File 'lib/griffnode/models/transaction.rb', line 126

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



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
123
# File 'lib/griffnode/models/transaction.rb', line 95

def self.attribute_map
  {
    :'transaction_id' => :'transaction_id',
    :'status' => :'status',
    :'type' => :'type',
    :'crypto' => :'crypto',
    :'deposit_address' => :'deposit_address',
    :'amount_crypto' => :'amount_crypto',
    :'amount_fiat' => :'amount_fiat',
    :'amount_usd' => :'amount_usd',
    :'amount_paid' => :'amount_paid',
    :'amount_remaining' => :'amount_remaining',
    :'currency_fiat' => :'currency_fiat',
    :'fiat_to_usd_rate' => :'fiat_to_usd_rate',
    :'exchange_rate' => :'exchange_rate',
    :'confirmations_required' => :'confirmations_required',
    :'payment_url' => :'payment_url',
    :'order_id' => :'order_id',
    :'customer_email' => :'customer_email',
    :'items' => :'items',
    :'payments' => :'payments',
    :'metadata' => :'metadata',
    :'success_url' => :'success_url',
    :'cancel_url' => :'cancel_url',
    :'created_at' => :'created_at',
    :'updated_at' => :'updated_at',
    :'expires_at' => :'expires_at'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/griffnode/models/transaction.rb', line 424

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



162
163
164
165
166
167
168
169
170
# File 'lib/griffnode/models/transaction.rb', line 162

def self.openapi_nullable
  Set.new([
    :'order_id',
    :'customer_email',
    :'items',
    :'success_url',
    :'cancel_url',
  ])
end

.openapi_typesObject

Attribute type mapping.



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
159
# File 'lib/griffnode/models/transaction.rb', line 131

def self.openapi_types
  {
    :'transaction_id' => :'String',
    :'status' => :'TransactionStatus',
    :'type' => :'String',
    :'crypto' => :'CryptoSymbol',
    :'deposit_address' => :'String',
    :'amount_crypto' => :'Float',
    :'amount_fiat' => :'Float',
    :'amount_usd' => :'Float',
    :'amount_paid' => :'Float',
    :'amount_remaining' => :'Float',
    :'currency_fiat' => :'FiatCurrency',
    :'fiat_to_usd_rate' => :'Float',
    :'exchange_rate' => :'Float',
    :'confirmations_required' => :'Integer',
    :'payment_url' => :'String',
    :'order_id' => :'String',
    :'customer_email' => :'String',
    :'items' => :'Array<LineItem>',
    :'payments' => :'Array<PaymentSplit>',
    :'metadata' => :'Hash<String, String>',
    :'success_url' => :'String',
    :'cancel_url' => :'String',
    :'created_at' => :'Time',
    :'updated_at' => :'Time',
    :'expires_at' => :'Time'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/griffnode/models/transaction.rb', line 379

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      transaction_id == o.transaction_id &&
      status == o.status &&
      type == o.type &&
      crypto == o.crypto &&
      deposit_address == o.deposit_address &&
      amount_crypto == o.amount_crypto &&
      amount_fiat == o.amount_fiat &&
      amount_usd == o.amount_usd &&
      amount_paid == o.amount_paid &&
      amount_remaining == o.amount_remaining &&
      currency_fiat == o.currency_fiat &&
      fiat_to_usd_rate == o.fiat_to_usd_rate &&
      exchange_rate == o.exchange_rate &&
      confirmations_required == o.confirmations_required &&
      payment_url == o.payment_url &&
      order_id == o.order_id &&
      customer_email == o.customer_email &&
      items == o.items &&
      payments == o.payments &&
       == o. &&
      success_url == o.success_url &&
      cancel_url == o.cancel_url &&
      created_at == o.created_at &&
      updated_at == o.updated_at &&
      expires_at == o.expires_at
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/griffnode/models/transaction.rb', line 519

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


411
412
413
# File 'lib/griffnode/models/transaction.rb', line 411

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



417
418
419
# File 'lib/griffnode/models/transaction.rb', line 417

def hash
  [transaction_id, status, type, crypto, deposit_address, amount_crypto, amount_fiat, amount_usd, amount_paid, amount_remaining, currency_fiat, fiat_to_usd_rate, exchange_rate, confirmations_required, payment_url, order_id, customer_email, items, payments, , success_url, cancel_url, created_at, updated_at, expires_at].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



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
# File 'lib/griffnode/models/transaction.rb', line 312

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if @transaction_id.nil?
    invalid_properties.push('invalid value for "transaction_id", transaction_id cannot be nil.')
  end

  if @status.nil?
    invalid_properties.push('invalid value for "status", status cannot be nil.')
  end

  if @crypto.nil?
    invalid_properties.push('invalid value for "crypto", crypto cannot be nil.')
  end

  if @amount_fiat.nil?
    invalid_properties.push('invalid value for "amount_fiat", amount_fiat cannot be nil.')
  end

  if @amount_usd.nil?
    invalid_properties.push('invalid value for "amount_usd", amount_usd cannot be nil.')
  end

  if @currency_fiat.nil?
    invalid_properties.push('invalid value for "currency_fiat", currency_fiat cannot be nil.')
  end

  if @created_at.nil?
    invalid_properties.push('invalid value for "created_at", created_at cannot be nil.')
  end

  if @expires_at.nil?
    invalid_properties.push('invalid value for "expires_at", expires_at cannot be nil.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



495
496
497
# File 'lib/griffnode/models/transaction.rb', line 495

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/griffnode/models/transaction.rb', line 501

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



489
490
491
# File 'lib/griffnode/models/transaction.rb', line 489

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/griffnode/models/transaction.rb', line 352

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @transaction_id.nil?
  return false if @status.nil?
  type_validator = EnumAttributeValidator.new('String', ["basic", "detailed"])
  return false unless type_validator.valid?(@type)
  return false if @crypto.nil?
  return false if @amount_fiat.nil?
  return false if @amount_usd.nil?
  return false if @currency_fiat.nil?
  return false if @created_at.nil?
  return false if @expires_at.nil?
  true
end