<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once "lib/mercadopago.php"; $mp = new MP("3821444876288488", "1MsZwpHqFP2MDPh1d4IaXsIrUAbIXbjt"); $arquivo = fopen('result_ipn.php', 'a'); fwrite($arquivo, "\n POST <? echo('<pre>'); ?> " . $_SERVER['REQUEST_URI'] . "<? echo('</pre>'); ?><br><br>"); fclose($arquivo); switch ($_GET["topic"]) { case "payment": $payment_info = $mp->get_payment_info($_GET["id"]); if ($payment_info["status"] == 200) { $arquivo = fopen('result_ipn.php', 'a'); fwrite($arquivo, "\n<? echo('<pre>'); ?> " . json_encode($payment_info) . "<? echo('</pre>'); ?><br><hr><br>"); fclose($arquivo); } break; case "preapproval": $payment_info = $mp->get_preapproval_payment($_GET["id"]); if ($payment_info["status"] == 200) { $arquivo = fopen('result_ipn.php', 'a'); fwrite($arquivo, "\n<pre> " . json_encode($payment_info) . "</pre><br><hr><br>"); fclose($arquivo); } break; case "authorized_payment": $payment_info = $mp->get_authorized_payment($_GET["id"]); if ($payment_info["status"] == 200) { $arquivo = fopen('result_ipn.php', 'a'); fwrite($arquivo, "\n<pre> " . json_encode($payment_info) . "</pre><br><hr><br>");
public function retorno() { if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']; $client_id = $this->config->get('mercadopago2_client_id'); $client_secret = $this->config->get('mercadopago2_client_secret'); $sandbox = $this->config->get('mercadopago2_sandbox') == 1 ? true : null; //$checkdata = New Shop($client_id,$client_secret); $mp = new MP($client_id, $client_secret); $mp->sandbox_mode($sandbox); //$dados = $checkdata->GetStatus($id); $dados = $mp->get_payment_info($id); $dados = $dados['response']; $order_id = $dados['collection']['external_reference']; $order_status = $dados['collection']['status']; $this->load->model('checkout/order'); $order = $this->model_checkout_order->getOrder($order_id); if ($order['order_status_id'] == '0') { $this->model_checkout_order->confirm($order_id, $this->config->get('mercadopago_order_status_id')); } switch ($order_status) { case 'approved': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_completed')); break; case 'pending': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending')); break; case 'in_process': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_process')); break; case 'reject': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_rejected')); break; case 'refunded': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_refunded')); break; case 'cancelled': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_cancelled')); break; case 'in_metiation': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_in_mediation')); break; default: $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending')); break; } echo "ID: " . $id . " - Status: " . $order_status; } }
<?php include_once '../../../config/config.inc.php'; include_once 'mercadopago.php'; if (isset($_REQUEST['topic']) && isset($_REQUEST['id'])) { $id = $_REQUEST['id']; $client_id = Db::getInstance()->getRow("SELECT value FROM " . _DB_PREFIX_ . "configuration WHERE name = 'mercadopago_CLIENT_ID'"); $client_secret = Db::getInstance()->getRow("SELECT value FROM " . _DB_PREFIX_ . "configuration WHERE name = 'mercadopago_CLIENT_SECRET'"); $sandbox = Db::getInstance()->getRow("SELECT value FROM " . _DB_PREFIX_ . "configuration WHERE name = 'mercadopago_SANDBOX'"); $mp = new MP($client_id['value'], $client_secret['value']); $mp->sandbox_mode($sandbox['value'] == "active" ? true : false); $dados = $mp->get_payment_info($id); $dados = $dados['response']; $order_id = $dados['collection']['external_reference']; $order_status = $dados["collection"]["status"]; switch ($order_status) { case 'approved': $nomestatus = "mercadopago_STATUS_1"; break; case 'pending': $nomestatus = "mercadopago_STATUS_0"; break; case 'in_process': $nomestatus = "mercadopago_STATUS_0"; break; case 'reject': $nomestatus = "mercadopago_STATUS_2"; break; case 'refunded': $nomestatus = "mercadopago_STATUS_2"; break;
public function retorno() { if (isset($this->request->get['collection_id'])) { if ($this->request->get['collection_id'] == 'null') { $order_id = $this->request->get['external_reference']; $this->load->model('checkout/order'); $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_' . $this->request->get['status']), date('d/m/Y h:i')); return; } $ids = explode(',', $this->request->get['collection_id']); $client_id = $this->config->get('mp_standard_client_id'); $client_secret = $this->config->get('mp_standard_client_secret'); $sandbox = $this->config->get('mp_standard_sandbox') == 1 ? true : null; $mp = new MP($client_id, $client_secret); $mp->sandbox_mode($sandbox); foreach ($ids as $id) { $resposta = $mp->get_payment_info($id); $dados = $resposta['response']; $order_id = $dados['collection']['external_reference']; $order_status = $dados['collection']['status']; $this->load->model('checkout/order'); $order = $this->model_checkout_order->getOrder($order_id); if ($order['order_status_id'] == '0') { $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id')); } switch ($order_status) { case 'approved': $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_completed'), date('d/m/Y h:i') . ' - ' . $dados['collection']['payment_method_id'] . ' - ' . $dados['collection']['net_received_amount']); break; case 'pending': $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_pending'), date('d/m/Y h:i') . ' - ' . $dados['collection']['payment_method_id'] . ' - ' . $dados['collection']['net_received_amount']); break; case 'in_process': $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_process'), date('d/m/Y h:i') . ' - ' . $dados['collection']['payment_method_id'] . ' - ' . $dados['collection']['net_received_amount']); break; case 'reject': $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_rejected'), date('d/m/Y h:i') . ' - ' . $dados['collection']['payment_method_id'] . ' - ' . $dados['collection']['net_received_amount']); break; case 'refunded': $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_refunded'), date('d/m/Y h:i') . ' - ' . $dados['collection']['payment_method_id'] . ' - ' . $dados['collection']['net_received_amount']); break; case 'cancelled': $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_cancelled'), date('d/m/Y h:i') . ' - ' . $dados['collection']['payment_method_id'] . ' - ' . $dados['collection']['net_received_amount']); break; case 'in_metiation': $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_in_mediation'), date('d/m/Y h:i') . ' - ' . $dados['collection']['payment_method_id'] . ' - ' . $dados['collection']['net_received_amount']); break; default: $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('mp_standard_order_status_id_pending'), date('d/m/Y h:i') . ' - ' . $dados['collection']['payment_method_id'] . ' - ' . $dados['collection']['net_received_amount']); break; } } } else { error_log('id não setado na compra!!!'); } }