Paypal付款确认回复无效

时间:2016-11-22 14:12:34

标签: php paypal cakephp-3.0

我需要知道为什么Paypal在进行握手确认付款时会给出“无效状态”。虽然付款正在接收,但一切都很好。

以下代码用于发送请求以进行付款。

$path = "http:/127.0.0.1/acedmy/";
$paypal_email = 'imranguher-seller@hotmail.com';
$return_url = $path .'Packages/success';
$cancel_url = $path .'Packages/cancel';
$notify_url = $path .'Packages/success';

$item = $this->request->data["item_number"];
$itemArray = explode("_", $item);

$payer_email = "imranguher-buy@hotmail.com";

$querystring = '';
$querystring .= "?cmd=".urlencode("_xclick"). "&";
$querystring .= "business=".urlencode($paypal_email). "&";
$querystring .= "payer_email".urlencode($payer_email). "&";
$querystring .= 'currency_code='. urlencode( 'USD'). "&";
$querystring .= "item_name=".urlencode(stripslashes("monthly")). "&";
$querystring .= "amount="."20". "&";
$querystring .= "item_number="."121"."&";
$querystring .= "submit_x=".urlencode(stripslashes($this->request->data['submit_x'])). "&";
$querystring .= "submit_y=".urlencode(stripslashes($this->request->data['submit_y'])). "&";
$querystring .= "return=".urlencode(stripslashes($return_url)). "&";
$querystring .= "cancel_return=".urlencode(stripslashes($cancel_url)). "&";        
$querystring .= "notify_url=".urlencode($notify_url);


header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);      
        exit();

确认付款是否成功且有效的代码。

  $req = 'cmd=_notify-validate';
foreach ($_GET as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

debug($req);
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";


$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
 if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

 $status = "verified";
 debug($status);
// PAYMENT VALIDATED & VERIFIED!

}
else if (strcmp ($res, "INVALID") == 0) {

  $status = "Invalid";
 debug($status);
// PAYMENT INVALID & INVESTIGATE MANUALY!

}
}
fclose ($fp);
}

调试响应后,我得到以下

\src\Controller\PackagesController.php (line 168)
'cmd=_notify-validate&tx=6JS3234156861063R&st=Completed&amt=5.00&cc=USD&cm=&item_number=3_1'
\src\Controller\PackagesController.php (line 192)
'Invalid'

付款成功但仍然出错。

0 个答案:

没有答案