PHP code example of crizprz / laravelmercadopago
1. Go to this page and download the library: Download crizprz/laravelmercadopago 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/ */
crizprz / laravelmercadopago example snippets
crizprz\laravelmercadopago\Providers\LaravelMercadoPagoProvider::class,
'MercadoPago' => crizprz\laravelmercadopago\Facades\MercadoPago::class,
php artisan vendor:publish --provider="crizprz\laravelmercadopago\Providers\LaravelMercadoPagoProvider"
array:2 [▼
0 => array:5 [▼
"id" => 752892812
"nickname" => "TESTE2VYDAPX"
"email" => "[email protected] "
"password" => "qatest3393"
"type User" => "seller"
]
1 => array:5 [▼
"id" => 752890064
"nickname" => "TETE9884170"
"email" => "[email protected] "
"password" => "qatest6713"
"type User" => "payer"
]
]
use crizprz\laravelmercadopago\Facades\MercadoPago;
$preference = MercadoPago::CreatePreference([
'auto_return' => 'approved',
'binary_mode' => true,
'back_urls' => [
"success" => route('mpsuccess'),
"failure" => route('mpfailure'),
"pending" => route('mppending')
],
'notification_url' => route('webhook'),
'items' => [
'id' => '001',
'title' => 'prod 1',
'picture_url' => 'https://www.tusitio.com/images/products/prod1.jpg',
'description' => 'this is descriptions',
'category_id' => 'food',
'quantity' => 1,
'price' => 1000,
],
'payment_methods' => [
'excluded_payment_methods' => array(
array('id' => 'master'),
// array('id' => 'visa'),
),
'excluded_payment_types' => array(
array('id' => 'ticket')
),
'installments' => 12
],
'payer' => [
'name' => 'Cristian',
'last_name' => 'Lira Perez',
'email' => '[email protected] ',
'phone' => [
'area_code' => +52,
'number' => '7224738425'
],
'address' => [
'zip_code' => 23492,
'street_name' => 'Calle cerrada de juerez',
'street_number' => '104'
]
],
'shipments' => [
'cost' => 100,
],
'statement_descriptor' => 'Mi tienda online',
]);
return view('checkout',['preference' => $preference]);
{{ MercadoPago::ButtonPay($preference->init_point) }}
<a class="btn btn-info mt-5" href="{{ $preference->init_point }}">Pay Now</a>
public function success(Request $request)
{
// dd($request->all());
if ($request->status === 'approved') {
$response = Http::get("https://api.mercadopago.com/v1/payments/{$request->payment_id}", [
'access_token' => env('ACCESS_TOKEN_MP'),
])->json();
dd($response);
}
}
array:11 [▼
"collection_id" => "14694550173"
"collection_status" => "approved"
"payment_id" => "14694550173"
"status" => "approved"
"external_reference" => "null"
"payment_type" => "credit_card"
"merchant_order_id" => "2621979593"
"preference_id" => "752892812-d318bf82-4eea-4748-af60-cd4ade381491"
"site_id" => "MLM"
"processing_mode" => "aggregator"
"merchant_account_id" => "null"
]
if ($request->status === 'approved') {
$response = Http::get("https://api.mercadopago.com/v1/payments/{$request->payment_id}", [
'access_token' => env('ACCESS_TOKEN_MP'),
])->json();
dd($response);
}