PHP code example of diego-mascarenhas / laravel-mercadopago-sdk
1. Go to this page and download the library: Download diego-mascarenhas/laravel-mercadopago-sdk 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/ */
diego-mascarenhas / laravel-mercadopago-sdk example snippets
'providers' => [
// Others Providers...
DiegoMascarenhas\LaravelMercadoPago\Providers\MercadoPagoServiceProvider::class,
/*
* Application Service Providers...
*/
],
'aliases' => [
// Others Aliases
'MP' => DiegoMascarenhas\LaravelMercadoPago\Facades\MP::class,
],
return [
'app_id' => env('MP_APP_ID', 'YOUR CLIENT ID'),
'app_secret' => env('MP_APP_SECRET', 'YOUR CLIENT SECRET'),
'app_ssl' => env('MP_APP_SSL', true),
'app_sandbox' => env('MP_APP_DEBUG', false)
];
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use MP;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class MercadoPagoController extends Controller
{
public function getCreatePreference()
{
$preferenceData = [
'items' => [
[
'id' => 101,
'category_id' => 'electronics',
'title' => 'iPhone 14 Pro Max',
'description' => 'iPhone 14 Pro Max 128GB - Black',
'picture_url' => 'https://example.com/images/products/iphone-14-pro-max-black.png',
'quantity' => 1,
'currency_id' => 'ARS',
'unit_price' => 150000
]
],
'payer' => [
'email' => '[email protected]'
],
'payment_methods' => [
'excluded_payment_types' => [
['id' => 'atm']
],
'installments' => 12
],
'back_urls' => [
'success' => 'https://yourdomain.com/success',
'failure' => 'https://yourdomain.com/failure',
'pending' => 'https://yourdomain.com/pending'
],
'auto_return' => 'approved',
'notification_url' => 'https://yourdomain.com/notifications'
];
$preference = MP::create_preference($preferenceData);
return dd($preference);
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use MP;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class MercadoPagoController extends Controller
{
public function getCreatePreapproval()
{
$preapproval_data = [
'payer_email' => '[email protected]',
'back_url' => 'https://example.com/preapproval',
'reason' => 'Premium Suscription',
'external_reference' => $subscription->id,
'auto_recurring' => [
'frequency' => 1,
'frequency_type' => 'months',
'transaction_amount' => 99,
'currency_id' => 'ARS',
'start_date' => Carbon::now()->addHour()->format('Y-m-d\TH:i:s.BP'),
'end_date' => Carbon::now()->addMonth()->format('Y-m-d\TH:i:s.BP'),
],
];
MP::create_preapproval_payment($preapproval_data);
return dd($preapproval);
}