Jump to content

PayPal


NLT

Recommended Posts

Hello.

 

I'm experiencing problems with PayPal IPN.

Firstly, I'm getting this error:

"Parse error: syntax error, unexpected ')' in /home/nathanlo/public_html/index.php on line 37" (I'll post the code on the bottom)

 

Once I fixed that error, I need the code to get the username or the userid from the database. So if the payment is successful, it can change their rank to rank 2.

I'm hoping someone can help me with this, thanks.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="X7GR9QDVHZQPJ">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>


<?php
define('USERNAME_REQUIRED', TRUE);
define('ACCOUNT_REQUIRED', TRUE);

function write2LogFile( $message, $file = "mylog.txt" ) { $file = fopen($file, "a"); fputs($file, "[".date('d-m-Y')."] ".$message."\n"); fclose($file); }
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
}
$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) {
        write2LogFile( "ERROR Can not connect to paypal!" );
}
else
{
        fputs ($fp, $header . $req);
        while (!feof($fp))
        {
                $res = fgets ($fp, 1024);
                if (strcmp ($res, "VERIFIED") == 0)
                {
                        $payment_status = $_POST['payment_status'];
                        $transaction_id = $_POST['txn_id'];
                        $payer_email    = $_POST['payer_email'] );
                        $custom_field   = $_POST['custom'];

                        if ( $payment_status == 'Completed' )
                        {                      
                                // Make him VIP (Rank 2)
                        }
                        else if ( $payment_status == 'Canceled_Reversal' )
                        {
                                // Ban the account
                        }
                }
        }
        fclose ($fp);
}
?>

P.S.I'm sorry for the little issue I had with another user on here.

Link to comment
Share on other sites

Ahh. Now the error is fixed xD.

Now I need to like somehow find the ID of the user logged in, and use it to update.

 

mysql_query("UPDATE users SET rank = '2'

WHERE username='_'");

 

I think you know what I mean.

 

Edit: I know I'll need to add the database connection and things

Edit2: I did a bit of research, and I found this: "Customer/Player visits your web-site and clicks donate button. Now you can add custom field to button code with name "custom" and then in that hidden input variable you can put user id, or his character id, or whatever you want. Example below...

<input type="hidden" name="custom" value="XXX">  

I don't know if that'll help you or whatever, just trying to help too.

 

Link to comment
Share on other sites

I was about to edit my post. I've added this to the script:

include('global.php');
define("THIS_SCRIPT", 'buy');
if(isset($_GET['u']))
{
$username = $core->EscapeString($_GET['u']);
}
else
{
$username = $core->EscapeString($_SESSION['username']);
}

 

 

I'm not sure how to include it in the query though.

 

And now I'm getting this error: Fatal error: Call to a member function EscapeString() on a non-object in /home/nathanlo/public_html/index.php on line 20

 

Full code:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="X7GR9QDVHZQPJ">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>


<?php
define('USERNAME_REQUIRED', TRUE);
define('ACCOUNT_REQUIRED', TRUE);
include('global.php');
define("THIS_SCRIPT", 'buy');
if(isset($_GET['u']))
{
$username = $core->EscapeString($_GET['u']);
}
else
{
$username = $core->EscapeString($_SESSION['username']);
}


function write2LogFile( $message, $file = "mylog.txt" ) { $file = fopen($file, "a"); fputs($file, "[".date('d-m-Y')."] ".$message."\n"); fclose($file); }
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
}
$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) {
        write2LogFile( "ERROR Can not connect to paypal!" );
}
else
{
        fputs ($fp, $header . $req);
        while (!feof($fp))
        {
                $res = fgets ($fp, 1024);
                if (strcmp ($res, "VERIFIED") == 0)
                {
                        $payment_status = $_POST['payment_status'];
                        $transaction_id = $_POST['txn_id'];
                        $payer_email    = $_POST['payer_email'];
                        $custom_field   = $_POST['custom'];

                        if ( $payment_status == 'Completed' )
                        {                      
                                // Make him VIP (Rank 2)
                        }
                        else if ( $payment_status == 'Canceled_Reversal' )
                        {
                                // Ban the account
                        }
                }
        }
        fclose ($fp);
}
?>

Link to comment
Share on other sites

mysql_query("UPDATE users SET rank = '2' WHERE username='$username'");

 

If I add that, the code is complete really. It'll update them if PayPal says it's successful etc, right?

Just want to make sure if it's anything else I need to add.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.