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
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. –