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/"
MAX_RETRIES =
1

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
# File 'lib/mp_api/client.rb', line 14

def create_payment(body)
  post("/payments", body: body, headers: @headers) { |response| validate_response(response, "id") }
end

#create_token(card_token_data) ⇒ Object



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

def create_token(card_token_data)
  post("/card_tokens", body: card_token_data, headers: @headers) { |response| validate_response(response, "id") }
end

#get_payment(payment_id) ⇒ Object



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

def get_payment(payment_id)
  get("/payments/#{payment_id}") { |response| validate_response(response, "id") }
end

#get_payment_methodsObject



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

def get_payment_methods
  get("/payment_methods") { |response| validate_response(response, "id") }
end

#search_payment_methods(query) ⇒ Object



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

def search_payment_methods(query)
  get("/payment_methods/search", params: query) { |response| validate_response(response, ["results", 0]) }
end

#update_payment(payment_id, body) ⇒ Object



22
23
24
# File 'lib/mp_api/client.rb', line 22

def update_payment(payment_id, body)
  put("/payments/#{payment_id}", body: body, headers: @headers) { |response| validate_response(response, "id") }
end