ציטוט:
נכתב במקור על ידי Hezi & BomBas
היי, אני כרגע בונה מערכת קטנה המשלבת תשלום ישיר באמצעות PAYPAL.
את התשלום כבר בניתי והכל בסדר, הגדרתי גם כתובת חזרה לאחר התשלום. השאלה שלי - איך אני מוודא שהמשתמש אכן שילם ולא סתם נכנס לכתובת המתבקשת? תודה.
זה הקוד שלי:
PHP קוד:
require "config.php";
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$req .= "&tx=$tx_token";
// post back to PayPal system to validate the payment.
$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.paypal.com', 80, $errno, $errstr, 30);
if ( ! $fp )
{
$output = 'Error opening PayPal';
}
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)
{
$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 if the payment_status has been Completed.
// check that the receiver_email is your Primary PayPal email.
// check that payment_amount/payment_currency are correct.
// Process payment.
$output = $_GET['item_name'];
}
else
{
$output = 'error';
}
}
print $output;
אחרי הקנייה הוא מדפיס "error".
|
כמה דברים בסיסיים שאתה צריך בחשבון שלך:
- תוודא שהחשבון פאיפאל שלך הוא Premier, אם הוא לא כזה, יש לך אפשרות לשדרג (חינם)
- בחשבון שלך תחת "Profile" תלחץ על Instant Payment Notification ותבדוק אם האפשרות כבויה, אם כן, תאפשר אותה. וישנה תיבת טקסט מתחת שבה אתה צריך להכניס את הדומיין שמשתמש בIPN.
אם עבדת לפי המדריך הזה:
http://net.tutsplus.com/tutorials/ph...tion-with-php/
אז אני מציע לך להתבונן בו שוב, אם לא, אז כדאי לך להיכנס.
בכל מקרה, אם הוא מדפיס לך "error" יכול להיות שפשוט משהו בשלב ההזמנה לא טוב. הקוד שלך מאוד מבולגן וזה דיי קשה או לפחות מתסכל לבדוק אותו.