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
SAVE_RESPONSES =
true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



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

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.



7
8
9
# File 'lib/mp_api/client.rb', line 7

def access_token
  @access_token
end

Instance Method Details

#create_card(customer_id, body) ⇒ Object



44
45
46
# File 'lib/mp_api/client.rb', line 44

def create_card(customer_id, body)
  post("/customers/#{customer_id}/cards", body: body, headers: @headers) { |response| validate_response(response, "id") }
end

#create_customer(body) ⇒ Object



40
41
42
# File 'lib/mp_api/client.rb', line 40

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

#create_payment(body) ⇒ Object



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

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

#create_token(card_token_data) ⇒ Object



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

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



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

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

#get_payment_methodsObject



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

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

#search_payment_methods(query) ⇒ Object



32
33
34
# File 'lib/mp_api/client.rb', line 32

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

#update_payment(payment_id, body) ⇒ Object



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

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