2011-02-06 27 views
6

Estoy usando PayPal Pay API, con pagos adaptativos (encadenados). Estoy tratando de reenviar un usuario a PayPal y luego de regreso a mi return_url predefinido.PayPal AdaptivePayments PaymentDetail PayKey

El problema es: Necesito tener una PayKey dentro de mi URL de devolución. Motivo: necesito llamar a una API PaymentDetail para revisar el pago dentro de la return_url. Y, no quiero usar IPN ya que necesito la validación con algún token en mi Url de devolución.

El problema que tengo es que se está generando la PayKey con todos los parámetros, incluida la URL de retorno (por lo tanto, después de compilar la matriz real de la que obtengo mi respuesta $. No puedo poner PayKey en el retorno Url ya que no es generada en este punto todavía

//Create request payload with minimum required parameters 
    $bodyparams = array ("requestEnvelope.errorLanguage" => "en_US", 
         "actionType" => "PAY", 
         "currencyCode" => "USD", 
         "cancelUrl" => "http://www.paypal.com", 
         "returnUrl" => $return_url . "&payKey=${payKey}", **// Does not work - PAYKEY NEEDED TO ADD???** 
         "receiverList.receiver(0).email" => "[email protected]", //TODO 
         "receiverList.receiver(0).amount" => $price, //TODO 
         "receiverList.receiver(0).primary" => "true", //TODO 
         "receiverList.receiver(1).email" => "[email protected]", //TODO 
         "receiverList.receiver(1).amount" => $receiver_gets, //TODO 
         "receiverList.receiver(1).primary" => "false" //TODO 
         ); 

    // convert payload array into url encoded query string 
    $body_data = http_build_query($bodyparams, "", chr(38)); // Generates body data 

    try 
    { 
    //create request and add headers 
    $params = array("http" => array(
        "method" => "POST", 
        "content" => $body_data, 
        "header" => "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" . 
        "X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" . 
        "X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" . 
        "X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" . 
        "X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" . 
        "X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat . "\r\n" 
        )); 

    //create stream context 
    $ctx = stream_context_create($params); 

    //open the stream and send request 
    $fp = @fopen($url, "r", false, $ctx); 

    //get response 
    $response = stream_get_contents($fp); 

    //check to see if stream is open 
    if ($response === false) { 
     throw new Exception("php error message = " . "$php_errormsg"); 
    } 

    fclose($fp); 

    //parse the ap key from the response 
    $keyArray = explode("&", $response); 

    foreach ($keyArray as $rVal){ 
     list($qKey, $qVal) = explode ("=", $rVal); 
       $kArray[$qKey] = $qVal; 
    } 

    //set url to approve the transaction 
    $payPalURL = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" . $kArray["payKey"]; **// Here it works fine, since the PayKey is generated at this point ...** 

    //print the url to screen for testing purposes 
    If ($kArray["responseEnvelope.ack"] == "Success") { 
     echo '<p><a href="' . $payPalURL . '" target="_blank">' . $payPalURL . '</a></p>'; 
     } 
    else { 
     echo 'ERROR Code: ' . $kArray["error(0).errorId"] . " <br/>"; 
     echo 'ERROR Message: ' . urldecode($kArray["error(0).message"]) . " <br/>"; 
    } 

puede alguien ayudar a

Respuesta

0

Aparentemente se puede incrustar variables dinámicas en el URL de retorno:.? https://www.x.com/thread/49785

Desafortunadamente, {$ payKey} no es válido. t sea $ paykey o $ pay_key. ¡Buena suerte!

3

Parece que te falta un paso en la secuencia.

El primer paso es enviar sus parámetros de transacción a

https://svcs.paypal.com/AdaptivePayments/Pay&yourtransactionparameters=blah [caja de arena] https://svcs.sandbox.paypal.com/AdaptivePayments/Pay & yourtransactionparameters = bla

Obtendrá la paga en esta respuesta.

Una vez que haya recuperado la paykey éxito, se le llama:

https://www.paypal.com/webscr&cmd=_ap-payment&paykey=xxxx [caja de arena] https://www.sandbox.paypal.com/webscr & cmd = _AP-pago & paykey = xxxx

En la segunda llamada, payKey representa el resto de su transacción para que no tenga que crear otra cadena de consulta gigante.

2

cambiar su código para:

//Create request payload with minimum required parameters 
    $bodyparams = array ("requestEnvelope.errorLanguage" => "en_US", 
         "actionType" => "PAY", 
         "currencyCode" => "USD", 
         "cancelUrl" => "http://www.paypal.com", 
         "returnUrl" => $return_url . '&payKey=${payKey}', **// That's right** 
         "receiverList.receiver(0).email" => "[email protected]", //TODO 
         "receiverList.receiver(0).amount" => $price, //TODO 
         "receiverList.receiver(0).primary" => "true", //TODO 
         "receiverList.receiver(1).email" => "[email protected]", //TODO 
         "receiverList.receiver(1).amount" => $receiver_gets, //TODO 
         "receiverList.receiver(1).primary" => "false" //TODO 
         ); 

PHP interpreta $ {} payKey como variable entre las comillas dobles. Cambiar las comillas dobles (") para las comillas simples (')

5

Yo también estuve en esto por mucho tiempo. Finalmente lo descubrí. Los documentos de Paypal son difíciles de seguir. Encontré la respuesta en la guía pdf adaptable de PayPal que he descargado. en él se especifica para agregar payKey=${payKey} hasta el final de su return_url. yo sólo probé allí y el paypal conseguir solicitud a mi url de retorno contiene ahora la paykey.

Así que en raíles que estoy usando el return_url parece esto. Escribir una variable php (creo) en la url como se indica en la guía

:return_url  => "http://***********.com/paypal-return?payKey=${payKey}" 
+0

Eso es realmente simple. Estuve mirando los documentos de IPN de PayPal y lo vi, y pensé que solo tendría que agregarlo a la URL y, por supuesto. Perfecto. –