Module: Mercadopago::Api

Included in:
Mp
Defined in:
lib/mercadopago/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#credentialsObject



40
41
42
43
44
45
46
# File 'lib/mercadopago/api.rb', line 40

def credentials
  if @credentials.empty?
    raise "Please set yours Credentials, using set_credentials"
  else
    @credentials
  end
end

#preferenceObject



48
49
50
51
52
53
54
# File 'lib/mercadopago/api.rb', line 48

def preference
  if @preference.nil?
    raise "You have to create or get a preference first" 
  else
    @preference
  end
end

#sdkObject (readonly)

Returns the value of attribute sdk.



6
7
8
# File 'lib/mercadopago/api.rb', line 6

def sdk
  @sdk
end

Instance Method Details



8
9
10
11
12
13
14
15
# File 'lib/mercadopago/api.rb', line 8

def checkout_link(data)
  preference = sdk.create_checkout_preference(data, config[:excluded_payment_methods])
  if config[:sandbox]
    preference['sandbox_init_point']
  else
    preference['init_point']
  end
end

#configObject



56
57
58
# File 'lib/mercadopago/api.rb', line 56

def config
  @config || {}
end

#config=(config) ⇒ Object



60
61
62
# File 'lib/mercadopago/api.rb', line 60

def config=(config)
  @config = config
end

#find_payment(payment_id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mercadopago/api.rb', line 17

def find_payment(payment_id)
  if config[:sandbox]
    result = sdk.search_payments_where({:id => payment_id})['results'].first
  else
    result = sdk.search_payment(payment_id)
  end
  if result["collection"].nil?
result
			else
result["collection"]
			end
end

#find_payment_with_notification(payment_id) ⇒ Object



30
31
32
33
34
# File 'lib/mercadopago/api.rb', line 30

def find_payment_with_notification(payment_id)
  result = sdk.get_payment_info(payment_id)
  payment = result['collection']
  payment[:code] = result[:code]
end

#set_credentials(client_id, client_secret) ⇒ Object



64
65
66
67
68
69
# File 'lib/mercadopago/api.rb', line 64

def set_credentials(client_id, client_secret)
  @credentials = {
    :client_id => client_id,
    :client_secret => client_secret
  }
end