PHP code example of olvisdevalencia / mercado-pago

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

    

olvisdevalencia / mercado-pago example snippets


'providers' => [

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

    'olvisdevalencia\MercadoPago\Providers\MercadoPagoServiceProvider',
],

'aliases' => [
	// otros alias

    'MP' => 'olvisdevalencia\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 MP;
use MercadoPagoException;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MercadoPagoController extends Controller {


    /**
     *
     * Method to create a customer on mercadopago
     * @param  Request
     * @return object
     */
    public function createCustomer(Request $request) {

       	try {

            $data = $request;

            $customer_data = [
              'email'       => $data->email, #[email protected]
              'first_name'  => $data->first_name # Jhon Doe
            ];

       	    $customer = MP::post("/v1/customers", $customer_data);

            return $customer;

       	} catch(MercadoPagoException $e) {

       	    return $e->getMessage();

       	} catch (\Exception $e){

       	    return response()->json($e->getMessage());
       	}

    }
}