Class: CoinGate::Merchant::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/coingate/merchant/order.rb

Constant Summary collapse

STATUSES =
%w(new pending confirming paid invalid canceled expired failed)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Order



4
5
6
7
8
9
10
11
12
# File 'lib/coingate/merchant/order.rb', line 4

def initialize(params)
  @order = params

  @order.each do |name, value|
    self.define_singleton_method name do
      value
    end
  end
end

Class Method Details

.create(params, authentication = {}, options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/coingate/merchant/order.rb', line 46

def self.create(params, authentication={}, options={})
  create!(params, authentication, options)
rescue CoinGate::OrderIsNotValid
  false
end

.create!(params, authentication = {}, options = {}) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/coingate/merchant/order.rb', line 38

def self.create!(params, authentication={}, options={})
  response_code, order = CoinGate.api_request('/orders', :post, params, authentication)

  if response_code == 200
    self.new(order)
  end
end

.find(order_id, authentication = {}, options = {}) ⇒ Object



32
33
34
35
36
# File 'lib/coingate/merchant/order.rb', line 32

def self.find(order_id, authentication={}, options={})
  find!(order_id, authentication, options)
rescue CoinGate::OrderNotFound
  false
end

.find!(order_id, authentication = {}, options = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/coingate/merchant/order.rb', line 24

def self.find!(order_id, authentication={}, options={})
  response_code, order = CoinGate.api_request("/orders/#{order_id}", :get, {}, authentication)

  if response_code == 200
    self.new(order)
  end
end

Instance Method Details

#to_hashObject



20
21
22
# File 'lib/coingate/merchant/order.rb', line 20

def to_hash
  @order
end