Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/03/2011, 11:04
hugotuxsv
 
Fecha de Ingreso: noviembre-2010
Ubicación: El Salvador
Mensajes: 44
Antigüedad: 14 años, 4 meses
Puntos: 6
Agregar varios productos con paypal class

Hola estoy trabajando con clase paypal que encontre en esta direccion:
http://www.micahcarrick.com/php-paypal-ipn-integration-class.html

y ya la pude integrar a mis pruebas comprando/pagando un solo articulo, el problema me viene cuando quiero agregar mas de un articulo, no lo logro hacer.

Este es el codigo de mi clase:
Código PHP:
<?php
require_once('paypal.class.php');  // include the class file
$dir_sandbox='https://www.sandbox.paypal.com/cgi-bin/webscr'// testing paypal url
$dir='https://www.paypal.com/cgi-bin/webscr';
$p = new paypal_class;             // initiate an instance of the class
$p->paypal_url $dir_sandbox;

            
// setup a variable for this script (ie: 'http://www.micahcarrick.com/paypal.php')
$this_script 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

// if there is not action variable, set the default action of 'process'
if (empty($_GET['action'])) $_GET['action'] = 'process';  

switch (
$_GET['action']) {
    
   case 
'process':      // Process and order...     

      
$p->add_field('business''[email protected]');
      
$p->add_field('return'$this_script.'?action=success');
      
$p->add_field('cancel_return'$this_script.'?action=cancel');
      
$p->add_field('notify_url'$this_script.'?action=ipn');
      
$p->add_field('item_name''prueba de pago');
      
$p->add_field('amount''2.00');
      
$p->add_field('currency_code''EUR');
      
$p->add_field('quantity''2');
      
$p->add_field('item_number''001');
            
            
      
$p->submit_paypal_post(); // submit the fields to paypal
      //$p->dump_fields();      // for debugging, output a table of all the fields
      
break;
      
   case 
'success':      // Order was successful...
   
      // This is where you would probably want to thank the user for their order
      // or what have you.  The order information at this point is in POST 
      // variables.  However, you don't want to "process" the order until you
      // get validation from the IPN.  That's where you would have the code to
      // email an admin, update the database with payment status, activate a
      // membership, etc.  
 
      
echo "<html><head><title>Success</title></head><body><h3>Thank you for your order.</h3>";
            foreach (
$_POST as $key => $value) {
                echo 
"$key: $value<br>";
            }
      echo 
"</body></html>";
      
      
// You could also simply re-direct them to another page, or your own 
      // order status page which presents the user with the status of their
      // order based on a database (which can be modified with the IPN code 
      // below).
      
      
break;
      
   case 
'cancel':       // Order was canceled...

      // The order was canceled before being completed.
 
      
echo "<html><head><title>Canceled</title></head><body><h3>The order was canceled.</h3>";
      echo 
"</body></html>";
      
      break;
      
   case 
'ipn':          // Paypal is calling page for IPN validation...
   
      // It's important to remember that paypal calling this script.  There
      // is no output here.  This is where you validate the IPN data and if it's
      // valid, update your database to signify that the user has payed.  If
      // you try and use an echo or printf function here it's not going to do you
      // a bit of good.  This is on the "backend".  That is why, by default, the
      // class logs all IPN data to a text file.
      
      
if ($p->validate_ipn()) {
          
         
// Payment has been recieved and IPN is verified.  This is where you
         // update your database to activate or process the order, or setup
         // the database with the user's order details, email an administrator,
         // etc.  You can access a slew of information via the ipn_data() array.
  
         // Check the paypal documentation for specifics on what information
         // is available in the IPN POST variables.  Basically, all the POST vars
         // which paypal sends, which we send back for validation, are now stored
         // in the ipn_data() array.
         
         
                         
$user="user";
                 
$servidor="localhost";
                 
$pass="pass";
                 
$db="db";

                 
$connection=mysql_connect ($servidor$user$pass);
                    if (!
$connection) {
                        die(
'Not connected : ' mysql_error());
                    }

                    
// Set the active mySQL database
                    
$db_selected mysql_select_db($db$connection);
                    if (!
$db_selected) {
                        die (
'Can\'t use db : ' mysql_error());
                    }

                    if(
mysql_query("insert into pagado (id,pagado) values(0,0)")){
                        echo 
"exito";
                    }else{
                        echo 
"error";
                    }

      }        
      break;
 }     

?>