Class: Cielo::API30::Sale

Inherits:
Object
  • Object
show all
Defined in:
lib/cielo/api30/sale.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(merchant_order_id) ⇒ Sale

Returns a new instance of Sale.



8
9
10
# File 'lib/cielo/api30/sale.rb', line 8

def initialize(merchant_order_id)
  @merchant_order_id = merchant_order_id
end

Instance Attribute Details

#customerObject

Returns the value of attribute customer.



4
5
6
# File 'lib/cielo/api30/sale.rb', line 4

def customer
  @customer
end

#merchant_order_idObject

Returns the value of attribute merchant_order_id.



4
5
6
# File 'lib/cielo/api30/sale.rb', line 4

def merchant_order_id
  @merchant_order_id
end

#paymentObject

Returns the value of attribute payment.



4
5
6
# File 'lib/cielo/api30/sale.rb', line 4

def payment
  @payment
end

Class Method Details

.from_json(data) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/cielo/api30/sale.rb', line 18

def self.from_json(data)
  return if data.nil?

  sale = new(data["MerchantOrderId"])
  sale.customer = Customer.from_json(data["Customer"])
  sale.payment = Payment.from_json(data["Payment"])
  sale
end

Instance Method Details

#as_json(options = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/cielo/api30/sale.rb', line 27

def as_json(options={})
  {
    MerchantOrderId: @merchant_order_id,
    Customer: @customer,
    Payment: @payment
  }
end

#to_json(*options) ⇒ Object



12
13
14
15
16
# File 'lib/cielo/api30/sale.rb', line 12

def to_json(*options)
  hash = as_json(*options)
  hash.reject! {|k,v| v.nil?}
  hash.to_json(*options)
end