Class: CheckoutsPe

Inherits:
OpenPayResource show all
Defined in:
lib/openpay/peru/checkouts_pe.rb

Instance Attribute Summary

Attributes inherited from OpenPayResource

#api_hook

Instance Method Summary collapse

Methods inherited from OpenPayResource

#delete, #delete_all, #each, #env, #errors?, #get_with_custom_url, #hash2json, #initialize, #json2hash, #post, #put

Constructor Details

This class inherits a constructor from OpenPayResource

Instance Method Details

#all(customer_id = nil) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/openpay/peru/checkouts_pe.rb', line 28

def all(customer_id = nil)
  if customer_id
    customers = @api_hook.create(:customers)
    customers.all_checkouts(customer_id)
  else
    super ''
  end
end

#create(checkout, customer_id = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/openpay/peru/checkouts_pe.rb', line 5

def create(checkout, customer_id = nil)
  amount = checkout[:amount].to_s.split('.')
  if amount.length > 0
    LOG.warn "The amount have decimals. Revoming.."
  end
  checkout[:amount] = amount[0]
  if customer_id
    customers = @api_hook.create(:customers)
    customers.create_checkout(customer_id, checkout)
  else
    super checkout
  end
end

#get(checkout_id = '', customer_id = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/openpay/peru/checkouts_pe.rb', line 19

def get(checkout_id = '', customer_id = nil)
  if customer_id
    customers = @api_hook.create(:customers)
    customers.get_checkout(customer_id, checkout_id)
  else
    super checkout_id
  end
end

#get_by_order_id(order_id) ⇒ Object



46
47
48
49
# File 'lib/openpay/peru/checkouts_pe.rb', line 46

def get_by_order_id(order_id)
  url = @base_url + "#{@merchant_id}/orderId/#{order_id}/checkouts"
  get_with_custom_url(url)
end

#list(search_params, customer_id = nil) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/openpay/peru/checkouts_pe.rb', line 37

def list(search_params, customer_id = nil)
  if customer_id
    customers = @api_hook.create(:customers)
    customers.list_checkouts(customer_id, search_params)
  else
    super search_params
  end
end