public function toOptionArray() { $methods = array(); //adiciona um valor vazio caso nao queria excluir nada $methods[] = array("value" => "", "label" => ""); $client_id = Mage::getStoreConfig('payment/mercadopago/client_id'); $client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret'); //verifico se as credenciais não são vazias, caso sejam não é possível obte-los if ($client_id != "" && $client_secret != "") { $mp = new MP($client_id, $client_secret); $access_token = $mp->get_access_token(); Mage::helper('mercadopago')->log("Get payment methods by country... ", 'mercadopago.log'); Mage::helper('mercadopago')->log("API payment methods: " . "/v1/payment_methods?access_token=" . $access_token, 'mercadopago.log'); $response = MPRestClient::get("/v1/payment_methods?access_token=" . $access_token); Mage::helper('mercadopago')->log("API payment methods", 'mercadopago.log', $response); $response = $response['response']; foreach ($response as $m) { if ($m['id'] != 'account_money') { $methods[] = array('value' => $m['id'], 'label' => Mage::helper('adminhtml')->__($m['name'])); } } } return $methods; }
public function testLongLiveAccessToken() { $mp = new MP($this->credentials["access_token"]); $this->assertTrue($mp->get_access_token() == $this->credentials["access_token"]); }
<?php $mp = new MP("ACCESS_TOKEN"); $request = array("uri" => "/oauth/token", "data" => array("client_secret" => $mp->get_access_token(), "grant_type" => "authorization_code", "code" => "AUTHORIZATION_CODE", "redirect_uri" => "REDIRECT_URI"), "headers" => array("content-type" => "application/x-www-form-urlencoded"), "authenticate" => false); $mp->post($request);
<?php $mp = new MP("ACCESS_TOKEN"); $request = array("uri" => "/oauth/token", "data" => array("client_secret" => $mp->get_access_token(), "grant_type" => "refresh_token", "refresh_token" => "USER_RT"), "headers" => array("content-type" => "application/x-www-form-urlencoded"), "authenticate" => false); $mp->post($request);
/** * MercadoPago SDK * Receive IPN * @date 2015/03/17 * @author fvaccaro */ // Include Mercadopago library require_once "../../lib/mercadopago.php"; // Create an instance with your MercadoPago credentials (CLIENT_ID and CLIENT_SECRET): // Argentina: https://www.mercadopago.com/mla/herramientas/aplicaciones // Brasil: https://www.mercadopago.com/mlb/ferramentas/aplicacoes // Mexico: https://www.mercadopago.com/mlm/herramientas/aplicaciones // Venezuela: https://www.mercadopago.com/mlv/herramientas/aplicaciones $mp = new MP("CLIENT_ID", "CLIENT_SECRET"); $params = ["access_token" => $mp->get_access_token()]; // Get the payment reported by the IPN. Glossary of attributes response in https://developers.mercadopago.com if ($_GET["topic"] == 'payment') { $payment_info = $mp->get("/collections/notifications/" . $_GET["id"], $params, false); $merchant_order_info = $mp->get("/merchant_orders/" . $payment_info["response"]["collection"]["merchant_order_id"], $params, false); // Get the merchant_order reported by the IPN. Glossary of attributes response in https://developers.mercadopago.com } else { if ($_GET["topic"] == 'merchant_order') { $merchant_order_info = $mp->get("/merchant_orders/" . $_GET["id"], $params, false); } } //If the payment's transaction amount is equal (or bigger) than the merchant order's amount you can release your items if ($merchant_order_info["status"] == 200) { $transaction_amount_payments = 0; $transaction_amount_order = $merchant_order_info["response"]["total_amount"]; $payments = $merchant_order_info["response"]["payments"];
public function action_ipn() { $this->auto_render = FALSE; $id_order = $this->request->param('id'); //retrieve info for the item in DB $order = new Model_Order(); $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find(); if ($order->loaded()) { //its a fraud...lets let him know if ($order->is_fraud() === TRUE) { Kohana::$log->add(Log::ERROR, __('We had, issues with your transaction. Please try paying with another paymethod.')); $this->response->body('KO'); } // Include Mercadopago library require Kohana::find_file('vendor/mercadopago', 'mercadopago'); // Create an instance with your MercadoPago credentials (CLIENT_ID and CLIENT_SECRET): $mp = new MP(core::config('payment.mercadopago_client_id'), core::config('payment.mercadopago_client_secret')); $params = ["access_token" => $mp->get_access_token()]; // Check mandatory parameters if (Core::get('id') == NULL or Core::get('topic') == NULL or !ctype_digit(Core::get('id'))) { $this->response->body('KO'); } // Get the payment reported by the IPN. Glossary of attributes response in https://developers.mercadopago.com if (Core::get('topic') == 'payment') { try { $payment_info = $mp->get("/collections/notifications/" . Core::get('id'), $params, false); // Get the merchant_order reported by the IPN. Glossary of attributes response in https://developers.mercadopago.com } catch (Exception $e) { Kohana::$log->add(Log::ERROR, $e); $this->response->body('KO'); } try { $merchant_order_info = $mp->get("/merchant_orders/" . $payment_info["response"]["collection"]["merchant_order_id"], $params, false); } catch (Exception $e) { Kohana::$log->add(Log::ERROR, $e); $this->response->body('KO'); } } else { if (Core::get('topic') == 'merchant_order') { try { $merchant_order_info = $mp->get("/merchant_orders/" . Core::get('id'), $params, false); } catch (Exception $e) { Kohana::$log->add(Log::ERROR, 'Order not loaded'); $this->response->body('KO'); } } } //If the payment's transaction amount is equal (or bigger) than the merchant order's amount you can release your items if (isset($merchant_order_info["status"]) and $merchant_order_info["status"] == 200) { $transaction_amount_payments = 0; $transaction_amount_order = $merchant_order_info["response"]["total_amount"]; $payments = $merchant_order_info["response"]["payments"]; foreach ($payments as $payment) { if ($payment['status'] == 'approved') { $transaction_amount_payments += $payment['transaction_amount']; } } //correct payment if ($transaction_amount_payments >= $transaction_amount_order) { $order->confirm_payment('mercadopago', Core::get('id')); $this->response->body('OK'); } else { Kohana::$log->add(Log::ERROR, 'A payment has been made but is flagged as INVALID'); $this->response->body('KO'); } } } else { Kohana::$log->add(Log::ERROR, 'Order not loaded'); $this->response->body('KO'); } }
function add_balance_to_user_array($args) { $fullArgs = array(); if ($args['titulo']) { $fullArgs['titulo'] = $args['titulo']; unset($args['titulo']); } foreach ($args as $argumento) { $mp = new MP($argumento['identificador'], $argumento["Client_pass"]); $token = $mp->get_access_token(); $user = explode("-", $token); $user_ID = end($user); $balance = $mp->get("/users/{$user_ID}/mercadopago_account/balance"); $argumento['Saldo'] = $balance['response']['available_balance']; $argumento['Retenido'] = $balance['response']['unavailable_balance']; $fullArgs[] = $argumento; } return $fullArgs; }
public function testLongLiveAccessToken() { $mp = new MP("LONG_LIVE_ACCESS_TOKEN"); $this->assertTrue($mp->get_access_token() == "LONG_LIVE_ACCESS_TOKEN"); }
<?php require_once 'mercadopago.php'; $mp = new MP("CLIENT_ID", "CLIENT_SECRET"); $access_token = $mp->get_access_token(); print_r($access_token);