Suggest edit
Help us improve the documentation
Did you see wrong information and would you like us to explain something else or improve our manuals? Please leave your suggestions on GitHub.

Mercado Pago SDK for PHP

This library provides developers with a simple set of bindings to the Mercado Pago API.

Supported PHP Versions:

This SDK supports PHP version 5.6 or newer.

Installation

Using Composer

  1. Download Composer if not already installed
  2. Go to your project directory and run composer require "mercadopago/dx-php:dev-master" on the command line.
  3. This how your directory structure would look like.

Structure of the Mercado Pago SDK for PHP

  1. Thats all, you have Mercado Pago SDK installed.

Quick Start

  1. You have to require the library from your Composer vendor folder.

Php

  require __DIR__  . '/vendor/autoload.php';
  1. Setup your credentials

You have two types of credentials:

  • For Checkout Mercado Pago:

    Php

    MercadoPago\SDK::setClientId("ENV_CLIENT_ID");
    MercadoPago\SDK::setClientSecret("ENV_CLIENT_SECRET");
    
  • For API or custom checkout:

    Php

    MercadoPago\SDK::setAccessToken("ACCESS_TOKEN");      // On Production
    MercadoPago\SDK::setAccessToken("TEST_ACCESS_TOKEN"); // On Sandbox
    
  1. Using resource objects.

You can interact with all the resources available in the public API, to this each resource is represented by classes according to the following diagram:

SDK resource structure of Mercado Pago

Sample

Php

  <?php

    require_once 'vendor/autoload.php';

    MercadoPago\SDK::setAccessToken("ENV_ACCESS_TOKEN");

    $payment = new MercadoPago\Payment();

    $payment->transaction_amount = 141;
    $payment->token = "YOUR_CARD_TOKEN";
    $payment->description = "Ergonomic Silk Shirt";
    $payment->installments = 1;
    $payment->payment_method_id = "visa";
    $payment->payer = array(
      "email" => "larue.nienow@hotmail.com"
    );

    $payment->save();

    echo $payment->status;

  ?>

Your search returns no results.

Verifique a ortografia de termos de pesquisa ou teste com outras palavras-chave.