Class: Cryptopay::Transaction

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

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



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

def initialize(attributes = {})
  @attributes = ENCODER.sanitize(attributes)
end

Class Method Details

.build_from_hash(data) ⇒ Cryptopay::Transaction

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:



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

def self.build_from_hash(data)
  attributes = ENCODER.build_from_hash(data)
  new(attributes)
end

Instance Method Details

#amountObject

Transaction amount



84
85
86
# File 'lib/cryptopay/models/transaction.rb', line 84

def amount
  @attributes[:amount]
end

#balanceObject

Account subtotal



94
95
96
# File 'lib/cryptopay/models/transaction.rb', line 94

def balance
  @attributes[:balance]
end

#created_atObject

Transaction creation date and time



137
138
139
# File 'lib/cryptopay/models/transaction.rb', line 137

def created_at
  @attributes[:created_at]
end

#currencyObject

Transaction currency



89
90
91
# File 'lib/cryptopay/models/transaction.rb', line 89

def currency
  @attributes[:currency]
end

#custom_idObject

Transaction description



74
75
76
# File 'lib/cryptopay/models/transaction.rb', line 74

def custom_id
  @attributes[:custom_id]
end

#customer_idObject

The reference ID of your customer



79
80
81
# File 'lib/cryptopay/models/transaction.rb', line 79

def customer_id
  @attributes[:customer_id]
end

#descriptionObject

Transaction description



118
119
120
# File 'lib/cryptopay/models/transaction.rb', line 118

def description
  @attributes[:description]
end

#feeObject

Transaction fee details



99
100
101
# File 'lib/cryptopay/models/transaction.rb', line 99

def fee
  @attributes[:fee]
end

#fee_currencyObject

Transaction fee currency



104
105
106
# File 'lib/cryptopay/models/transaction.rb', line 104

def fee_currency
  @attributes[:fee_currency]
end

#idObject

Account transaction ID



69
70
71
# File 'lib/cryptopay/models/transaction.rb', line 69

def id
  @attributes[:id]
end

#inspectObject



183
184
185
# File 'lib/cryptopay/models/transaction.rb', line 183

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}> JSON: " + JSON.pretty_generate(to_hash)
end

#invalid_propertiesObject

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

Returns:

  • Array for valid properties with the reasons



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/cryptopay/models/transaction.rb', line 143

def invalid_properties
  properties = []

  properties.push('invalid value for "id", id cannot be nil.') if id.nil?

  properties.push('invalid value for "amount", amount cannot be nil.') if amount.nil?

  properties.push('invalid value for "currency", currency cannot be nil.') if currency.nil?

  properties.push('invalid value for "balance", balance cannot be nil.') if balance.nil?

  properties.push('invalid value for "reference_id", reference_id cannot be nil.') if reference_id.nil?

  properties.push('invalid value for "reference_type", reference_type cannot be nil.') if reference_type.nil?

  if !reference_type.nil? && !%w[BankDeposit BankWithdrawal ChannelPayment CoinDeposit CoinWithdrawal ExchangeTransfer Invoice InvoiceRefund ManualBalanceTransaction].include?(reference_type)
    properties.push('invalid value for reference_type, must be one of "BankDeposit", "BankWithdrawal", "ChannelPayment", "CoinDeposit", "CoinWithdrawal", "ExchangeTransfer", "Invoice", "InvoiceRefund", "ManualBalanceTransaction"')
  end

  risk&.invalid_properties&.each do |prop|
    properties.push("invalid value for \"risk\": #{prop}")
  end

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

  properties
end

#reference_idObject

Transaction reference ID in Cryptopay



109
110
111
# File 'lib/cryptopay/models/transaction.rb', line 109

def reference_id
  @attributes[:reference_id]
end

#reference_typeObject



113
114
115
# File 'lib/cryptopay/models/transaction.rb', line 113

def reference_type
  @attributes[:reference_type]
end

#riskObject



132
133
134
# File 'lib/cryptopay/models/transaction.rb', line 132

def risk
  @attributes[:risk]
end

#statusObject

Transaction status



123
124
125
# File 'lib/cryptopay/models/transaction.rb', line 123

def status
  @attributes[:status]
end

#status_contextObject

Transaction status context



128
129
130
# File 'lib/cryptopay/models/transaction.rb', line 128

def status_context
  @attributes[:status_context]
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



179
180
181
# File 'lib/cryptopay/models/transaction.rb', line 179

def to_hash
  ENCODER.to_hash(@attributes)
end

#valid?Boolean

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

Returns:

  • (Boolean)

    true if the model is valid



173
174
175
# File 'lib/cryptopay/models/transaction.rb', line 173

def valid?
  invalid_properties.empty?
end