本文整理汇总了PHP中MP::create_preference方法的典型用法代码示例。如果您正苦于以下问题:PHP MP::create_preference方法的具体用法?PHP MP::create_preference怎么用?PHP MP::create_preference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MP
的用法示例。
在下文中一共展示了MP::create_preference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gmp_link
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;
}
示例2: postPago
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;
}
示例3: pay
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);
}
示例4: button
/**
* 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 '';
}
示例5: pago
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();
}
示例6: MP_link_button
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>";
}
示例7: probandoMP
function probandoMP()
{
$sessionid = "1234567890";
$payer = array("name" => "Cristian ", "surname" => "Tala S.", "email" => "naito.neko@gmail.com", "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;
}
示例8: carrental_confirm_reservation
//.........这里部分代码省略.........
} 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;
}
示例9: function_mercado_pago
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') {
//.........这里部分代码省略.........
示例10: isset
?>
</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
示例11: MP
<?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>";
}
?>
示例12: index
//.........这里部分代码省略.........
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();
}
示例13: index
//.........这里部分代码省略.........
$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);
}
}
示例14: get_mercadopago
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);
}
示例15: hookPaymentReturn
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;})();}
//.........这里部分代码省略.........