PHP code example of enlinealab / mercado-pago

1. Go to this page and download the library: Download enlinealab/mercado-pago library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

enlinealab / mercado-pago example snippets


'providers' => [

    /*
     * Laravel Framework Service Providers...
     */

    EnlineaLab\MercadoPago\Providers\MercadoPagoServiceProvider::class,
],

'aliases' => [
    // Otros alias 

    'MP' => EnlineaLab\MercadoPago\Facades\MP::class,
]

return [
    'app_id'     => env('MP_APP_ID', 'SEU CLIENT ID'),
    'app_secret' => env('MP_APP_SECRET', 'SEU CLIENT SECRET')
];



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Exception;
use MP;

class HomeController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $preference_data = array (
            "items" => array (
                array (
                    "title" => "Test2",
                    "quantity" => 1,
                    "currency_id" => "BRL",
                    "unit_price" => 10.41
                )
            )
        );

        try {
            $preference = MP::create_preference($preference_data);
            return redirect()->to($preference['response']['init_point']);
        } catch (Exception $e){
            dd($e->getMessage());
        }
    }
}