承接 diego-mascarenhas/laravel-mercadopago-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

diego-mascarenhas/laravel-mercadopago-sdk

最新稳定版本:0.6.3

Composer 安装命令:

composer require diego-mascarenhas/laravel-mercadopago-sdk

包简介

Mercado Pago SDK v0.6.3 for Laravel

README 文档

README

Installation

composer require diego-mascarenhas/laravel-mercadopago-sdk

Within config/app.php, add the following Provider and Alias

Provider

'providers' => [
  // Others Providers...
  DiegoMascarenhas\LaravelMercadoPago\Providers\MercadoPagoServiceProvider::class,
  /*
   * Application Service Providers...
   */
],

Alias

'aliases' => [
  // Others Aliases
  'MP' => DiegoMascarenhas\LaravelMercadoPago\Facades\MP::class,
],

Configuration

Before configuring the APP ID and APP SECRET, run the following command:

php artisan vendor:publish

After executing the command, go to the .env file and add the MP_APP_ID and MP_APP_SECRET fields with the corresponding values of the CLIENT_ID and CLIENT_SECRET from your MercadoPago application.

To find out your CLIENT_ID and CLIENT_SECRET information, you can go here:

If you do not want to use the .env file, go to config/mercadopago.php and add your corresponding application details.

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)
];

Usage

In this example, we will create a payment preference using the MP Facade.

<?php

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' => 'customer@example.com'
        ],
        '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);

  }

In this example, we will create a subscription (automatic debit) using the MP Facade.

<?php

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' => 'customer@example.com',
      '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);
  }

In the example, the use of the Carbon library can be seen to specify the start and end dates of the subscription, with a monthly frequency.

To the current date, an hour is added via Carbon, as otherwise MercadoPago might consider the date as past.

Troubleshooting

SSL Certificate Problem: Unable to Get Local Issuer Certificate

If you encounter an error stating SSL certificate problem: unable to get local issuer certificate, this typically occurs when the root certificates on your system are out of date or missing.

To resolve this issue, download the Latest CA Certificates Bundle from CA Extract.

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-18