leonardcodep/mercadopago-sdk-php

Cliente Mercado de Pago API para PHP

Downloads

1169

Stars

0

Version

2.4.8

Mercado Pago SDK for PHP

Latest Stable Version Total Downloads License

This library provides developers with a simple set of bindings to help you integrate Mercado Pago API to a website and start receiving payments.

πŸ’‘ Requirements

PHP 7.1, 8.0 y 8.1 or higher

πŸ’» Installation

First time using Mercado Pago? Create your Mercado Pago account, if you don’t have one already.

  1. Download Composer if not already installed

  2. On your project directory run on the command line composer require leonardcodep/mercadopago-sdk-php

  3. Copy the access_token in the credentials section of the page and replace YOUR_ACCESS_TOKEN with it.

That's it! Mercado Pago SDK has been successfully installed.

🌟 Getting Started

Simple usage looks like:

  <?php
    require_once 'vendor/autoload.php'; // You have to require the library from your Composer vendor folder

    use MercadoPago\SDK;
    use MercadoPago\Entity\Shared\Payment;
    use MercadoPago\Entity\Shared\Payer;
    try {
        SDK::setAccessToken("YOUR_ACCESS_TOKEN"); // Either Production or SandBox AccessToken
        $payment = new Payment();
        $payment->transaction_amount = 259;
        $payment->token = $request->token;
        $payment->description = "Compra de productos";
        $payment->installments = (int) $request->installments;
        $payment->payment_method_id = $request->payment_method_id;
        $payment->issuer_id = (int) $request->issuer_id;

        $payer = new Payer();
        $payerForm = $request->payer;
        $payer->email = $payerForm['email'];
        $payer->identification = array(
            "type" => $payerForm['identification']['type'],
            "number" => $payerForm['identification']['number']
        );
        $payment->payer = $payer;
        $payment->save();

        if($payment->id === null) {
            $error_message = 'Unknown error cause';
            if(isset($payment->error)) {
                $error_message = $payment->error->message;
            }
            throw new Exception($error_message);
        }

        $response = array(
            "request" => $request,
            "payment_id" => $payment->id,
            "status" => $payment->status,
            "status_detail" => $payment->status_detail,
        );
    } catch (Exception $e) {
        throw new Exception(trim(trim($e->getMessage()), '"'));
    }
  ?>

πŸ“š Documentation

Visit our Dev Site for further information regarding:

Check our official code reference to explore all available functionalities.

❀️ Support

If you require technical support, please contact our support team at developers.mercadopago.com

leonardcodep

Author

leonardcodep