function gmp_link($params) { $clientId = $params['client_id']; $clientSecret = $params['client_secret']; $testmode = $params['testmode']; $invoiceid = $params['invoiceid']; $description = $params["description"]; $amount = $params['amount']; # Format: ##.## $currency = $params['currency']; # Currency Code $mp = new MP($clientId, $clientSecret); $preference_data = array("external_reference" => $invoiceid, "items" => array(array("title" => $description, "quantity" => 1, "currency_id" => $currency, "unit_price" => (double) $amount))); $preference = $mp->create_preference($preference_data); $initPoint = $testmode ? $preference['response']['sandbox_init_point'] : $preference['response']['init_point']; $code = '<a href="' . $initPoint . '">Pagar</a>'; return $code; }
public function transition() { $this->load->model('checkout/order'); $this->load->model('account/customer'); $order_id = $this->session->data['order_id']; $token = $this->request->post['token']; $bran = $this->request->post['bran']; $installments = (int) $this->request->post['installments']; $total = $this->request->post['total']; $issuer = $this->request->post['issuer']; $cardNumber = $this->request->post['cardNumber']; $cardExpirationMonth = $this->request->post['cardExpirationMonth']; $cardExpirationYear = $this->request->post['cardExpirationYear']; $cardholderName = $this->request->post['cardholderName']; $docType = $this->request->post['docType']; $docNumber = $this->request->post['docNumber']; $order_info = $this->model_checkout_order->getOrder($order_id); $customer = $this->model_account_customer->getCustomer($order_info['customer_id']); $products = array(); foreach ($this->cart->getProducts() as $product) { $products[] = array('id' => $product['model'], 'title' => $product['name'], 'description' => $product['name'], 'picture_url' => $product['image'], 'quantity' => $product['quantity'], 'unit_price' => $product['price']); } $cellphone = preg_replace('/[\\D]/', '', $order_info['cellphone']); $area_code = substr($cellphone, 0, 2); $number = substr($cellphone, 2); $param = array('transaction_amount' => (double) number_format($total, 2, '.', ''), 'token' => $token, 'description' => 'Compra realizada na ' . $this->config->get('config_name'), 'installments' => $installments, 'payment_method_id' => $bran, 'payer' => array('email' => $order_info['email']), 'external_reference' => $order_id, 'statement_descriptor' => $this->config->get('config_name'), 'notification_url' => $this->url->link('payment/mercadopago_card/callback', '', 'SSL'), 'additional_info' => array('items' => $products, 'payer' => array('first_name' => $order_info['firstname'], 'last_name' => $order_info['lastname'], 'phone' => array('area_code' => $area_code, 'number' => $number), 'address' => array('zip_code' => preg_replace('/[\\D]/', '', $order_info['payment_postcode']), 'street_name' => $order_info['payment_address_1'], 'street_number' => $order_info['payment_number_home']), 'registration_date' => $customer['date_added']), 'shipments' => array('receiver_address' => array('zip_code' => $order_info['shipping_postcode'], 'street_name' => $order_info['shipping_address_1'], 'street_number' => $order_info['shipping_number_home'], 'floor' => $order_info['shipping_address_2'])))); require_once DIR_SYSTEM . '/library/mercadopago/mercadopago.php'; $mp = new MP($this->config->get('mercadopago_card_access_token')); $payment = $mp->post('/v1/payments', $param); $this->confirm($payment); $this->load->model('payment/mercadopago_card'); $this->model_payment_mercadopago_card->addCardMercadoPago($order_id, $this->request->post['creditCardHolderName'], $this->request->post['cvv'], $this->request->post['expirationMonth'] . '/' . $this->request->post['expirationYear'], $this->request->post['cardNumber'], $this->request->post['installmentQuantity'], $this->request->post['brand'], $payment['response']['code']); $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode(array())); }
public function transition() { $this->load->model('checkout/order'); $this->load->model('account/customer'); $this->load->model('extension/simulator_payments'); $simulation = $this->model_extension_simulator_payments->getSimulation('mercadopago_billet'); $order_id = $this->session->data['order_id']; $order_info = $this->model_checkout_order->getOrder($order_id); $customer = $this->model_account_customer->getCustomer($order_info['customer_id']); $products = array(); foreach ($this->cart->getProducts() as $product) { $products[] = array('id' => $product['model'], 'title' => $product['name'], 'description' => $product['name'], 'picture_url' => $product['image'], 'quantity' => $product['quantity'], 'unit_price' => $product['price']); } $cellphone = preg_replace('/[\\D]/', '', $order_info['cellphone']); $area_code = substr($cellphone, 0, 2); $number = substr($cellphone, 2); $total = $order_info['total']; if ($simulation['status'] && (int) $simulation['interest_total'] > 0) { $total *= 1 + $simulation['interest_total'] / 100; } $param = array('transaction_amount' => (double) number_format($order_info['total'], 2, '.', ''), 'description' => 'Compra realizada na ' . $this->config->get('config_name'), 'payment_method_id' => 'bolbradesco', 'payer' => array('email' => $order_info['email']), 'external_reference' => $order_id, 'statement_descriptor' => $this->config->get('config_name'), 'notification_url' => $this->url->link('payment/mercadopago_card/callback', '', 'SSL'), 'additional_info' => array('items' => $products, 'payer' => array('first_name' => $order_info['firstname'], 'last_name' => $order_info['lastname'], 'phone' => array('area_code' => $area_code, 'number' => $number), 'address' => array('zip_code' => preg_replace('/[\\D]/', '', $order_info['payment_postcode']), 'street_name' => $order_info['payment_address_1'], 'street_number' => $order_info['payment_number_home']), 'registration_date' => $customer['date_added']), 'shipments' => array('receiver_address' => array('zip_code' => $order_info['shipping_postcode'], 'street_name' => $order_info['shipping_address_1'], 'street_number' => $order_info['shipping_number_home'], 'floor' => $order_info['shipping_address_2'])))); require_once DIR_SYSTEM . '/library/mercadopago/mercadopago.php'; $mp = new MP($this->config->get('mercadopago_card_access_token')); $payment = $mp->post('/v1/payments', $param); $this->load->model('checkout/order'); $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('config_status_awaiting_payment')); $this->session->data['paymentLink'] = $payment['response']['transaction_details']['external_resource_url']; $this->load->model('payment/mercadopago_billet'); $this->model_payment_mercadopago_billet->addBilletMercadoPago($this->session->data['order_id'], $this->session->data['paymentLink']); $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode(array())); }
public function postPago() { $core = Mage::getModel('mercadopago/core'); //seta sdk php mercadopago $client_id = Mage::getStoreConfig('payment/mercadopago/client_id'); $client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret'); $mp = new MP($client_id, $client_secret); //monta a prefernecia $pref = $this->makePreference(); Mage::helper('mercadopago')->log("make array", 'mercadopago-standard.log', $pref); //faz o posto do pagamento $response = $mp->create_preference($pref); Mage::helper('mercadopago')->log("create preference result", 'mercadopago-standard.log', $response); $array_assign = array(); if ($response['status'] == 200 || $response['status'] == 201) { $payment = $response['response']; $init_point = $payment['init_point']; $array_assign = array("init_point" => $init_point, "type_checkout" => $this->getConfigData('type_checkout'), "iframe_width" => $this->getConfigData('iframe_width'), "iframe_height" => $this->getConfigData('iframe_height'), "banner_checkout" => $this->getConfigData('banner_checkout'), "status" => 201); Mage::helper('mercadopago')->log("Array preference ok", 'mercadopago-standard.log'); } else { $array_assign = array("message" => Mage::helper('mercadopago')->__('An error has occurred. Please refresh the page.'), "json" => json_encode($response), "status" => 400); Mage::helper('mercadopago')->log("Array preference error", 'mercadopago-standard.log'); } return $array_assign; }
public function register(Application $app) { $app['mp'] = $app->share(function () use($app) { $mp = new MP($app['id_client'], $app['id_client_secret']); $mp->sandbox_mode(TRUE); return $mp; }); }
function pay($item) { require_once "mercadopago.php"; $item_decoded = json_decode($item); $mp = new MP("2825512066514146", "2KIKPJLtXNGBlRMLK2h3IY8WI6g8dfrB"); $preference_data = array("items" => array(array("title" => $item_decoded->titulo, "currency_id" => "ARS", "category_id" => $item_decoded->categoria, "quantity" => intval($item_decoded->cantidad), "unit_price" => floatval($item_decoded->precio))), "payer" => array("email" => $item_decoded->mail)); $preference = $mp->create_preference($preference_data); echo json_encode($preference); }
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; } }
/** * generates HTML for apy buton * @param Model_Order $order * @return string */ public static function button(Model_Order $order) { if (Core::config('payment.mercadopago_client_id') != '' and Core::config('payment.mercadopago_client_secret') != '' and Theme::get('premium') == 1) { // 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')); $preference_data = array("items" => array(array("id" => $order->id_order, "title" => $order->product->title, "currency_id" => $order->currency, "picture_url" => $order->product->get_first_image(), "description" => Text::limit_chars(Text::removebbcode($order->product->description), 30, NULL, TRUE), "category_id" => $order->product->category->name, "quantity" => 1, "unit_price" => self::money_format($order->amount))), "payer" => array("name" => Auth::instance()->get_user()->name, "email" => Auth::instance()->get_user()->email), "back_urls" => array("success" => Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')), "failure" => Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))), "auto_return" => "approved", "notification_url" => Route::url('default', array('controller' => 'mercadopago', 'action' => 'ipn', 'id' => $order->id_order)), "expires" => false); $preference = $mp->create_preference($preference_data); $link = $preference["response"]["init_point"]; return View::factory('pages/mercadopago/button', array('link' => $link)); } return ''; }
function pago($atts){ require_once(__DIR__."/mvc/Factory.php"); require_once(__DIR__.'/mercadopago/lib/mercadopago.php'); $atts['cuantos']=($atts['cuantos']==null)?1:$atts['cuantos']; $factory=new MP_Factory(); $mydb=$factory->myDB(); $products=$mydb->print_all_items_from_tables("Productos",'*','title',$atts['title']); $proveedor=$mydb->print_all_items_from_tables("MP_Admin",'*','username',$products['provedor']); $encrypt=preg_split('/-/',$_COOKIE['MP_user']); $user=$mydb->print_all_items_from_tables('MP_user','MP_nombre,MP_email,MP_password','id',$encrypt[0]); if($user[1]['MP_password']==$encrypt[1]){ $MP_user=$user[1]; }else{ $user=''; } $mp = new MP($proveedor['identificador'], $proveedor['Client_pass']); $proveedor=$proveedor[1]; $products=$products[1]; $mp = new MP($proveedor['identificador'], $proveedor['Client_pass']); $price=round($products['unit_price'], 2); $preference_data = array( "items" => array( array( "title" => $products['title'], "quantity" => intval($atts['cuantos']), "currency_id" => "MXN", "unit_price" => $price, ) ), "payer"=>array( "name"=>$MP_user['MP_nombre'], "email"=>$MP_user['MP_email'] ) ); $preference = $mp->create_preference ($preference_data); header("location:".$preference[response][init_point]); exit(); }
function MP_link_button($atts) { require_once dirname(__DIR__) . '/mercadopago/lib/mercadopago.php'; $factory = new MP_Factory(); $mydb = $factory->myDB(); $proveedor = $mydb->print_all_items_from_tables("MP_Admin", '*', 'username', $atts['proveedor']); $encrypt = preg_split('/-/', $_COOKIE['MP_user']); $user = $mydb->print_all_items_from_tables('MP_user', 'MP_nombre,MP_email,MP_password', 'id', $encrypt[0]); if ($user[1]['MP_password'] == $encrypt[1]) { $MP_user = $user[1]; } else { $user = ''; } $proveedor = $proveedor[1]; $mp = new MP($proveedor['identificador'], $proveedor['Client_pass']); $price = round($atts['precio'], 2); $preference_data = array("items" => array(array("title" => $atts['title'], "quantity" => 1, "currency_id" => $atts['currency'], "unit_price" => $price)), "payer" => array("name" => $MP_user['MP_nombre'], "email" => $MP_user['MP_email'])); $preference = $mp->create_preference($preference_data); return "<a href='" . $preference[response][init_point] . "' class='MP_button' >{$atts['title']}</a>"; }
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; }
function probandoMP() { $sessionid = "1234567890"; $payer = array("name" => "Cristian ", "surname" => "Tala S.", "email" => "*****@*****.**", "date_created" => "", "phone" => array("area_code" => "-", "number" => "+56991629602"), "address" => array("zip_code" => "00000", "street_name" => "Presidente Kennedy", "street_number" => "5933"), "identification" => array("number" => "null", "type" => "null")); $shipments = array("receiver_address" => array("floor" => "-", "zip_code" => "000000", "street_name" => "DESTINO", "apartment" => "-", "street_number" => "-")); $items = array(array("id" => $sessionid, "title" => "Producto", "description" => "x", "quantity" => 1, "unit_price" => 10, "currency_id" => "CLP", "picture_url" => "", "category_id" => "")); //set back url $back_urls = array("pending" => "URLPENDING", "success" => "URLSUCCESS"); //mount array pref $pref = array(); $pref['external_reference'] = $sessionid; $pref['payer'] = $payer; $pref['shipments'] = $shipments; $pref['items'] = $items; $pref['back_urls'] = $back_urls; $pref['payment_methods'] = $payment_methods; $mp = new MP(CTALA_MP_CLIENTID, CTALA_MP_CLIENTSCRETET); $preferenceResult = $mp->create_preference($pref); $result = ""; $result .= "<pre>"; if ($preferenceResult['status'] == 201) { if (true) { $link = $preferenceResult['response']['sandbox_init_point']; } else { $link = $preferenceResult['response']['init_point']; } } else { $result .= "Error: " . $preferenceResult['status']; } $result .= print_r($preferenceResult, true); $filters = array("id" => null, "site_id" => null, "external_reference" => null); $searchResult = $mp->search_payment($filters); $result .= print_r($searchResult, true); $result .= "</pre>"; return $result; }
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); }
<body> <?php /** * MercadoPago SDK * Search approved payments in last month * @date 2012/03/29 * @author hcasatti */ // 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"); // Sets the filters you want $filters = array("range" => "date_created", "begin_date" => "NOW-1MONTH", "end_date" => "NOW", "status" => "approved", "operation_type" => "regular_payment"); // Search payment data according to filters $searchResult = $mp->search_payment($filters); // Show payment information ?> <table border='1'> <tr><th>id</th><th>site_id</th><th>date_created</th><th>operation_type</th><th>external_reference</th></tr> <?php foreach ($searchResult["response"]["results"] as $payment) { ?> <tr> <td><?php echo $payment["collection"]["id"]; ?>
<?php require_once 'mercadopago.php'; $mp = new MP("CLIENT_ID", "CLIENT_SECRET"); $filters = array("status" => "approved"); $search_result = $mp->search_payment($filters, 0, 10); print_r($search_result);
public function testLongLiveAccessToken() { $mp = new MP($this->credentials["access_token"]); $this->assertTrue($mp->get_access_token() == $this->credentials["access_token"]); }
<?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;
<?php ini_set('display_errors', 1); ini_set('display_startup_erros', 1); error_reporting(E_ALL); require_once "lib/mercadopago.php"; // 5031 4332 1540 6351 $mp = new MP("3821444876288488", "1MsZwpHqFP2MDPh1d4IaXsIrUAbIXbjt"); print_r($_REQUEST); $valor = rand(10, 350); $preference = array("amount" => (double) $_REQUEST['amount'], "installments" => (int) $_REQUEST['installmentsOption'], "payment_method_id" => $_REQUEST['paymentMethod'], "currency_id" => "BRL", "card_token_id" => $_REQUEST['card_token_id'], "external_reference" => "my_order_1234", "items" => array(array("id" => "2133", "title" => "Titulo do produto", "description" => "Descricao ", "picture_url" => "http=>//2.bp.blogspot.com/-Zu-IpE01s5Y/TtEAy89fUzI/AAAAAAAAAXE/0_ZrT5SUbUQ/s1600/unicef.jpg", "category_id" => "others", "quantity" => 1, "unit_price" => (double) $_REQUEST['amount'])), "customer" => array("email" => "*****@*****.**", "first_name" => "name", "last_name" => "lastName", "phone" => array("area_code" => "011", "number" => "38882377"), "identification" => array("type" => "CPF", "number" => "19119119100"), "address" => array("zip_code" => "06541005", "street_name" => "Street name", "street_number" => 1), "registration_date" => "2014-06-28T16:53:03.176-04:00"), "shipments" => array("receiver_address" => array("zip_code" => "06541005", "street_name" => "Street name", "street_number" => 1, "floor" => "5", "apartment" => "c"))); $preferenceResult = $mp->invisible($preference); ?>
<?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>");
function function_mercado_pago($seperator, $sessionid) { global $wpdb, $wpsc_cart; //This grabs the purchase log id from the database //that refers to the $sessionid $purchase_log = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1", ARRAY_A); //This grabs the users info using the $purchase_log // from the previous SQL query $usersql = "SELECT `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.value,\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.`name`,\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.`unique_name` FROM\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "` LEFT JOIN\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "` ON\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.id =\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`form_id` WHERE\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`log_id`=" . $purchase_log['id']; $userinfo = $wpdb->get_results($usersql, ARRAY_A); // configs $data = array(); $data['client_id'] = get_option('mercadopago_client_id'); $data['client_secret'] = get_option('mercadopago_client_secret'); $data['sucess'] = get_option('mercadopago_url_sucess'); $data['pending'] = get_option('mercadopago_url_pending'); $data['currency'] = get_option('mercadopago_currency'); $sandbox = get_option('mercadopago_sandbox') == "active" ? true : false; $type_checkout = get_option('mercadopago_typecheckout'); $category = get_option('mercadopago_category'); // order info $data['total'] = $wpsc_cart->total_price; //client $arr_info = array(); foreach ((array) $userinfo as $key => $value) { $arr_info[$value['unique_name']] = $value['value']; } // products foreach ($wpsc_cart->cart_items as $i => $Item) { $data['PROD_NAME' . $i] = $Item->product_name; $data['PROD_TOTAL' . $i] = number_format($Item->unit_price, 2); $data['PROD_NUMBER' . $i] = $i; $data['PROD_QTY' . $i] = $Item->quantity; $data['prod'] .= $Item->product_name . '*' . $Item->quantity; if ($Item->thumbnail_image) { foreach ($Item->thumbnail_image as $key => $Image) { if ($key == 'guid') { $data['image' . $i] = $Image; } } } else { $data['image0'] = 'https://www.mercadopago.com/org-img/MP3/home/logomp3.gif'; } } // exclude methods $shippingpostcode = array_key_exists("shippingpostcode", $arr_info) && $arr_info['shippingpostcode'] != "" ? $arr_info['shippingpostcode'] : "uninformed"; $shippingaddress = array_key_exists("shippingaddress", $arr_info) && $arr_info['shippingaddress'] != "" ? $arr_info['shippingaddress'] : "uninformed"; $shippingcity = array_key_exists("shippingcity", $arr_info) && $arr_info['shippingcity'] != "" ? $arr_info['shippingcity'] : "uninformed"; $shippingstate = array_key_exists("shippingstate", $arr_info) && $arr_info['shippingstate'] != "" ? $arr_info['shippingstate'] : "uninformed"; $shippingcountry = array_key_exists("shippingcountry", $arr_info) && $arr_info['shippingcountry'] != "" ? $arr_info['shippingcountry'] : "uninformed"; $shipments = array("receiver_address" => array("floor" => "-", "zip_code" => $shippingpostcode, "street_name" => $shippingaddress . " - " . $shippingcity . " - " . $shippingstate . " - " . $shippingcountry, "apartment" => "-", "street_number" => "-")); $billingpostcode = array_key_exists("billingpostcode", $arr_info) && $arr_info['billingpostcode'] != "" ? $arr_info['billingpostcode'] : "uninformed"; $billingaddress = array_key_exists("billingaddress", $arr_info) && $arr_info['billingaddress'] != "" ? $arr_info['billingaddress'] : "uninformed"; $billingcity = array_key_exists("billingcity", $arr_info) && $arr_info['billingcity'] != "" ? $arr_info['billingcity'] : "uninformed"; $billingstate = array_key_exists("billingstate", $arr_info) && $arr_info['billingstate'] != "" ? $arr_info['billingstate'] : "uninformed"; $billingcountry = array_key_exists("billingcountry", $arr_info) && $arr_info['billingcountry'] != "" ? $arr_info['billingcountry'] : "uninformed"; $billingphone = array_key_exists("billingphone", $arr_info) && $arr_info['billingphone'] != "" ? $arr_info['billingphone'] : "uninformed"; $payer = array("name" => $data['billingfirstname'], "surname" => $data['billinglastname'], "email" => $data['email'], "date_created" => "", "phone" => array("area_code" => "-", "number" => $billingphone), "address" => array("zip_code" => $billingpostcode, "street_name" => $billingaddress . " - " . $billingcity . " - " . $billingstate . " - " . $billingcountry, "street_number" => "-"), "identification" => array("number" => "null", "type" => "null")); $items = array(array("id" => $sessionid, "title" => $data['PROD_NAME0'], "description" => $data['PROD_NAME0'] . " x " . $data['PROD_QTY0'], "quantity" => 1, "unit_price" => $data['total'], "currency_id" => $data['currency'], "picture_url" => $data['image0'], "category_id" => $category)); //excludes_payment_methods $exclude = get_option('mercadopago_methods'); $installments = (int) get_option('mercadopago_limit_payments'); if ($exclude != '') { //case exist exclude methods $methods_excludes = preg_split("/[\\s,]+/", $exclude); $excludemethods = array(); foreach ($methods_excludes as $exclude) { if ($exclude != "") { $excludemethods[] = array('id' => $exclude); } } $payment_methods = array("installments" => $installments, "excluded_payment_methods" => $excludemethods); } else { //case not exist exclude methods $payment_methods = array("installments" => $installments); } //set back url $back_urls = array("pending" => $data['pending'], "success" => $data['sucess']); //mount array pref $pref = array(); $pref['external_reference'] = $sessionid; $pref['payer'] = $payer; $pref['shipments'] = $shipments; $pref['items'] = $items; $pref['back_urls'] = $back_urls; $pref['payment_methods'] = $payment_methods; $mp = new MP($data['client_id'], $data['client_secret']); $preferenceResult = $mp->create_preference($pref); if ($preferenceResult['status'] == 201) { if ($sandbox) { $link = $preferenceResult['response']['sandbox_init_point']; } else { $link = $preferenceResult['response']['init_point']; } } else { echo "Error: " . $preferenceResult['status']; } //title $title = ""; if (get_option('mercadopago_country') == 'MLB') { $title = 'Continue pagando com MercadoPago'; } else { $title = 'Continue pagando con MercadoPago'; } //add image $img_banner = ""; if (get_option('mercadopago_country') == 'MLB') { $img_banner = '<img src="http://img.mlstatic.com/org-img/MLB/MP/BANNERS/tipo2_468X60.jpg" alt="MercadoPago" title="MercadoPago" />'; } elseif (get_option('mercadopago_country') == 'MLM') { $img_banner = '<img src="http://imgmp.mlstatic.com/org-img/banners/mx/medios/MLM_468X108.JPG" title="MercadoPago - Medios de pago" alt="MercadoPago - Medios de pago" width="468" height="108"/>'; } elseif (get_option('mercadopago_country') == 'MLV') { $img_banner = '<img src="http://imgmp.mlstatic.com/org-img/banners/ar/medios/468X60.jpg" title="MercadoPago - Medios de pago" alt="MercadoPago - Medios de pago" width="468" height="60"/>'; } else { $img_banner = '<img src="http://imgmp.mlstatic.com/org-img/banners/ar/medios/468X60.jpg" alt="MercadoPago" title="MercadoPago" />'; } $button = ""; switch ($type_checkout) { case "Redirect": header("location: " . $link); break; case "Iframe": $button = ' <iframe src="' . $link . '" name="MP-Checkout" width="740" height="600" frameborder="0"></iframe> <script type="text/javascript"> (function(){function $MPBR_load(){window.$MPBR_loaded !== true && (function(){var s = document.createElement("script");s.type = "text/javascript";s.async = true; s.src = ("https:"==document.location.protocol?"https://www.mercadopago.com/org-img/jsapi/mptools/buttons/":"http://mp-tools.mlstatic.com/buttons/")+"render.js"; var x = document.getElementsByTagName("script")[0];x.parentNode.insertBefore(s, x);window.$MPBR_loaded = true;})();} window.$MPBR_loaded !== true ? (window.attachEvent ? window.attachEvent("onload", $MPBR_load) : window.addEventListener("load", $MPBR_load, false)) : null;})(); </script> '; break; case "Lightbox": default: $button = ' <a href="' . $link . '" name="MP-Checkout" class="blue-L-Rn" mp-mode="modal" onreturn="execute_my_onreturn">Pagar</a> <script type="text/javascript"> (function(){function $MPBR_load(){window.$MPBR_loaded !== true && (function(){var s = document.createElement("script");s.type = "text/javascript";s.async = true; s.src = ("https:"==document.location.protocol?"https://www.mercadopago.com/org-img/jsapi/mptools/buttons/":"http://mp-tools.mlstatic.com/buttons/")+"render.js"; var x = document.getElementsByTagName("script")[0];x.parentNode.insertBefore(s, x);window.$MPBR_loaded = true;})();} window.$MPBR_loaded !== true ? (window.attachEvent ? window.attachEvent("onload", $MPBR_load) : window.addEventListener("load", $MPBR_load, false)) : null;})(); </script> '; break; } //show page get_header(); $html = '<div style="position: relative; margin: 20px 0;" >'; $html .= '<div style="margin: 0 auto; width: 1080px; ">'; $html .= '<h3>' . $title . '</h3>'; $html .= '<p>' . $img_banner . '</p>'; $html .= $button; $html .= '</div>'; $html .= '</div>'; echo $html; get_footer(); exit; }
?> <div class="page-right-sidebar payment-option-page"> <div class="main"> <?php echo "<p class=\"uk-text-danger\">" . $error . "</p>"; ?> </div> </div> <?php } } else { if (is_array($data) && count($data) >= 1) { $amount_to_pay = isset($data['total_w_tax']) ? Yii::app()->functions->standardPrettyFormat($data['total_w_tax']) : ''; $amount_to_pay = is_numeric($amount_to_pay) ? unPrettyPrice($amount_to_pay) : ''; try { $mp = new MP($admin_mercado_id, $admin_mercado_key); $reference = Yii::app()->functions->generateRandomKey(); $_SESSION['mcd_ref'] = $reference; $preference_data = array("items" => array(array("title" => $payment_description . " " . $data['merchant_name'], "currency_id" => Yii::app()->functions->adminCurrencyCode(), "category_id" => "services", "quantity" => 1, "unit_price" => (double) $amount_to_pay)), "back_urls" => array("success" => Yii::app()->getBaseUrl(true) . "/store/mercadoInit/id/{$order_id}/status/success", "failure" => Yii::app()->getBaseUrl(true) . "/store/mercadoInit/id/{$order_id}/status/failure", "pending" => Yii::app()->getBaseUrl(true) . "/store/mercadoInit/id/{$order_id}/status/pending"), "auto_return" => "approved", "external_reference" => $reference); //dump($preference_data); $preference = $mp->create_preference($preference_data); ?> <div class="page-right-sidebar payment-option-page"> <div class="main"> <h2><?php echo Yii::t("default", "Pay using Mercadopago"); ?> </h2> <?php if ($paymode == "Sandbox") { ?>
<?php if (isset($_POST["_eventId_confirmation"])) { require_once "lib/mercadopago.php"; $clientid = $_SESSION['user']; $clientsecret = $_SESSION['pass']; $mp = new MP($clientid, $clientsecret); $preference = array('items' => array(array('id' => $_REQUEST['pedido'], 'title' => $_REQUEST['curso'], 'description' => $_REQUEST['desc'], 'quantity' => 1, 'unit_price' => (double) $_REQUEST['price'], 'currency_id' => 'BRL', 'category_id' => $_REQUEST['category'])), 'external_reference' => $_REQUEST['pedido'], 'payer' => array('name' => $_REQUEST['nome'], 'surname' => $_REQUEST['sobrenome'], 'email' => $_REQUEST['email'], 'phone' => array('area_code' => '55' . $_REQUEST['ddd'], 'number' => $_REQUEST['telefone']), 'identification' => array('type' => $_REQUEST['docto'], 'number' => $_REQUEST['cpf']), 'address' => array('street_name' => $_REQUEST['endereco'], 'street_number' => $_REQUEST['nro'], 'zip_code' => $_REQUEST['cep'])), 'shipments' => array('receiver_address' => array('zip_code' => $_REQUEST['cep'], 'street_number' => $_REQUEST['endereco'], 'street_name' => $_REQUEST['nro'], 'floor' => '', 'apartment' => '')), 'back_urls' => array('success' => '', 'failure' => '', 'pending' => ''), 'payment_methods' => array('excluded_payment_methods' => array(array('id' => '')), 'excluded_payment_types' => array(array('id' => 'ticket')), 'installments' => 24)); $preferenceResult = $mp->create_preference($preference); echo "<br><br><div class='ch-box-ok'><h2>Envie o link abaixo para o cliente : </h2><h3>" . $preferenceResult['response']['init_point'] . "</h3></div>"; } ?>
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 require_once "../../lib/mercadopago.php"; $mp = new MP("CLIENT_ID", "CLIENT_SECRET"); $preapprovalPayment_data = array("payer_email" => "my_customer@my_site.com", "back_url" => "http://www.my_site.com", "reason" => "Monthly subscription to premium package", "external_reference" => "OP-1234", "auto_recurring" => array("frequency" => 1, "frequency_type" => "months", "transaction_amount" => 60, "currency_id" => "BRL", "start_date" => "2012-12-10T14:58:11.778-03:00", "end_date" => "2013-06-10T14:58:11.778-03:00")); $preapprovalPayment = $mp->create_preapproval_payment($preapprovalPayment_data); ?> <!doctype html> <html> <head> <title>MercadoPago SDK - Create Preapproval Payment and Show Subscription Example</title> </head> <body> <a href="<?php echo $preapprovalPayment["response"]["init_point"]; ?> " name="MP-Checkout" class="orange-ar-m-sq-arall">Pay</a> <script type="text/javascript" src="http://mp-tools.mlstatic.com/buttons/render.js"></script> </body> </html>
<?php require_once 'mercadopago.php'; $mp = new MP('ACCESS_TOKEN'); $payment_data = array("transaction_amount" => 100, "token" => "ff8080814c11e237014c1ff593b57b4d", "description" => "Title of what you are paying for", "installments" => 1, "payer" => array("id" => "12345678")); $payment = $mp->post("/v1/payments", $payment_data);
<?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"]); } }
<ul class="nav navbar-nav navbar-right"> <li class="active"><a href="destroy.php">Logoff</a></li> </ul> </div> </div> </div> <div class="ch-box"> <h2>Balance</h2> <br> <?php $mp = new MP($clientid, $clientsecret); $balance = $mp->get_balance(); echo "<pre>"; print_r($balance); echo "</pre>"; ?> <p class="alert alert-success" style="width: 50%;padding: 5px;" role="alert"> Total : <b> R$ <? echo($balance["response"]["total_amount"]); ?></b></p> <p class="alert alert-info" style="width: 50%;padding: 5px;" role="alert"> Available : <b> R$ <? echo($balance["response"]["available_balance"]); ?></b></p> <p class="alert alert-warning" style="width: 50%;padding: 5px;" role="alert"> Unavailable : <b> R$ <? echo($balance["response"]["unavailable_balance"]); ?></b></p> </div>
<?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 require_once 'mercadopago.php'; $mp = new MP("ACCESS_TOKEN"); $cards = $mp->get("/v1/customers/[CUSTOMER_ID]/cards"); print_r($cards["response"]);
<?php require_once "lib/mercadopago.php"; $mp = new MP("CLIENT_ID", "CLIENT_SECRET"); $id = "PREAPPROVAL_ID"; $preapprovalPayment = array("payer_email" => "my_customer@my_site.com", "back_url" => "http://www.example.com.ar", "reason" => "Suscripción mensual", "external_reference" => "OP-1234", "frequency" => 1, "frequency_type" => "months", "transaction_amount" => 60, "currency_id" => "ARS", "start_date" => "2013-10-10T14:58:11.778-03:00", "end_date" => "2013-12-10T14:58:11.778-03:00"); $preapprovalPaymentResult = $mp->update_preapproval_payment($id, $preapprovalPayment); ?> <!doctype html> <html> <head> <title>MercadoPago SDK - Create Preapproval Payment and Show Subscription Example</title> </head> <body> <a href="<?php echo $preapprovalPaymentResult["response"]["init_point"]; ?> " name="MP-Checkout" class="orange-ar-m-sq-arall">Pay</a> <script type="text/javascript" src="http://mp-tools.mlstatic.com/buttons/render.js"></script> </body> </html>