PHP code example of livepixel / mercado-pago

1. Go to this page and download the library: Download livepixel/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/ */

    

livepixel / mercado-pago example snippets


'providers' => [

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

    'LivePixel\MercadoPago\Providers\MercadoPagoServiceProvider',
],

'aliases' => [
	// Outros alias 

    'MP' => 'LivePixel\MercadoPago\Facades\MP',
]

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());
        }
    }
}