开发者

Really confused about paypal payments

开发者 https://www.devze.com 2023-02-23 03:50 出处:网络
UPDATE 1: Writing $res to a textfile just returns the word VERIFIED: <?php /* mysql_connect(\"localhost\", \"user\", \"password\") or die(mysql_error());

UPDATE 1:

Writing $res to a textfile just returns the word VERIFIED:

<?php  
/*  
mysql_connect("localhost", "user", "password") or die(mysql_error());  
mysql_select_db("PayPal") or die(mysql_error());  
*/

// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
$value = urlencode(stripslashes($value));  
$req .= "&$key=$value";  
}  
// 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.sandbox.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) {  

$ourFileName = "payment开发者_JAVA百科_successful.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $res);
fclose($ourFileHandle);


}  

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

$ourFileName = "payment_failed.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $res);
fclose($ourFileHandle);

}  
}  
fclose ($fp);  
}  
?> 

ORIGINAL QUESTION:

I have the following IPN (Instant Payment Notification) script, which works, i.e. it creates a successful file if successful and a failed file if failed.

Does paypal return post values to the IPN file so I can figure out which payment was successful or which payment has failed?

If yes, how do I access these values?

If no, how do I figure out which payment has been accepted or declined?

This is the script in the IPN file I currently have:

<?php  
// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
$value = urlencode(stripslashes($value));  
$req .= "&$key=$value";  
}  
// 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.sandbox.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) {  

$ourFileName = "payment_successful.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

}  

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

$ourFileName = "payment_failed.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

}  
}  
fclose ($fp);  
}  
?>  


You have the answer in your generic script.

Paypal will return the word VERIFIED or INVALID in the string.

($res, "VERIFIED") == 0

A good trick is to write the value of $res to your log and you will see the returned result right at the end.

Make sure you use the sandbox for testing as well.

Also there is a forum at http://x.com (how much did they pay for THAT domain?)

FWIW, Paypal's IPN is a PITA.


hi i implemented mine this way

foreach ($_POST as $key => $value)
{
    $data[$key] = $value;
}

doing a echo '<pre>'.print_r($data,true).'</pre>';

would produce something like this :

cmd=_notify-validate
test_ipn=1
payment_type=echeck
payment_date=22:21:28 Mar 24, 2011 PDT
payment_status=Completed
address_status=confirmed
payer_status=verified
first_name=John
last_name=Smith
payer_email=buyer@paypalsandbox.com
payer_id=TESTBUYERID01
address_name=John+Smith
address_country=United+States
address_country_code=US
address_zip=95131
address_state=CA
address_city=San+Jose
address_street=123%2C+any+street
business=seller@paypalsandbox.com
receiver_email=seller@paypalsandbox.com
receiver_id=TESTSELLERID1
residence_country=US
item_name=something
item_number=AK-1234
quantity=1
shipping=3.04
tax=2.02
mc_currency=USD
mc_fee=0.44
mc_gross=12.34
txn_type=web_accept
txn_id=28325521
notify_version=2.1
custom=xyz123
invoice=abc1234
charset=windows-1252
verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AM3F5ODR-2hb2fIsWPHepIEPzAwg
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号