Class: MpApi::Client

Inherits:
Ac::Base
  • Object
show all
Defined in:
lib/mp_api/client.rb

Constant Summary collapse

BASE_URL =
"https://api.mercadopago.com/v1/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token = MpApi.configuration.access_token) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
# File 'lib/mp_api/client.rb', line 6

def initialize(access_token=MpApi.configuration.access_token)
  @headers = {
    "Content-Type": "application/json",
    'x-idempotency-key' => SecureRandom.uuid
  }
  super access_token
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/mp_api/client.rb', line 5

def access_token
  @access_token
end

Instance Method Details

#create_payment(body) ⇒ Object



14
15
16
17
# File 'lib/mp_api/client.rb', line 14

def create_payment(body)
  response = post("/payments", body: body, headers: @headers) {_1.json['id']}
  response.json
end

#create_token(card_token_data) ⇒ Object



24
25
26
27
# File 'lib/mp_api/client.rb', line 24

def create_token(card_token_data)
  response = post("/card_tokens", body: card_token_data, headers: @headers){_1.json['id']}
  response.json
end

#get_payment(payment_id) ⇒ Object



19
20
21
22
# File 'lib/mp_api/client.rb', line 19

def get_payment(payment_id)
    response = get("/payments/#{payment_id}") {_1.json['id']}
    response.json
end

#get_payment_methodsObject



34
35
36
37
# File 'lib/mp_api/client.rb', line 34

def get_payment_methods
  response = get("/payment_methods") {_1.json['id']}
  response.json
end

#search_payment_methods(query) ⇒ Object



29
30
31
32
# File 'lib/mp_api/client.rb', line 29

def search_payment_methods(query)
  response = get("/payment_methods/search", params: query) {_1.json['results'][0]}
  response.json
end