Sha256: 2634ebef1c5fd96f540d11a9c58692fa2993eeec1270057e018475acda0d66d6

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module MpApi
  class Client < Ac::Base
    BASE_URL = "https://api.mercadopago.com/v1/"
    
    attr_reader :access_token
    def initialize(access_token=MpApi.configuration.access_token)
      @headers = {
        "Content-Type": "application/json",
        'x-idempotency-key' => SecureRandom.uuid
      }
      super access_token
    end

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

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

    def create_token(card_token_data)
      response = post("/card_tokens", body: card_token_data, headers: @headers){_1.json['id']}
      response.json
    end
    
    def search_payment_methods(query)
      response = get("/payment_methods/search", params: query) {_1.json['results'][0]}
      response.json
    end

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mp_api-0.1.6 lib/mp_api/client.rb
mp_api-0.1.5 lib/mp_api/client.rb