Hola, necesito cargar dinámicamente el precio en el código del botón de pago de mercado pago pero me da error, alguien me ayuda? El código PHP que uso es este:
<?php
session_start();
require_once ('/home/ei000127/public_html/mercadopago.php');
$mp = new MP('6932340610692472', 'vBZfcw864fqCgc2pFA3AOu5ool5pvFfq');
$cantidad=0;
foreach ($_SESSION["carrito"] as $carrito) {
$total+=$carrito['precio'];
$cantidad=$cantidad+1;
}
$preference_data = array(
"items" => array(
array(
"title" => "Barrilete multicolor",
"quantity" => $cantidad,
"currency_id" => "ARS",
"unit_price" => $total
)
),
"back_urls" => array(
'success' => 'http://todoaudiolibros.com/aprobado.php',
'pending' => 'http://todoaudiolibros.com/pendiente.php'
),
"payer" => array(
'name' => $_SESSION['nombre'],
'email' => $_SESSION['email']
)
);
$preference = $mp->create_preference($preference_data);
header("Location: ".$preference['response']['sandbox_init_point']);
?>
Gracias!
<?php
session_start();
require_once ('/home/ei000127/public_html/mercadopago.php');
$mp = new MP('6932340610692472', 'vBZfcw864fqCgc2pFA3AOu5ool5pvFfq');
$cantidad=0;
foreach ($_SESSION["carrito"] as $carrito) {
$total+=$carrito['precio'];
$cantidad=$cantidad+1;
}
$preference_data = array(
"items" => array(
array(
"title" => "Barrilete multicolor",
"quantity" => $cantidad,
"currency_id" => "ARS",
"unit_price" => $total
)
),
"back_urls" => array(
'success' => 'http://todoaudiolibros.com/aprobado.php',
'pending' => 'http://todoaudiolibros.com/pendiente.php'
),
"payer" => array(
'name' => $_SESSION['nombre'],
'email' => $_SESSION['email']
)
);
$preference = $mp->create_preference($preference_data);
header("Location: ".$preference['response']['sandbox_init_point']);
?>
Gracias!