Ejemplo n.º 1
0
 private function getMethods($token)
 {
     try {
         $mp = new MP($token);
         $methods = $mp->get("/v1/payment_methods");
         return $methods;
     } catch (Exception $e) {
         $this->load->language('payment/mp_ticket');
         $error = array('status' => 400, 'message' => $this->language->get('error_access_token'));
         return $error;
     }
 }
Ejemplo n.º 2
0
 public function setSponsor()
 {
     Mage::helper('mercadopago')->log("Sponsor_id: " . Mage::getStoreConfig('payment/mercadopago/sponsor_id'), 'mercadopago.log');
     $sponsor_id = "";
     Mage::helper('mercadopago')->log("Valid user test", 'mercadopago.log');
     $client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
     Mage::helper('mercadopago')->log("Get client id: " . $client_id, 'mercadopago.log');
     $client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
     Mage::helper('mercadopago')->log("Get client secret: " . $client_secret, 'mercadopago.log');
     $mp = new MP($client_id, $client_secret);
     $user = $mp->get("/users/me");
     Mage::helper('mercadopago')->log("API Users response", 'mercadopago.log', $user);
     //caso api retorne 403 (error no get) verifica se a mensagem e do usuario com test credentials
     if ($user['status'] == 200 && !in_array("test_user", $user['response']['tags'])) {
         $sponsor_id = 1;
         $country = Mage::getStoreConfig('payment/mercadopago/country');
         switch ($user['response']['site_id']) {
             case 'MLA':
                 $sponsor_id = 186172525;
                 break;
             case 'MLB':
                 $sponsor_id = 186175129;
                 break;
             case 'MLM':
                 $sponsor_id = 186175064;
                 break;
             default:
                 $sponsor_id = "";
                 break;
         }
         Mage::helper('mercadopago')->log("Sponsor id setted", 'mercadopago.log', $sponsor_id);
     }
     $core = new Mage_Core_Model_Resource_Setup('core_setup');
     $core->setConfigData('payment/mercadopago/sponsor_id', $sponsor_id);
     Mage::helper('mercadopago')->log("Sponsor saved", 'mercadopago.log', $sponsor_id);
 }
Ejemplo n.º 3
0
<?php

require_once 'mercadopago.php';
$mp = new MP("ACCESS_TOKEN");
$payment = $mp->get("/v1/payments/[ID]");
print_r($payment);
Ejemplo n.º 4
0
<?php

require_once 'mercadopago.php';
$mp = new MP("ACCESS_TOKEN");
$customer = array("email" => "your.payer@email");
$saved_customer = $mp->get("/v1/customers/search", $customer);
$customer_id = $saved_customer["response"]["id"];
$card = $mp->post("/v1/customers/" . $customer_id . "/cards", array("token" => "ff8080814c11e237014c1ff593b57b4d"));
print_r($card);
Ejemplo n.º 5
0
 * 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"];
    foreach ($payments as $payment) {
        if ($payment['status'] == 'approved') {
            $transaction_amount_payments += $payment['transaction_amount'];
Ejemplo n.º 6
0
 private function getCards()
 {
     $id = $this->getCustomerId();
     $retorno = null;
     $access_token = $this->config->get('mp_transparente_access_token');
     $mp = new MP($access_token);
     $cards = $mp->get("/v1/customers/" . $id . "/cards");
     if (array_key_exists("response", $cards) && sizeof($cards["response"]) > 0) {
         $this->session->data['cards'] = $cards["response"];
         $retorno = $cards["response"];
     }
     return $retorno;
 }
Ejemplo n.º 7
0
 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');
     }
 }
Ejemplo n.º 8
0
<?php

require_once 'mercadopago.php';
$mp = new MP("CLIENT_ID", "CLIENT_SECRET");
$balance = $mp->get("/users/USER_ID/mercadopago_account/balance");
print_r($balance);
<?php

require_once 'mercadopago.php';
$mp = new MP("ACCESS_TOKEN");
$payment_methods = $mp->get("/v1/payment_methods");
print_r($payment_methods);
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
 protected function mercadopage_check($topic, $id)
 {
     require_once __DIR__ . '/../class/mercadopago.php';
     $config = Bootstrap::$main->getConfig();
     try {
         $mp = new MP($config['mercadopago.client_id'], $config['mercadopago.client_secret']);
         $merchant_order_info = null;
         switch ($topic) {
             case 'payment':
                 $payment_info = $mp->get("/collections/notifications/" . $id);
                 $merchant_order_info = $mp->get("/merchant_orders/" . $payment_info["response"]["collection"]["merchant_order_id"]);
                 break;
             case 'merchant_order':
                 $merchant_order_info = $mp->get("/merchant_orders/" . $id);
                 break;
             default:
                 $merchant_order_info = null;
         }
         return $merchant_order_info;
     } catch (Exception $e) {
         mydie($e);
     }
 }
<?php

ini_set('display_errors', 1);
ini_set('display_startup_erros', 1);
error_reporting(E_ALL);
require_once "lib/mercadopago.php";
$mp = new MP("Set your access token long live");
$email_buyer = "*****@*****.**";
$payment_preference = array("token" => $_REQUEST['token'], "installments" => 1, "transaction_amount" => round((double) $_REQUEST['amount'], 2), "external_reference" => "order code 1234xxxx", "binary_mode" => true, "description" => "Teste payments v1", "payment_method_id" => $_REQUEST['paymentMethodId'], "statement_descriptor" => "*MEUTESTE", "binary_mode" => true, "payer" => array("email" => $email_buyer), "additional_info" => array("items" => array(array("id" => "1234", "title" => "Aqui coloca os itens do carrinho", "description" => "Produto Teste novo", "picture_url" => "https://google.com.br/images?image.jpg", "category_id" => "others", "quantity" => 1, "unit_price" => round((double) $_REQUEST['amount'], 2))), "payer" => array("first_name" => "João", "last_name" => "Silva", "registration_date" => "2014-06-28T16:53:03.176-04:00", "phone" => array("area_code" => "5511", "number" => "3222-1000"), "address" => array("zip_code" => "05303-090", "street_name" => "Av. Queiroz Filho", "street_number" => "213")), "shipments" => array("receiver_address" => array("zip_code" => "05303-090", "street_name" => "Av. Queiroz Filho", "street_number" => "213", "floor" => "0", "apartment" => "0"))));
$response_payment = $mp->post("/v1/payments/", $payment_preference);
echo "<h3> ==== 1st Payment ===== </h3>";
echo "Payment Status:" . $response_payment["response"]["status"] . " - " . $response_payment["response"]["status_detail"];
// Check if user exist
echo "<h3> ==== Check if user exist ===== </h3>";
$check_user_exists = $mp->get("/v1/customers/search?email={$email_buyer}");
$id_user = $check_user_exists["response"]["results"][0]["id"];
if (!isset($id_user)) {
    echo "<h3> ==== Create user ===== </h3>";
    $user_preference = array("email" => $email_buyer, "first_name" => "João", "last_name" => "Silva");
    $create_users = $mp->post("/v1/customers/", $user_preference);
    print_r($create_users);
    $id_user = $create_users["response"]["id"];
}
echo "<h3> ==== Create card ===== (Save in your datamodel) </h3>";
$card_preference = array("token" => $_REQUEST['token']);
$create_card = $mp->post("/v1/customers/{$id_user}/cards", $card_preference);
echo "<pre>";
print_r($create_card);
echo "</pre>";
$card_id = $create_card["response"]["id"];
$bandeira = $create_card["response"]["payment_method"]["id"];
Ejemplo n.º 13
0
 function process_response()
 {
     $SUFIJO = __FUNCTION__;
     $id = $_REQUEST['id'];
     $topic = $_REQUEST['topic'];
     if (isset($id) && isset($topic)) {
         ctala_log_me("TOPIC : " . $topic, __FUNCTION__);
         ctala_log_me($_REQUEST, __FUNCTION__);
         $mp = new \MP($this->get_option('clientid'), $this->get_option('secretkey'));
         /*
          * Creamos el merchant info dependiendo del request.
          */
         if ($topic == "payment") {
             $payment_info = $mp->get("/collections/notifications/" . $id);
             $merchant_order_info = $mp->get("/merchant_orders/" . $payment_info["response"]["collection"]["merchant_order_id"]);
         } elseif ($topic == 'merchant_order') {
             $merchant_order_info = $mp->get("/merchant_orders/" . $_GET["id"]);
         }
         /*
          * Logeamos los datos.
          */
         ctala_log_me($merchant_order_info, __FUNCTION__);
         if ($merchant_order_info["status"] == 200) {
             //Usamos la variabel [external_reference] para el order_id
             $order_id = $merchant_order_info["response"]["external_reference"];
             $TrxId = $merchant_order_info["response"]["id"];
             $PreferenceId = $merchant_order_info["response"]["preference_id"];
             add_post_meta($order_id, self::MP_META_KEY_ID, $TrxId, true);
             add_post_meta($order_id, self::MP_META_KEY_PREFERENCE_ID, $PreferenceId, true);
             //Creamos la OC para agregar las notas y completar en caso de que sea necesario.
             global $woocommerce;
             $order = new \WC_Order($order_id);
             $paid_amount = 0;
             foreach ($merchant_order_info["response"]["payments"] as $payment) {
                 if ($payment['status'] == 'approved') {
                     $paid_amount += $payment['transaction_amount'];
                 }
             }
             if ($paid_amount >= $merchant_order_info["response"]["total_amount"]) {
                 if (count($merchant_order_info["response"]["shipments"]) > 0) {
                     // The merchant_order has shipments
                     if ($merchant_order_info["response"]["shipments"][0]["status"] == "ready_to_ship") {
                         $mensaje = "Pago total completado. Puedes entregar el pedido  : {$TrxId}";
                         $order->add_order_note($mensaje);
                         $order->add_order_note("PREF ID : {$PreferenceId}");
                         ctala_log_me($mensaje);
                         $order->update_status('processing', "Pago recibido, se procesa la orden : {$TrxId}");
                     }
                 } else {
                     // The merchant_order don't has any shipments
                     $mensaje = "PAGO COMPLETADO {$TrxId}";
                     ctala_log_me($mensaje);
                     $order->update_status('processing', "Pago recibido, se procesa la orden : {$TrxId}");
                     $order->add_order_note($mensaje);
                     $order->add_order_note("PREF ID : {$PreferenceId}");
                 }
             } else {
                 $mensaje = "Aun no pagado.";
                 $order->add_order_note($mensaje);
                 ctala_log_me($mensaje);
                 //                    $order->update_status('pending', "pago aun no recibido");
             }
         }
     }
 }
Ejemplo n.º 14
0
<?php

require_once 'mercadopago.php';
$mp = new MP("ACCESS_TOKEN");
$cards = $mp->get("/v1/customers/[CUSTOMER_ID]/cards");
print_r($cards["response"]);
Ejemplo n.º 15
0
<?php

require_once 'mercadopago.php';
$mp = new MP("ACCESS_TOKEN");
$filters = array("email" => "your.payer@email");
$customer = $mp->get("/v1/customers/search", $filters);
?>
<li>
	<label>Payment Method:</label>
	<select id="cardId" name="cardId" data-checkout='cardId'>
	<?php 
foreach ($customer["response"]["cards"] as $card) {
    ?>
		<option value="<?php 
    echo $card["id"];
    ?>
" 
			first_six_digits="<?php 
    echo $card["first_six_digits"];
    ?>
" 
			security_code_length="<?php 
    echo $card["security_code"]["length"];
    ?>
">
				<?php 
    echo $card["payment_method"]["name"];
    ?>
 ended in <?php 
    echo $card["last_four_digits"];
    ?>
Ejemplo n.º 16
0
<?php

require_once "mercadopago.php";
$mp = new MP("ACCESS_TOKEN");
$json_event = file_get_contents('php://input', true);
$event = json_decode($json_event);
if ($event->type == 'payment') {
    $payment_info = $mp->get('/v1/payments/' . $event->data->id);
    if ($payment_info["status"] == 200) {
        print_r($payment_info["response"]);
    }
}
Ejemplo n.º 17
0
 public function validCoupon($id)
 {
     $this->client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
     $this->client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
     $mp = new MP($this->client_id, $this->client_secret);
     $params = array("transaction_amount" => $this->getAmount(), "payer_email" => $this->getEmailCustomer(), "coupon_code" => $id);
     $details_discount = $mp->get("/discount_campaigns", $params);
     //add value on return api discount
     $details_discount['response']['transaction_amount'] = $params['transaction_amount'];
     $details_discount['response']['params'] = $params;
     return $details_discount;
 }