简体   繁体   English

PHP PayPal API更改

[英]PHP PayPal API changes

I was using PHP code (below) but stopped to work. 我使用PHP代码(下面)但停止工作。 Did Paypal changed something about. Paypal改变了一些事情。 It does not work anylonger. 它不再有效。

print_r($res) gives this: print_r($ res)给出了这个:

Invalid URL The requested URL "[no URL]", is invalid. 无效的网址请求的网址“[无网址]”无效。 Reference #9.67ac1002.1539939948.1d3bb0b6 参考编号#9.67ac1002.1539939948.1d3bb0b6

The payment to Paypal works OK, Paypal returns to successfull page URL OK. 付款到Paypal工作正常,Paypal返回成功的页面网址确定。

 <?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];

$auth_token = "my_very_long_token_goes_here";

$req .= "&tx;=$tx_token&at;=$auth_token";


// 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 ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

// parse the data
$lines = explode("\n", $res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$itemname = $keyarray['item_name'];
$amount = $keyarray['mc_gross'];

echo ("
Thank you for your purchase!

");


echo ("Payment Details

\n");

echo ("<li>Name: $firstname $lastname</li>\n");

echo ("<li>Item: $itemname</li>\n");

echo ("<li>Amount: $amount</li>\n");

echo ("");

}

else if (strcmp ($lines[0], "FAIL") == 0) {

// log for manual investigation

}


}


fclose ($fp);


?>

add a host header 添加主机头

$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

on about september 7th, paypal moved their api behind akamai cdn, which requires a host header, but didn't tell anyone about it nor update all of their documentation. 在大约9月7日,paypal将他们的api移到了akamai cdn后面,这需要一个主机头,但没有告诉任何人有关它,也没有更新他们的所有文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM