GithubHelp home page GithubHelp logo

sdk-php's Introduction

MercadoPago SDK module for Payments integration

Usage:

  1. Copy lib/mercadopago.php to your project desired folder.
  2. Copy lib/cacert.pem to the same folder (for SSL access to MercadoPago APIs).
require_once "mercadopago.php";

$mp = new MP ("CLIENT_ID", "CLIENT_SECRET");

Get your Access Token:

$accessToken = $mp->get_access_token();

print_r ($accessToken);

Using MercadoPago Checkout

Get an existent Checkout preference:

$preferenceResult = $mp->get_preference("PREFERENCE_ID");

print_r ($preferenceResult);

Create a Checkout preference:

$preference = array (
	"items" => array (
		array (
			"title" => "Test",
			"quantity" => 1,
			"currency_id" => "USD",
			"unit_price" => 10.4
		)
	)
);

$preferenceResult = $mp->create_preference($preference);

print_r ($preferenceResult);

Update an existent Checkout preference:

$preference = array (
	"items" => array (
		array (
			"title" => "Test Modified",
			"quantity" => 1,
			"currency_id" => "USD",
			"unit_price" => 20.4
		)
	)
);

$preferenceResult = $mp->update_preference("PREFERENCE_ID", $preference);

print_r ($preferenceResult);

Using MercadoPago Payment

###Searching:

$filters = array (
        "id": null,
        "site_id": null,
        "external_reference": null
    };

$searchResult = $mp->search_payment ($filters);

print_r ($searchResult);

Receiving IPN notification:

require_once "mercadopago.php";

header("Content-type: text/plain");

$mp = new MP ("CLIENT_ID", "CLIENT_SECRET");
$paymentInfo = $mp->get_payment_info ($_GET["id"]);

header ("", true, $paymentInfo["status"]);

print_r ($paymentInfo);

Cancel (only for pending payments):

$result = $mp->cancel_payment($_GET["ID"]);

// Show result
print_r ($result);

Refund (only for accredited payments):

$result = $mp->refund_payment($_GET["ID"]);

// Show result
print_r ($result);

sdk-php's People

Contributors

hcasatti avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.