Skip to content

eavilesmejia/sdk-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published