shopping cart pagseguro

1

How do I make a payment to get all the products added to my checkout and pass it to the payer? It's just passing 1 product does not catch everyone who is in my checkout how can I do this?

php code:

 if(count($_SESSION['carrinho']) == 0){

                        echo '<tr><td colspan="5">Não há produto no carrinho</td></tr>';
                     }else{
                        require("conexao.php");
                        $a = new Conexao();
                        $a->conecta();
                                                               $total = 0;
                        foreach($_SESSION['carrinho'] as $id => $qtd){
                              $sql   = "SELECT *  FROM produtos WHERE id_produto= '$id'";
                              $qr    = mysql_query($sql) or die(mysql_error());
                              $ln    = mysql_fetch_assoc($qr);

                              $nome  = $ln['nome'];
                              $preco = $ln['preco'];
                              $sub   = $ln['preco'] * $qtd;
                              $img   = $ln['img'];
                              $desc  = $ln['descricao'];
                              $id    = $ln['id_produto']; 
                              $total += $ln['preco'] * $qtd;

                              print"
                        <tr>

                            <td class=\"cart_product\">
                                <a href=\"\"><img src=\"images/shop/$img\" alt=\"\" width=\"100px\" height=\"100px\"></a>
                            </td>
                            <td class=\"cart_description\">
                                <h4><a href=\"\">$nome</a></h4>

                            </td>
                            <td class=\"cart_price\">
                                <p>R$ $preco</p>
                            </td>
                            <td class=\"cart_quantity\">
                                <div class=\"cart_quantity_button\">

                                    <input class=\"cart_quantity_input\" type=\"text\" name=\"prod['$id']\" value=\"$qtd\" autocomplete=\"off\" size=\"2\">

                                </div>
                            </td>
                            <td class=\"cart_total\">
                                <p class=\"cart_total_price\">R$ $sub</p>
                            </td>
                            <td class=\"cart_delete\">
                                <a class=\"cart_quantity_delete\" href=\"?acao=del&id=$id\"><i class=\"fa fa-times\"></i></a>
                            </td>
                        </tr>";
                    }
                    $total = number_format($total, 2, ',', '.');
                           echo '<tr>
                                    <td colspan="4" class="cart_price">Total</td>
                                    <td>R$ '.$total.'</td>
                              </tr>';
                }

part of the payroll form:

<form target="pagseguro" method="post" action="https://pagseguro.uol.com.br/checkout/checkout.jhtml">
          <input type="hidden" name="email_cobranca" value="[email protected]">
          <input type="hidden" name="tipo" value="CP">
          <input type="hidden" name="moeda" value="BRL">

          <input type="hidden" name="item_id_1" value="<?php echo $id; ?>">
          <input type="hidden" name="item_descr_1" value="<?php echo $nome; ?>">
          <input type="hidden" name="item_quant_1" value="1">
          <input type="hidden" name="item_valor_1" value="<?php echo $total; ?>">
          <input type="hidden" name="item_frete_1" value="0">
          <input type="hidden" name="item_peso_1" value="1000">
          <input type="submit" class="btn btn-default check_out" value="Finalizar Compra">
        </form>
    
asked by anonymous 19.11.2015 / 02:47

1 answer

2

The ideal in these cases is to use the secure paging api for php ( Documentation here ).

Inside it we can add the products as follows:

$paymentRequest = new PagSeguroPaymentRequest();  
$paymentRequest->addItem('0001', 'Notebook', 1, 2430.00);  
$paymentRequest->addItem('0002', 'Mochila',  1, 150.99);  
...

What would fit perfectly within your product loop and would directly generate a payment url to forward to your user.

It's worth a look.

    
19.11.2015 / 02:58