Class: Mercadopago::Client

Inherits:
Object
  • Object
show all
Includes:
Api, Authentication, Preferences
Defined in:
app/models/mercadopago/client.rb,
app/models/mercadopago/client/api.rb,
app/models/mercadopago/client/preferences.rb,
app/models/mercadopago/client/authentication.rb

Defined Under Namespace

Modules: Api, Authentication, Preferences

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Api

#redirect_url

Methods included from Preferences

#create_preferences

Methods included from Authentication

#authenticate

Constructor Details

#initialize(payment_method, options = {}) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
# File 'app/models/mercadopago/client.rb', line 20

def initialize(payment_method, options = {})
  @payment_method = payment_method
  @api_options    = options.clone
  @errors         = []
end

Instance Attribute Details

#auth_responseObject (readonly)

Returns the value of attribute auth_response.



17
18
19
# File 'app/models/mercadopago/client.rb', line 17

def auth_response
  @auth_response
end

#errorsObject (readonly)

Returns the value of attribute errors.



16
17
18
# File 'app/models/mercadopago/client.rb', line 16

def errors
  @errors
end

#preferences_responseObject (readonly)

Returns the value of attribute preferences_response.



18
19
20
# File 'app/models/mercadopago/client.rb', line 18

def preferences_response
  @preferences_response
end

Instance Method Details

#get_operation_info(operation_id) ⇒ Object



26
27
28
29
30
# File 'app/models/mercadopago/client.rb', line 26

def get_operation_info(operation_id)
  url = create_url(notifications_url(operation_id), access_token: access_token)
  options = { content_type: 'application/x-www-form-urlencoded', accept: 'application/json' }
  get(url, options, quiet: true)
end

#get_payment_status(external_reference) ⇒ Object

def get_external_reference(operation_id)

response = send_notification_request(operation_id)
if response
  response['collection']['external_reference']
end

end



39
40
41
42
43
44
45
46
47
# File 'app/models/mercadopago/client.rb', line 39

def get_payment_status(external_reference)
  response = send_search_request(external_reference: external_reference, access_token: access_token)

  if response['results'].empty?
    'pending'
  else
    response['results'][0]['collection']['status']
  end
end