הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   שאלה | PAYPAL (https://hosts.co.il/forums/showthread.php?t=76604)

Hezi & BomBas 14-07-09 14:39

שאלה | PAYPAL
 
היי, אני כרגע בונה מערכת קטנה המשלבת תשלום ישיר באמצעות 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$errstr30);
    
    if ( ! 
$fp )
    {
        
$output 'Error opening PayPal';
    }
    else
    {
        
fputs ($fp$header $req);
        
// Read the body data .
        
$res '';
        
$headerdone false;
        while ( ! 
feof($fp) )
        {
            
$line fgets ($fp1024);
            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") == )
        {
            for (
$i=1$i<count($lines);$i++)
            {
            list(
$key,$val) = explode("="$lines[$i]);
            
$keyarrayurldecode($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".

יאיר 14-07-09 15:02

יש אפשרות בPaypal שלאחר שהלקוח משלם נפתח לו לינק.
פשוט תפתח קובץ שתשים בו המשך לאחר התשלום ואם הוא לא מגיע לקובץ הזה ארור.

Hezi & BomBas 14-07-09 15:08

זה מה שאני עושה. אבל אחרי התשלום המשתמש צריך לקבל קובץ מסויים. אם סתם איש נכנס לכתובת ומקבל את הקובץ, לא עשינו פה כלום. אני צריך לעשות בדיקה שמי שנכנס לכתובת אכן שילם.

Shillo 14-07-09 15:15

ציטוט:

נכתב במקור על ידי Hezi & BomBas (פרסם 727807)
היי, אני כרגע בונה מערכת קטנה המשלבת תשלום ישיר באמצעות 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$errstr30);
    
    if ( ! 
$fp )
    {
        
$output 'Error opening PayPal';
    }
    else
    {
        
fputs ($fp$header $req);
        
// Read the body data .
        
$res '';
        
$headerdone false;
        while ( ! 
feof($fp) )
        {
            
$line fgets ($fp1024);
            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") == )
        {
            for (
$i=1$i<count($lines);$i++)
            {
            list(
$key,$val) = explode("="$lines[$i]);
            
$keyarrayurldecode($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".

כמה דברים בסיסיים שאתה צריך בחשבון שלך:
  1. תוודא שהחשבון פאיפאל שלך הוא Premier, אם הוא לא כזה, יש לך אפשרות לשדרג (חינם)
  2. בחשבון שלך תחת "Profile" תלחץ על Instant Payment Notification ותבדוק אם האפשרות כבויה, אם כן, תאפשר אותה. וישנה תיבת טקסט מתחת שבה אתה צריך להכניס את הדומיין שמשתמש בIPN.

אם עבדת לפי המדריך הזה:
http://net.tutsplus.com/tutorials/ph...tion-with-php/
אז אני מציע לך להתבונן בו שוב, אם לא, אז כדאי לך להיכנס.

בכל מקרה, אם הוא מדפיס לך "error" יכול להיות שפשוט משהו בשלב ההזמנה לא טוב. הקוד שלך מאוד מבולגן וזה דיי קשה או לפחות מתסכל לבדוק אותו.

Hezi & BomBas 14-07-09 15:17

המערכת תימכר ותעבוד על מאות שרתים, אני לא יכול להגדיר את האפשרות רק לדומיין אחד.

אוקיי זה הקוד שלי:
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";

      
//If testing on Sandbox use:
    //$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp fsockopen ('ssl://www.paypal.com'443$errno$errstr30);


if (!
$fp) {
// HTTP ERROR
} else {
fputs ($fp$header $req);
while (!
feof($fp)) {
$res fgets ($fp1024);
if (
strcmp ($res"VERIFIED") == 0) {
// 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


// echo the response
echo "The response from IPN was: <b>" .$res ."</b><br><br>";

//loop through the $_POST array and print all vars to the screen.

foreach($_POST as $key => $value){

        echo 
$key." = "$value."<br>";



}


}
else if (
strcmp ($res"INVALID") == 0) {
// log for manual investigation

// echo the response
echo "The response from IPN was: <b>" .$res ."</b>";

  }

}
fclose ($fp);


אחרי הקנייה זה מדפיס:
The response from IPN was: INVALID

Hezi & BomBas 14-07-09 18:05

פתרתי :) תודה לכולם.


כל הזמנים הם GMT +2. הזמן כעת הוא 10:56.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ