Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/07/2013, 13:19
mandygr87
 
Fecha de Ingreso: abril-2013
Mensajes: 82
Antigüedad: 11 años
Puntos: 0
Respuesta: Paypal en zend

Gracias por la ayuda,había dejado este tema de lado y ahora lo estoy retomando.

He intentado implementarlo y lo he hecho de esta forma:
En la vista dónde se va a pagar tengo el siguiente formulario de paypal:

Para reservar pulse en el botón de paypal
Código PHP:
                    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
                    <!-- Identify your business so that you can collect the payments. -->
                    <input type="hidden" name="business" value="[email protected]">
                    <!-- Specify a Buy Now button. -->
                    <input type="hidden" name="cmd" value="_xclick">
                    <!-- Specify details about the item that buyers will purchase. -->
                    <input type="hidden" name="item_name" value="Reserva Parcela">
                    <!-- Identificador de la reserva   -->
                    <input type='hidden' name="item_number" value="<?php echo $this->idreserva ?>">
                    <input type="hidden" name="amount" value="<?php echo $this->preciototal*0.15 ?>">
                    <input type="hidden" name="currency_code" value="EUR">
                    <input type="hidden" name="rm" value="2">
                    <input type="hidden" name="notify_url" value="http://localhost/asociacion/public/cliente/paypalipn">
                    <input type="hidden" name="custom" value="12;10">
                    <input type="hidden" name="return" value="http://localhost/asociacion/public/cliente/paypalipn">
                    <!-- Display the payment button. -->
                    <input type="image" name="submit" border="0"
                    src="http://www.paypal.com/es_ES/i/btn/x-click-but01.gif"
                    alt="PayPal - The safer, easier way to pay online">
                    <img alt="" border="0" width="1" height="1"
                    src="https://www.paypal.com/en_US/i/scr/pixel.gif" >
                    </form>
Y en mi Controlador Cliente tengo el action paypalipn con el siguiente código:

Código PHP:
$payaltest true//cambialo a false para realizar transacciones reales, de lo contrario utiliza sandbox.

        
$req 'cmd=_notify-validate';
        
$fullipnA = array();

        foreach (
$_POST as $key => $value) {
            
$fullipnA[$key] = $value;

            
$encodedvalue urlencode(stripslashes($value));
            
$req .= "&$key=$encodedvalue";
        }

        
$fullipn $this->Array2Str(" : ""\n"$fullipnA);

        if (!
$payaltest) {
            
$url 'https://www.paypal.com/cgi-bin/webscr';
        } else {

            
$url 'https://www.sandbox.paypal.com/cgi-bin/webscr';
        }

        
$client = new Zend_Http_Client($url);
        
$client->setMethod(Zend_Http_Client::POST);
        
$client->setParameterPost(array('cmd' => '_notify-validate')+$_POST);
        
$response $client->request();

 
// Variables enviadas por Paypal
        
$item_name $_POST['item_name'];
        
$item_number $_POST['item_number'];
        
$payment_status $_POST['payment_status'];
        
$payment_amount $_POST['mc_gross'];
        
$payment_currency $_POST['mc_currency'];
        
$txn_id $_POST['txn_id'];
        
$receiver_email $_POST['receiver_email'];
        
$payer_email $_POST['payer_email'];
        
$txn_type $_POST['txn_type'];
        
$pending_reason $_POST['pending_reason'];
        
$payment_type $_POST['payment_type'];
        
$custom_key $_POST['custom'];

        if (
//$response->getBody() !== 'VERIFIED'
        
strcmp ($response"VERIFIED") == 0) {
            
//Not verified
             //la transacción es invalida NO se pudo cobrarle al cliente.
            
$this->TransLog("Pago Inválido - $fullipn");
            
//die("FAIL");
            
}else{
                
// Verifico el estado de la orden
        
if ($payment_status != "Completed") {
            
$this->TransLog("El pago no fue aceptado por paypal - Estado del Pago: $payment_status");
            
$this->StopProcess();
        }

        
//todo bien hasta ahora, la transacción ha sido confirmada por lo tanto puedo realizar mis tareas,
        //actualizar DB, stock, acreditar cómputos, activar cuentas etc etc


        
$this->TransLog("Pago Correcto - $fullipn"); //notifico al webmaster

        
$reserva = new Application_Model_DbTable_Reserva();
        
$estado "Reservado";
        
$reserva->validarreserva($item_number$estado$payment_amount);

            } 
Me gustaría que me confirmaseis si se realiza de esta manera, que por lo que he estado leyendo creo que sí.


Otra cosa, estoy realizándolo en localhost, he leído que no hace el retorno automático cuando estas en localhost.
Si lo tengo en un servidor haciéndolo de la misma forma sí que lo haría o tendría que hacer algún cambio??

Gracias por vuestra ayuda.