0
I am working with paid market documentation, where I have a new instance/object for each product called item. Each item has to be passed to the preference->items instance where the preference->save() method will save and send a POST when I click the pay ML button. What I’m trying to do is this
- I have a form with 3 inputs of type Submit.
- Each input has an Hidden property and a value that corresponds to the product value
- When the user clicks on Ubmit, which would be the same as adding to the cart, I want to take the instance/object called item and pass inside the preference->items array.
The way I’m trying is this:
<?php
$preference = new MercadoPago\Preference();
// Cria um item na preferência
$item = new MercadoPago\Item();
$item->title = 'Produto 1';
$item->quantity = 1;
$item->unit_price = 23.00;
$item2 = new MercadoPago\Item();
$item2->title = 'Produto 2';
$item2->quantity = 1;
$item2->unit_price = 10.00;
$item3 = new MercadoPago\Item();
$item3->title = 'Produto 3';
$item3->quantity = 1;
$item3->unit_price = 1.99;
openssl_get_cert_locations();
if (isset($_POST['produto1'])) {
$preference->items = array($item);
$preference->save();
}
if (isset($_POST['produto2'])) {
$preference->items = array($item2);
$preference->save();
}
if (isset($_POST['produto3'])) {
$preference->items = array($item3);
$preference->save();
}
?>
As it is necessary to make use of some certifying SSL I am running this page on a free host, in case this link: https://max360vision.000webhostapp.com/playground.php
<form action="" method="POST">
<p> Produto: <input type="text" name="produto1" hidden></p>
<input type="submit" name="submit" value="submit">
<p> Produto 2: <input type="text" name="produto2" hidden></p>
<input type="submit" name="submit2" value="submit2">
<p> Produto 3: <input type="text" name="produto3" hidden></p>
<input type="submit" name="submit3" value="submit3">
</form>
<form action="/processar_pagamento" method="POST">
<script src="https://www.mercadopago.com.br/integrations/v1/web-payment-checkout.js" data-preference-id="<?php echo $preference->id; ?>">
</script>
</form>
The error that occurs to me as I am currently trying is the following: Every time I give Submit on any product, it sends 2 notices from the manager class that already comes with the market SDK
Free Notice: Undefined index: Metadata in /Storage/ssd3/656/11276656/public_html/vendor/mercadopago/dx-php/src/Mercadopago/Manager.php on line 336
Notice: Undefined index: Metadata in /Storage/ssd3/656/11276656/public_html/vendor/mercadopago/dx-php/src/Mercadopago/Manager.php on line 336
And when I click pay it redirects to pay for item 3, even if I click item 1, or 2.