Module: Mercadopago::Api

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#credentialsObject



36
37
38
39
40
41
42
# File 'lib/mercadopago/api.rb', line 36

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

#preferenceObject



44
45
46
47
48
49
50
# File 'lib/mercadopago/api.rb', line 44

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



52
53
54
# File 'lib/mercadopago/api.rb', line 52

def config
  @config || {}
end

#config=(config) ⇒ Object



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

def config=(config)
  @config = config
end

#find_payment(payment_id) ⇒ Object



17
18
19
20
21
22
23
24
# 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
  result
end

#find_payment_with_notification(payment_id) ⇒ Object



26
27
28
29
30
# File 'lib/mercadopago/api.rb', line 26

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



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

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