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 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; }
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); }
/** * 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>"; }
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; }
/** * Booking 4/4 */ public static function carrental_confirm_reservation() { $order_hash = self::save_booking($_POST); if ((int) $_POST['paypal'] == 1 && (double) $_POST['total_rental'] > 0) { $paypal = get_option('carrental_paypal'); $available_payments = unserialize(get_option('carrental_available_payments')); if (isset($available_payments) && isset($available_payments['carrental-paypal-security-deposit']) && (double) $available_payments['carrental-paypal-security-deposit'] > 0) { // if paypal security deposit is set $_POST['total_rental'] = $_POST['total_rental'] * ((double) $available_payments['carrental-paypal-security-deposit'] / 100); if (isset($available_payments['carrental-paypal-security-deposit-round'])) { if ($available_payments['carrental-paypal-security-deposit-round'] == 'up') { $_POST['total_rental'] = ceil($_POST['total_rental']); } elseif ($available_payments['carrental-paypal-security-deposit-round'] == 'down') { $_POST['total_rental'] = floor($_POST['total_rental']); } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } } // Redirect to PayPal $query = array(); $query['cmd'] = '_xclick'; $query['business'] = $paypal; $query['email'] = $_POST['email']; $query['item_name'] = 'Car Rental Reservation #' . $order_hash; $query['quantity'] = 1; $query['return'] = home_url() . '?page=carrental&payment=paypal&summary=' . $order_hash; $query['item_number'] = $order_hash; $query['custom'] = isset($_SESSION['carrental_language']) && !empty($_SESSION['carrental_language']) ? $_SESSION['carrental_language'] : 'en_GB'; $query['notify_url'] = CARRENTAL__PLUGIN_URL . 'paypal_ipn.php'; $query['cancel_return'] = $_SERVER['HTTP_REFERER'] . '&paymentError=1'; $query['amount'] = number_format((double) $_POST['total_rental'], 2, '.', ''); $query['currency_code'] = $_POST['currency_code']; // Prepare query string $query_string = http_build_query($query); Header('Location: https://www.paypal.com/cgi-bin/webscr?' . $query_string); return; } // is it eway payment? if ($_POST['payment_option'] == 'eway' && (double) $_POST['total_rental'] > 0) { $payments_others = unserialize(get_option('carrental_available_payments_others')); if ($payments_others && !empty($payments_others) && isset($payments_others['eway']) && $payments_others['eway']['enabled'] == 'yes' && (double) $payments_others['eway']['security-deposit'] > 0) { $_POST['total_rental'] = $_POST['total_rental'] * ((double) $payments_others['eway']['security-deposit'] / 100); if (isset($payments_others['eway']['security-deposit-round'])) { if ($payments_others['eway']['security-deposit-round'] == 'up') { $_POST['total_rental'] = ceil($_POST['total_rental']); } elseif ($payments_others['eway']['security-deposit-round'] == 'down') { $_POST['total_rental'] = floor($_POST['total_rental']); } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } require_once dirname(dirname(__FILE__)) . '/carrental-payments-eway/RapidAPI.php'; $request = new eWAY\CreateAccessCodesSharedRequest(); $request->Payment->TotalAmount = number_format((double) $_POST['total_rental'], 2, '.', '') * 100; // Amount is in cents, 100 = $1.00 //$request->Payment->CurrencyCode = 'AUD';//$_POST['currency_code']; $request->Payment->InvoiceReference = $order_hash; $request->Options->Option[] = isset($_SESSION['carrental_language']) && !empty($_SESSION['carrental_language']) ? $_SESSION['carrental_language'] : 'en_GB'; $request->RedirectUrl = CARRENTAL__PLUGIN_URL . 'eway_ipn.php'; $request->CancelUrl = $_SERVER['HTTP_REFERER'] . '&ewayError=1'; $service = new eWAY\RapidAPI($payments_others['eway']['api-key'], $payments_others['eway']['api-password']); //print_r($request);die(); // Get the AccessCode $result = $service->CreateAccessCodesShared($request); if (!empty($result->Errors)) { die(eWAY\ResponseCode::getMessage($result->Errors)); } // Send the customer to eWAY to pay header("Location: " . $result->SharedPaymentUrl); exit; } } // is it mercadopago payment? if ($_POST['payment_option'] == 'mercadopago' && (double) $_POST['total_rental'] > 0) { $payments_others = unserialize(get_option('carrental_available_payments_others')); if ($payments_others && !empty($payments_others) && isset($payments_others['mercadopago']) && $payments_others['mercadopago']['enabled'] == 'yes' && (double) $payments_others['mercadopago']['security-deposit'] > 0) { $_POST['total_rental'] = $_POST['total_rental'] * ((double) $payments_others['mercadopago']['security-deposit'] / 100); if (isset($payments_others['mercadopago']['security-deposit-round'])) { if ($payments_others['mercadopago']['security-deposit-round'] == 'up') { $_POST['total_rental'] = ceil($_POST['total_rental']); } elseif ($payments_others['mercadopago']['security-deposit-round'] == 'down') { $_POST['total_rental'] = floor($_POST['total_rental']); } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } require_once dirname(dirname(__FILE__)) . '/carrental-payments-mercadopago/mercadopago.php'; $mp = new MP($payments_others['mercadopago']['client-id'], $payments_others['mercadopago']['client-secret']); $sandbox = false; $mp->sandbox_mode($sandbox); $preference_data = array("items" => array(array("id" => $order_hash, "title" => 'Car Rental Reservation #' . $order_hash, "currency_id" => 'ARS', "category_id" => "Category", "quantity" => 1, "unit_price" => (double) number_format((double) $_POST['total_rental'], 2, '.', ''))), "back_urls" => array("success" => home_url() . '?page=carrental&payment=paypal&summary=' . $order_hash, "failure" => $_SERVER['HTTP_REFERER'] . '&paymentError=1', "pending" => home_url() . '?page=carrental&payment=paypal&summary=' . $order_hash), "auto_return" => "approved", "notification_url" => CARRENTAL__PLUGIN_URL . 'mercadopago_ipn.php', "external_reference" => $order_hash . '#' . (isset($_SESSION['carrental_language']) && !empty($_SESSION['carrental_language']) ? $_SESSION['carrental_language'] : 'en_GB'), "expires" => false, "expiration_date_from" => null, "expiration_date_to" => null); try { $preference = $mp->create_preference($preference_data); } catch (Exception $e) { echo 'Error during MercadoPago payment: ' . $e->getMessage() . '. Please contact the administrator.'; exit; } Header('Location: ' . $preference['response'][($sandbox ? 'sandbox_' : '') . 'init_point']); exit; } } do_action('carrental_after_save_booking', $order_hash); Header('Location: ' . home_url() . '?page=carrental&summary=' . $order_hash); exit; }
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> </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") { ?> <a href="<?php echo $preference["response"]["sandbox_init_point"]; ?> " name="MP-Checkout" class="lightblue-M-Ov-ArOn">Pay</a> <?php
<?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>"; } ?>
protected function index() { $this->data['button_confirm'] = $this->language->get('button_confirm'); $this->data['button_back'] = $this->language->get('button_back'); if ($this->config->get('mercadopago2_country')) { $this->data['action'] = $this->config->get('mercadopago2_country'); } $this->load->model('checkout/order'); $this->language->load('payment/mercadopago2'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('mercadopago2_order_status_id')); //Cambio el código ISO-3 de la moneda por el que se les ocurrio poner a los de mercadopago2!!! switch ($order_info['currency_code']) { case "ARS": $currency = 'ARS'; break; case "ARG": $currency = 'ARS'; break; case "VEF": $currency = 'VEF'; break; case "BRA": case "BRL": case "REA": $currency = 'BRL'; break; case "MXN": $currency = 'MEX'; break; case "CLP": $currency = 'CHI'; break; default: $currency = 'USD'; break; } $currencies = array('ARS', 'BRL', 'MEX', 'CHI', 'VEF'); if (!in_array($currency, $currencies)) { $currency = ''; $this->data['error'] = $this->language->get('currency_no_support'); } $products = ''; foreach ($this->cart->getProducts() as $product) { $products .= $product['quantity'] . ' x ' . $product['name'] . ', '; } $allproducts = $this->cart->getProducts(); $firstproduct = reset($allproducts); // dados 2.0 $totalprice = $order_info['total'] * $order_info['currency_value']; $this->id = 'payment'; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/mercadopago2.tpl')) { $this->template = $this->config->get('config_template') . '/template/payment/mercadopago2.tpl'; } else { $this->template = 'default/template/payment/mercadopago2.tpl'; } $this->data['server'] = $_SERVER; $this->data['debug'] = $this->config->get('mercadopago2_debug'); // get credentials $client_id = $this->config->get('mercadopago2_client_id'); $client_secret = $this->config->get('mercadopago2_client_secret'); $url = $this->config->get('mercadopago2_url'); $installments = (int) $this->config->get('mercadopago2_installments'); $shipments = array("receiver_address" => array("floor" => "-", "zip_code" => $order_info['shipping_postcode'], "street_name" => $order_info['shipping_address_1'] . " - " . $order_info['shipping_address_2'] . " - " . $order_info['shipping_city'] . " - " . $order_info['shipping_zone'] . " - " . $order_info['shipping_country'], "apartment" => "-", "street_number" => "-")); //Force format YYYY-DD-MMTH:i:s $cust = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` WHERE customer_id = " . $order_info['customer_id'] . " "); $date_created = ""; $date_creation_user = ""; if ($cust->num_rows > 0) { foreach ($cust->rows as $customer) { $date_created = $customer['date_added']; } $date_creation_user = date('Y-m-d', strtotime($date_created)) . "T" . date('H:i:s', strtotime($date_created)); } $payer = array("name" => $order_info['payment_firstname'], "surname" => $order_info['payment_lastname'], "email" => $order_info['email'], "date_created" => $date_creation_user, "phone" => array("area_code" => "-", "number" => $order_info['telephone']), "address" => array("zip_code" => $order_info['payment_postcode'], "street_name" => $order_info['payment_address_1'] . " - " . $order_info['payment_address_2'] . " - " . $order_info['payment_city'] . " - " . $order_info['payment_zone'] . " - " . $order_info['payment_country'], "street_number" => "-"), "identification" => array("number" => "null", "type" => "null")); $items = array(array("id" => $order_info['order_id'], "title" => $firstproduct['name'], "description" => $firstproduct['quantity'] . ' x ' . $firstproduct['name'], "quantity" => 1, "unit_price" => round($totalprice, 2), "currency_id" => $currency, "picture_url" => HTTP_SERVER . 'image/' . $firstproduct['image'], "category_id" => $this->config->get('mercadopago2_category_id'))); //excludes_payment_methods $exclude = $this->config->get('mercadopago2_methods'); $installments = (int) $installments; 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" => $url . '/index.php?route=payment/mercadopago2/callback', "success" => $url . '/index.php?route=payment/mercadopago2/callback'); //mount array pref $pref = array(); $pref['external_reference'] = $order_info['order_id']; $pref['payer'] = $payer; $pref['shipments'] = $shipments; $pref['items'] = $items; $pref['back_urls'] = $back_urls; $pref['payment_methods'] = $payment_methods; $mp = new MP($client_id, $client_secret); $preferenceResult = $mp->create_preference($pref); $sandbox = $this->config->get('mercadopago2_sandbox') == 1 ? true : false; if ($preferenceResult['status'] == 201) { $this->data['type_checkout'] = $this->config->get('mercadopago2_type_checkout'); if ($sandbox) { $this->data['link'] = $preferenceResult['response']['sandbox_init_point']; } else { $this->data['link'] = $preferenceResult['response']['init_point']; } } else { $this->data['error'] = "Error: " . $preferenceResult['status']; } $this->render(); }
public function index() { $data['button_confirm'] = $this->language->get('button_confirm'); $data['button_back'] = $this->language->get('button_back'); $data['terms'] = 'Teste de termos'; if ($this->config->get('mercadopago2_country')) { $data['action'] = $this->config->get('mercadopago2_country'); } $this->load->model('checkout/order'); $this->language->load('payment/mercadopago2'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); //echo "order status id" . $this->config->get('mercadopago2_order_status_id'); //$this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('mercadopago2_order_status_id')); //Cambio el código ISO-3 de la moneda por el que se les ocurrio poner a los de mercadopago2!!! switch ($order_info['currency_code']) { case "ARS": $currency = 'ARS'; break; case "ARG": $currency = 'ARS'; break; case "VEF": $currency = 'VEF'; break; case "BRA": case "BRL": case "REA": $currency = 'BRL'; break; case "MXN": $currency = 'MEX'; break; case "CLP": $currency = 'CHI'; break; default: $currency = 'USD'; break; } $currencies = array('ARS', 'BRL', 'MEX', 'CHI', 'VEF'); if (!in_array($currency, $currencies)) { $currency = ''; $data['error'] = $this->language->get('currency_no_support'); } /*CHAVES do array de produto cart_id, product_id, name, model, shipping, image, option, download, quantity, minimum, subtract, stock, price, total, reward, points, tax_class_id, weight, weight_class_id, length, width, height, length_class_id, recurring */ $totalprice = $order_info['total'] * $order_info['currency_value']; $products = ''; $all_products = $this->cart->getProducts(); $items = array(); foreach ($all_products as $product) { error_log('product keys' . implode(',', array_keys($product))); $products .= $product['quantity'] . ' x ' . $product['name'] . ', '; $items[] = array("id" => $product['product_id'], "title" => $product['name'], "description" => $product['quantity'] . ' x ' . $product['name'], "quantity" => intval($product['quantity']), "unit_price" => round(floatval($product['price']), 2), "currency_id" => $currency, "picture_url" => HTTP_SERVER . 'image/' . $product['image'], "category_id" => $this->config->get('mercadopago2_category_id')); } //$firstproduct = reset($allproducts); // dados 2.0 $this->id = 'payment'; $data['server'] = $_SERVER; $data['debug'] = $this->config->get('mercadopago2_debug'); // get credentials $client_id = $this->config->get('mercadopago2_client_id'); $client_secret = $this->config->get('mercadopago2_client_secret'); $url = $this->config->get('mercadopago2_url'); $installments = (int) $this->config->get('mercadopago2_installments'); $shipments = array("receiver_address" => array("floor" => "-", "zip_code" => $order_info['shipping_postcode'], "street_name" => $order_info['shipping_address_1'] . " - " . $order_info['shipping_address_2'] . " - " . $order_info['shipping_city'] . " - " . $order_info['shipping_zone'] . " - " . $order_info['shipping_country'], "apartment" => "-", "street_number" => "-")); //Force format YYYY-DD-MMTH:i:s $cust = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` WHERE customer_id = " . $order_info['customer_id'] . " "); $date_created = ""; $date_creation_user = ""; if ($cust->num_rows > 0) { foreach ($cust->rows as $customer) { $date_created = $customer['date_added']; } $date_creation_user = date('Y-m-d', strtotime($date_created)) . "T" . date('H:i:s', strtotime($date_created)); } $payer = array("name" => $order_info['payment_firstname'], "surname" => $order_info['payment_lastname'], "email" => $order_info['email'], "date_created" => $date_creation_user, "phone" => array("area_code" => "-", "number" => $order_info['telephone']), "address" => array("zip_code" => $order_info['payment_postcode'], "street_name" => $order_info['payment_address_1'] . " - " . $order_info['payment_address_2'] . " - " . $order_info['payment_city'] . " - " . $order_info['payment_zone'] . " - " . $order_info['payment_country'], "street_number" => "-"), "identification" => array("number" => "null", "type" => "null")); /* $items = array( array ( "id" => $order_info['order_id'], "title" => $firstproduct['name'], "description" => $firstproduct['quantity'] . ' x ' . $firstproduct['name'], // string "quantity" => 1, "unit_price" => round($totalprice, 2), //decimal "currency_id" => $currency ,// string Argentina: ARS (peso argentino) � USD (D�lar estadounidense); Brasil: BRL (Real)., "picture_url"=> HTTP_SERVER . 'image/' . $firstproduct['image'], "category_id"=> $this->config->get('mercadopago2_category_id') ) ); */ //excludes_payment_methods $exclude = $this->config->get('mercadopago2_methods'); $installments = (int) $installments; if ($exclude != '') { $accepted_methods = preg_split("/[\\s,]+/", $exclude); $all_payment_methods = $this->getMethods($this->config->get('mercadopago2_country')); $excluded_payments = array(); foreach ($all_payment_methods as $method) { if (!in_array($method['id'], $accepted_methods)) { if ($method['id'] != 'account_money') { $excluded_payments[] = array('id' => $method['id']); } } } $payment_methods = array("installments" => $installments, "excluded_payment_methods" => $excluded_payments); } else { //case not exist exclude methods $payment_methods = array("installments" => $installments); } //set back url $back_urls = array("pending" => $url . '/index.php?route=payment/mercadopago2/callback', "success" => $url . '/index.php?route=payment/mercadopago2/callback'); $pref = array(); $pref['external_reference'] = $order_info['order_id']; $pref['payer'] = $payer; $pref['shipments'] = $shipments; $pref['items'] = $items; $pref['back_urls'] = $back_urls; $pref['payment_methods'] = $payment_methods; $pref['auto_return'] = $this->config->get('mercadopago2_enable_return'); $mp = new MP($client_id, $client_secret); $preferenceResult = $mp->create_preference($pref); $sandbox = $this->config->get('mercadopago2_sandbox') == 1 ? true : false; if ($preferenceResult['status'] == 201) { $data['type_checkout'] = $this->config->get('mercadopago2_type_checkout'); if ($sandbox) { $data['redirect_link'] = $preferenceResult['response']['sandbox_init_point']; } else { $data['redirect_link'] = $preferenceResult['response']['init_point']; } } else { $data['error'] = "Error: " . $preferenceResult['status']; } //botão deve ser exibido aqui if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/mercadopago2.tpl')) { return $this->load->view($this->config->get('config_template') . '/template/payment/mercadopago2.tpl', $data); } else { return $this->load->view('default/template/payment/mercadopago2.tpl', $data); } }
public function get_mercadopago() { Bootstrap::$main->human_datetime_format(); $guest = $this->guest()->get($this->id); $event = $this->event()->get($guest['event']); $this->before_operator($guest, $event); $config = Bootstrap::$main->getConfig(); $data = Bootstrap::$main->user; $data['client_ip'] = Bootstrap::$main->ip; foreach ($config as $k => $v) { if (current($a = explode('.', $k)) == 'mercadopago') { $data[end($a)] = $v; } } require_once __DIR__ . '/../class/mercadopago.php'; $preference_data = array("items" => array(array("title" => $event['name'], "quantity" => $guest['persons'], "currency_id" => $event['currency'], "unit_price" => $guest['guest_price'])), "payer" => array('name' => Bootstrap::$main->user['firstname'], 'surname' => Bootstrap::$main->user['lastname'], 'email' => Bootstrap::$main->user['email']), "back_urls" => array('success' => Bootstrap::$main->getConfig('protocol') . '://' . $_SERVER['HTTP_HOST'] . Bootstrap::$main->getRoot() . 'guest/mercadopagoresult', 'pending' => Bootstrap::$main->getConfig('protocol') . '://' . $_SERVER['HTTP_HOST'] . Bootstrap::$main->getRoot() . 'guest/mercadopagoresult', 'failure' => Bootstrap::$main->getConfig('protocol') . '://' . $_SERVER['HTTP_HOST'] . Bootstrap::$main->getRoot() . 'guest/mercadopagoresult'), "notification_url" => Bootstrap::$main->getConfig('protocol') . '://' . $_SERVER['HTTP_HOST'] . Bootstrap::$main->getRoot() . 'guest/mercadopago'); try { $mp = new MP($data['client_id'], $data['client_secret']); $preference = $mp->create_preference($preference_data); } catch (Exception $e) { mydie($e); } //mydie($preference); $data = array_merge($data, $event, $guest); $user = new userModel($event['user']); $payment = new paymentModel(); $payment->status = 1; $payment->guest = $this->id; $payment->d_create = Bootstrap::$main->now; $payment->channel = 'mercadopago'; $payment->amount = $data['guest_price'] * $data['persons']; $payment->order_id = $preference['response']['id']; $payment->save(); $html = file_get_contents(__DIR__ . '/../resources/mercadopago.html'); foreach ($preference['response'] as $k => $v) { if (!is_array($v)) { $html = str_replace('{' . $k . '}', $v, $html); } } die($html); }
public function hookPaymentReturn($params) { global $cookie, $smarty; // dados do cliente $customer = new Customer(intval($cookie->id_customer)); $ArrayCliente = $customer->getFields(); // dados do pedido $DadosOrder = new Order($params['objOrder']->id); $ArrayListaProdutos = $DadosOrder->getProducts(); //Get shipment $address_delivery = new Address(intval($params['cart']->id_address_delivery)); $shipments = array("receiver_address" => array("floor" => "-", "zip_code" => $address_delivery->postcode, "street_name" => $address_delivery->address1 . " - " . $address_delivery->address2 . " - " . $address_delivery->city . "/" . $address_delivery->country, "apartment" => "-", "street_number" => "-")); //Force format YYYY-DD-MMTH:i:s $date_creation_user = date('Y-m-d', strtotime($ArrayCliente['date_add'])) . "T" . date('H:i:s', strtotime($ArrayCliente['date_add'])); $address_invoice = new Address(intval($params['cart']->id_address_invoice)); $phone = $address_invoice->phone; $phone .= $phone == "" ? "" : "|"; $phone .= $address_invoice->phone_mobile; $payer = array("name" => $ArrayCliente['firstname'], "surname" => $ArrayCliente['lastname'], "email" => $ArrayCliente['email'], "date_created" => $date_creation_user, "phone" => array("area_code" => "-", "number" => $phone), "address" => array("zip_code" => $address_invoice->postcode, "street_name" => $address_invoice->address1 . " - " . $address_delivery->address2 . " - " . $address_delivery->city . "/" . $address_delivery->country, "street_number" => "-"), "identification" => array("number" => "null", "type" => "null")); //items $image_url = ""; // gera descrição foreach ($ArrayListaProdutos as $info) { $item = array($zb[] = $info['product_name'] . ' * ' . $info['product_quantity']); //get object image on product object $id_image = $info['image']; // get Image by id if (sizeof($id_image) > 0) { $image = new Image($id_image->id_image); // get image full URL $image_url = _PS_BASE_URL_ . _THEME_PROD_DIR_ . $image->getExistingImgPath() . "." . $image->image_format; } } $descricao = implode(" + ", $zb); $item_price = number_format($params['total_to_pay'], 2, '.', ''); $currency = new Currency($DadosOrder->id_currency); $items = array(array("id" => $params['objOrder']->id, "title" => utf8_encode($descricao), "description" => utf8_encode($descricao), "quantity" => 1, "unit_price" => round($item_price, 2), "currency_id" => $currency->iso_code, "picture_url" => $image_url, "category_id" => Configuration::get('mercadopago_CATEGORY'))); //excludes_payment_methods $exclude = Configuration::get('mercadopago_METHODS'); $installments = Configuration::get('mercadopago_INSTALLMENTS'); $installments = str_replace("inst-", "", $installments); $installments = (int) $installments; 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" => Configuration::get('mercadopago_URLPROCESS'), "success" => Configuration::get('mercadopago_URLSUCCESFULL')); //mount array pref $pref = array(); $pref['external_reference'] = $params['objOrder']->id; $pref['payer'] = $payer; $pref['shipments'] = $shipments; $pref['items'] = $items; $pref['back_urls'] = $back_urls; $pref['payment_methods'] = $payment_methods; $client_id = Configuration::get('mercadopago_CLIENT_ID'); $client_secret = Configuration::get('mercadopago_CLIENT_SECRET'); $mp = new MP($client_id, $client_secret); $preferenceResult = $mp->create_preference($pref); $sandbox = Configuration::get('mercadopago_SANDBOX') == "active" ? true : false; $url = ""; if ($sandbox) { $url = $preferenceResult['response']['sandbox_init_point']; } else { $url = $preferenceResult['response']['init_point']; } switch (Configuration::get('mercadopago_TYPECHECKOUT')) { case "Iframe": $botton = ' <iframe src="' . $url . '" 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 "Redirect": header("location: " . $url); break; case "Lightbox": default: $botton = ' <a href="' . $url . '" 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; } $smarty->assign(array('totalApagar' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false), 'status' => 'ok', 'seller_op_id' => $params['objOrder']->id, 'secure_key' => $params['objOrder']->secure_key, 'id_module' => $this->id, 'formmercadopago' => $botton, 'imgBanner' => $this->getBanner())); return $this->display(__FILE__, 'payment_return.tpl'); }
/** * Crear el pago de mercadopago * @param $codigoM * @param $hashM * @param $sitioweb * @param $valor * @param $moneda * @param $cantidadProductos * @param $nombreProducto * @param $detalleProducto * @param $urlSucess * @param string $nombreCliente * @param string $apellidoCliente * @param string $dniCliente * @param string $mailCliente * @param string $comentariosAdicionales * @return array * @internal param $urlConcretado * @internal param $urlPendiente * @internal param $urlFallado * @internal param $sandbox */ public function pagoMercadopago($codigoM, $hashM, $sitioweb, $valor, $moneda, $cantidadProductos, $nombreProducto, $detalleProducto, $urlSucess, $excluir = true, $nombreCliente = '', $apellidoCliente = '', $dniCliente = '', $mailCliente = '', $comentariosAdicionales = '') { //url base $this->url_final = $urlSucess; $excluidos = array(); $excluidos_tipo = array(); if ($excluir) { $excluidos = array(array("id" => "rapipago"), array("id" => "pagofacil"), array("id" => "bapropagos")); $excluidos_tipo = array(array("id" => "ticket"), array("id" => "atm"), array("id" => "bank_transfer")); } //crear el pago //require_once('vendor/autoload.php'); $mp = new MP($codigoM, $hashM); $preference_data = array("items" => array(array("title" => $nombreProducto, "quantity" => $cantidadProductos, "currency_id" => $moneda, "unit_price" => (int) $valor, "category_id" => "services", "description" => $detalleProducto, "picture_url" => $sitioweb . "/images/logo.png")), "payer" => array("name" => $nombreCliente, "surname" => $apellidoCliente, "email" => $mailCliente, "identification" => array("type" => "dni", "number" => $dniCliente)), "payment_methods" => array("excluded_payment_methods" => $excluidos, "excluded_payment_types" => $excluidos_tipo, "installments" => 12), "back_urls" => array("success" => $urlSucess, "pending" => $urlSucess, "failure" => $urlSucess), "additional_info" => $comentariosAdicionales); $preference = $mp->create_preference($preference_data); $this->pref = $preference; return $this->pref; }
public function index() { $data['customer_email'] = $this->customer->getEmail(); $data['button_confirm'] = $this->language->get('button_confirm'); $data['button_back'] = $this->language->get('button_back'); $data['terms'] = 'Teste de termos'; $data['public_key'] = $this->config->get('mp_standard_public_key'); if ($this->config->get('mp_standard_country')) { $data['action'] = $this->config->get('mp_standard_country'); } $this->load->model('checkout/order'); $this->language->load('payment/mp_standard'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); //Cambio el código ISO-3 de la moneda por el que se les ocurrio poner a los de mp_standard!!! $accepted_currencies = array('ARS' => 'ARS', 'ARG' => 'ARS', 'VEF' => 'VEF', 'BRA' => 'BRL', 'BRL' => 'BRL', 'REA' => 'BRL', 'MXN' => 'MEX', 'CLP' => 'CHI', 'COP' => 'COP', 'PEN' => 'PEN', 'US' => 'US'); $currency = $accepted_currencies[$order_info['currency_code']]; $currencies = array('ARS', 'BRL', 'MEX', 'CHI', 'PEN', 'VEF', 'COP'); if (!in_array($currency, $currencies)) { $currency = ''; $data['error'] = $this->language->get('currency_no_support'); } $totalprice = $order_info['total'] * $order_info['currency_value']; $products = ''; $all_products = $this->cart->getProducts(); $items = array(); foreach ($all_products as $product) { $products .= $product['quantity'] . ' x ' . $product['name'] . ', '; $items[] = array("id" => $product['product_id'], "title" => $product['name'], "description" => $product['quantity'] . ' x ' . $product['name'], "quantity" => intval($product['quantity']), "unit_price" => round(floatval($product['price']), 2) * $order_info['currency_value'], "currency_id" => $currency, "picture_url" => HTTP_SERVER . 'image/' . $product['image'], "category_id" => $this->config->get('mp_standard_category_id')); } $this->id = 'payment'; $data['server'] = $_SERVER; $data['debug'] = $this->config->get('mp_standard_debug'); $client_id = $this->config->get('mp_standard_client_id'); $client_secret = $this->config->get('mp_standard_client_secret'); $url = $order_info['store_url']; $installments = (int) $this->config->get('mp_standard_installments'); $shipments = array("receiver_address" => array("floor" => "-", "zip_code" => $order_info['shipping_postcode'], "street_name" => $order_info['shipping_address_1'] . " - " . $order_info['shipping_address_2'] . " - " . $order_info['shipping_city'] . " - " . $order_info['shipping_zone'] . " - " . $order_info['shipping_country'], "apartment" => "-", "street_number" => "-"), "cost" => round(floatval($this->session->data['shipping_method']['cost']), 2) * $order_info['currency_value'], "mode" => "custom"); $cust = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` WHERE customer_id = " . $order_info['customer_id'] . " "); $date_created = ""; $date_creation_user = ""; if ($cust->num_rows > 0) { foreach ($cust->rows as $customer) { $date_created = $customer['date_added']; } $date_creation_user = date('Y-m-d', strtotime($date_created)) . "T" . date('H:i:s', strtotime($date_created)); } $payer = array("name" => $order_info['payment_firstname'], "surname" => $order_info['payment_lastname'], "email" => $order_info['email'], "date_created" => $date_creation_user, "phone" => array("area_code" => "-", "number" => $order_info['telephone']), "address" => array("zip_code" => $order_info['payment_postcode'], "street_name" => $order_info['payment_address_1'] . " - " . $order_info['payment_address_2'] . " - " . $order_info['payment_city'] . " - " . $order_info['payment_zone'] . " - " . $order_info['payment_country'], "street_number" => "-"), "identification" => array("number" => "null", "type" => "null")); $exclude = $this->config->get('mp_standard_methods'); $country_id = $this->config->get('mp_standard_country') == null ? 'MLA' : $this->config->get('mp_standard_country'); $installments = (int) $installments; if ($exclude != '') { $accepted_methods = preg_split("/[\\s,]+/", $exclude); $all_payment_methods = $this->getMethods($country_id); $excluded_payments = array(); sleep(3); foreach ($all_payment_methods as $method) { if (!in_array($method['id'], $accepted_methods) && $method['id'] != 'account_money') { $excluded_payments[] = array('id' => $method['id']); } } $payment_methods = array("installments" => $installments, "excluded_payment_methods" => $excluded_payments); } else { //case not exist exclude methods $payment_methods = array("installments" => $installments); } //set back url $back_urls = array("pending" => $url . 'index.php?route=payment/mp_standard/callback', "success" => $url . 'index.php?route=payment/mp_standard/callback', "failure" => $url . 'index.php?route=payment/mp_standard/callback'); $pref = array(); $pref['external_reference'] = $order_info['order_id']; $pref['items'] = $items; $pref['shipments'] = $shipments; $pref['auto_return'] = $this->config->get('mp_standard_enable_return'); $pref['back_urls'] = $back_urls; $pref['payment_methods'] = $payment_methods; $pref['payer'] = $payer; $pref['notification_url'] = $order_info['store_url'] . 'index.php?route=payment/mp_standard/notifications'; $sandbox = (bool) $this->config->get('mp_standard_sandbox'); $is_test_user = strpos($order_info['email'], '@testuser.com'); if (!$is_test_user) { $pref["sponsor_id"] = $this->sponsors[$this->config->get('mp_standard_country')]; } $mp = new MP($client_id, $client_secret); $preferenceResult = $mp->create_preference($pref); if ($preferenceResult['status'] == 201) { $data['type_checkout'] = $this->config->get('mp_standard_type_checkout'); if ($sandbox) { $data['redirect_link'] = $preferenceResult['response']['sandbox_init_point']; } else { $data['redirect_link'] = $preferenceResult['response']['init_point']; } } else { $data['error'] = "Error: " . $preferenceResult['status']; } $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('order_status_id_pending'), date('d/m/Y h:i')); $view = floatval(VERSION) < 2.2 ? 'default/template/payment/mp_standard.tpl' : 'payment/mp_standard.tpl'; return $this->load->view($view, $data); }
/** * * @param type $order * Esta funcion se ejecuta luego de seleccionar el metodo de pago y despues de la * funcion process payment. */ function receipt_page($order_id) { $dir = plugin_dir_url(__FILE__); $js = $dir . "../js/redirect.js"; wp_enqueue_script('jquery'); wp_enqueue_script('ctala-redirect', $js, array('jquery')); global $woocommerce; $order = new \WC_Order($order_id); $preference_data = array(); $mp = new \MP($this->get_option('clientid'), $this->get_option('secretkey')); echo '<p>' . __('¡Gracias! - Tu orden ahora está pendiente de pago.') . '</p>'; echo '<p>' . __('Ahora serás redirigido automáticamente a Mercado Pago') . '</p>'; /* * Asignamos los items a la orden */ $orderItems = $order->get_items(); $items = array(); foreach ($orderItems as $orderItem) { $id = $orderItem["item_meta"]["_product_id"][0]; $qty = intval($orderItem["item_meta"]["_qty"][0]); $product = new \WC_Product($id); $price = (double) $product->price; $items[] = array("title" => $product->get_title(), "quantity" => $qty, "currency_id" => $order->get_order_currency(), "unit_price" => $price); /* * Liberamos algo de memoria para wordpress. */ unset($price); unset($product); unset($id); unset($qty); } ctala_log_me($items); /* * Agregamos las URL Correspondientes a las respuestas. */ $successUrl = $this->get_return_url($order); $failureUrl = $this->get_return_url($order); $pendingUrl = $this->get_return_url($order); $back_urls = array('success' => $successUrl, 'pending' => $pendingUrl, 'failure' => $failureUrl); /* * Sobre el costo del envio */ $shippingCost = floatval($order->get_total_shipping()); $shipments = array("cost" => $shippingCost); /** * Sobre los metodos de pago * La variable que contiene los metodos de pago excluidos es "mediosdepago" */ $ePayments = $this->get_option('mediosdepago'); ctala_log_me($ePayments); $excluded_payment_methods = array(); foreach ($ePayments as $payment_method => $id) { $excluded_payment_methods[] = array("id" => $id); } ctala_log_me($excluded_payment_methods); $excluded_payment_types = array(); /* * Creo que son las cuotas :) */ $installments = intval(get_post_meta($order_id, "CUOTASMP", true)); ctala_log_me("CUOTAS : " . $installments); $payment_methods = array('excluded_payment_methods' => $excluded_payment_methods, 'excluded_payment_types' => $excluded_payment_types, 'installments' => $installments); /* * Informacion adicional */ $additional_info = array('order_id' => $order_id); $preference_data["additional_info"] = $additional_info; $preference_data["external_reference"] = $order_id; $preference_data["order_id"] = $order_id; $preference_data["items"] = $items; $preference_data["back_urls"] = $back_urls; $preference_data["notification_url"] = $this->notification_url; $preference_data["auto_return"] = "approved"; $preference_data["payment_methods"] = $payment_methods; $preference_data["shipments"] = $shipments; $preference = $mp->create_preference($preference_data); ctala_log_me($preference); /** * La Url de redireccion dependera de si estamos en modo desarrollo. */ $modoDesarrollo = $this->get_option('desarrollo'); ctala_log_me($modoDesarrollo, "[MODO DESARROLLO]"); if ($modoDesarrollo == "yes") { $url = $preference['response']['sandbox_init_point']; } else { $url = $preference['response']['init_point']; } $order->update_status('pending', "Esperando el pago de la orden"); \CTalaTools\Herramientas::setPostRedirectSimple($url); }