Class: Cryptopay::Invoice

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Invoice

Initializes the object

Parameters:

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

    Model attributes in the form of hash



90
91
92
# File 'lib/cryptopay/models/invoice.rb', line 90

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

Class Method Details

.build_from_hash(data) ⇒ Cryptopay::Invoice

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:



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

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

Instance Method Details

#addressObject

Invoice cryptocurrency address



122
123
124
# File 'lib/cryptopay/models/invoice.rb', line 122

def address
  @attributes[:address]
end

#created_atObject

Invoice creation date and time



209
210
211
# File 'lib/cryptopay/models/invoice.rb', line 209

def created_at
  @attributes[:created_at]
end

#custom_idObject

Invoice reference ID in your system



100
101
102
# File 'lib/cryptopay/models/invoice.rb', line 100

def custom_id
  @attributes[:custom_id]
end

#customer_idObject

The internal ID of your customer that the invoice relates to



105
106
107
# File 'lib/cryptopay/models/invoice.rb', line 105

def customer_id
  @attributes[:customer_id]
end

#descriptionObject

Invoice description



185
186
187
# File 'lib/cryptopay/models/invoice.rb', line 185

def description
  @attributes[:description]
end

#exchangeObject



171
172
173
# File 'lib/cryptopay/models/invoice.rb', line 171

def exchange
  @attributes[:exchange]
end

#expires_atObject

Invoice expiration date and time



214
215
216
# File 'lib/cryptopay/models/invoice.rb', line 214

def expires_at
  @attributes[:expires_at]
end

#feeObject

Processing fee



147
148
149
# File 'lib/cryptopay/models/invoice.rb', line 147

def fee
  @attributes[:fee]
end

#fee_currencyObject

Processing fee currency



152
153
154
# File 'lib/cryptopay/models/invoice.rb', line 152

def fee_currency
  @attributes[:fee_currency]
end

#hosted_page_urlObject

Invoice hosted page that renders invoice details



204
205
206
# File 'lib/cryptopay/models/invoice.rb', line 204

def hosted_page_url
  @attributes[:hosted_page_url]
end

#idObject

Invoice ID



95
96
97
# File 'lib/cryptopay/models/invoice.rb', line 95

def id
  @attributes[:id]
end

#inspectObject



288
289
290
# File 'lib/cryptopay/models/invoice.rb', line 288

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



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
# File 'lib/cryptopay/models/invoice.rb', line 220

def invalid_properties
  properties = []

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

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

  if !status.nil? && !%w[new completed unresolved refunded cancelled].include?(status)
    properties.push('invalid value for status, must be one of "new", "completed", "unresolved", "refunded", "cancelled"')
  end

  if !status_context.nil? && !%w[overpaid underpaid paid_late illicit_resource].include?(status_context)
    properties.push('invalid value for status_context, must be one of "overpaid", "underpaid", "paid_late", "illicit_resource"')
  end

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

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

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

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

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

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

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

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

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

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

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

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

  transactions&.each_with_index do |item, index|
    item.invalid_properties.each do |prop|
      properties.push("invalid value for \"transactions.#{index}\": #{prop}")
    end
  end

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

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

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

  properties
end

#metadataObject

Key-value data



190
191
192
# File 'lib/cryptopay/models/invoice.rb', line 190

def 
  @attributes[:metadata]
end

#nameObject

Invoice name



180
181
182
# File 'lib/cryptopay/models/invoice.rb', line 180

def name
  @attributes[:name]
end

#networkObject

Cryptocurrency network



127
128
129
# File 'lib/cryptopay/models/invoice.rb', line 127

def network
  @attributes[:network]
end

which amount already paid



167
168
169
# File 'lib/cryptopay/models/invoice.rb', line 167

def paid_amount
  @attributes[:paid_amount]
end

#pay_amountObject

Cryptocurrency amount to pay



157
158
159
# File 'lib/cryptopay/models/invoice.rb', line 157

def pay_amount
  @attributes[:pay_amount]
end

#pay_currencyObject

Cryptocurrency type



162
163
164
# File 'lib/cryptopay/models/invoice.rb', line 162

def pay_currency
  @attributes[:pay_currency]
end

#price_amountObject

Invoice amount



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

def price_amount
  @attributes[:price_amount]
end

#price_currencyObject

Invoice amount currency



142
143
144
# File 'lib/cryptopay/models/invoice.rb', line 142

def price_currency
  @attributes[:price_currency]
end

#statusObject



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

def status
  @attributes[:status]
end

#status_contextObject



117
118
119
# File 'lib/cryptopay/models/invoice.rb', line 117

def status_context
  @attributes[:status_context]
end

#subscription_idObject



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

def subscription_id
  @attributes[:subscription_id]
end

#success_redirect_urlObject

URL that a customer will be redirected to upon transaction confirmation



195
196
197
# File 'lib/cryptopay/models/invoice.rb', line 195

def success_redirect_url
  @attributes[:success_redirect_url]
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



284
285
286
# File 'lib/cryptopay/models/invoice.rb', line 284

def to_hash
  ENCODER.to_hash(@attributes)
end

#transactionsObject



175
176
177
# File 'lib/cryptopay/models/invoice.rb', line 175

def transactions
  @attributes[:transactions]
end

#unsuccess_redirect_urlObject



199
200
201
# File 'lib/cryptopay/models/invoice.rb', line 199

def unsuccess_redirect_url
  @attributes[:unsuccess_redirect_url]
end

#uriObject

Invoice URI. May be used for generating a QR code



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

def uri
  @attributes[:uri]
end

#valid?Boolean

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

Returns:

  • (Boolean)

    true if the model is valid



278
279
280
# File 'lib/cryptopay/models/invoice.rb', line 278

def valid?
  invalid_properties.empty?
end