我正在使用PHP MercadoPago SDK 模块。这是我的代码:
$mp = new MP("CLIENT_ID", "CLIENT_SCRET");
foreach ($_SESSION["carrito"] as $value){
$itemCode = $value['tagme'];
$itemDesc = get_pedido($itemCode);
$itemQty = $value['cant']; // it comes from $_POST['cant']
$unitPrice = $value['unit_price'];
$items[] = array(
"title" => $itemDesc,
"quantity" => $itemQty,
"currency_id" => "ARS",
"unit_price" => $unitPrice
);
}
$preference = array(
"items" => $items,
"payer" => array(
'name' => $name,
'email' => $email
),
"back_urls" => array(
'success' => 'http://example.com/success.php',
'pending' => 'http://example.com/pending.php'
)
);
echo '<pre>';print_r($items); echo '</pre>';
$mp->sandbox_mode(TRUE);
$preferenceResult = $mp->create_preference($preference);
$items
输出如下:
Array
(
[0] => Array
(
[title] => Test Product
[quantity] => 1
[currency_id] => ARS
[unit_price] => 36
)
[1] => Array
(
[title] => Shipping Cost
[quantity] => 1
[currency_id] => ARS
[unit_price] => 42
)
)
但我收到以下错误:
致命错误:在 /home/..../public_html/mercadopago-sdk/mercadopago.php:227 中带有消息“数量必须是数字”的未捕获异常“异常” :227 堆栈跟踪:#0 /home/..../ public_html/mercadopago-sdk/mercadopago.php(240): MPRESTClient::exec('POST', '/checkout/prefe...', Array, 'application/jso...') #1 /home/.. ../public_html/mercadopago-sdk/mercadopago.php(126): MPRESTClient::post('/checkout/prefe...', Array) #2 /home/../public_html/confirm.php(140 ): MP->create_preference(Array) #3 {main} 在第 227 行的 /home/..../public_html/mercadopago-sdk/mercadopago.php 中抛出
任何想法?