Sve*_*uem 6 php paypal paypal-adaptive-payments
我正在使用PayPal Pay API,具有自适应(链式)付款.我试图将用户转发到paypal,然后回到我预定义的return_url.
问题是:我需要在return-url中有一个PayKey.原因是:我需要调用PaymentDetail API来审核return_url中的付款.并且,我不想使用IPN,因为我需要在返回的Url上使用某些令牌进行验证.
我遇到的问题是:PayKey正在使用所有参数生成,包括return-url(因此在我构建实际数组之后,我从中得到我的$响应.我不能将PayKey放在return-Url中因为此时尚未生成.
//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" => "account1@hotmail.com", //TODO
"receiverList.receiver(0).amount" => $price, //TODO
"receiverList.receiver(0).primary" => "true", //TODO
"receiverList.receiver(1).email" => "account2@hotmail.com", //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/>";
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我自己也在这个时代.我终于弄明白了.Paypal文档很难遵循.我在下载的paypal自适应pdf指南中找到了答案.它指定添加 payKey=${payKey}到您的结尾return_url.我只是在那里尝试过,paypal获取请求到我的返回URL现在包含paykey.
所以在我正在使用的rails中return_url看起来像这样.按照指南的指示将php变量(我认为)写入url
:return_url => "http://***********.com/paypal-return?payKey=${payKey}"
Run Code Online (Sandbox Code Playgroud)
小智 0
显然,您可以在返回 URL 中嵌入动态变量: https: //www.x.com/thread/49785
不幸的是,{$payKey} 无效。所以它必须是 $paykey 或 $pay_key。祝你好运!
| 归档时间: |
|
| 查看次数: |
3930 次 |
| 最近记录: |