NLT Posted June 7, 2011 Share Posted June 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/ Share on other sites More sharing options...
gristoi Posted June 7, 2011 Share Posted June 7, 2011 your first problem is with an extra ) on this line: $payer_email = $_POST['payer_email'] -> ) <- ; Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226483 Share on other sites More sharing options...
NLT Posted June 7, 2011 Author Share Posted June 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226484 Share on other sites More sharing options...
gristoi Posted June 7, 2011 Share Posted June 7, 2011 are you using any kind of session variables? Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226486 Share on other sites More sharing options...
NLT Posted June 7, 2011 Author Share Posted June 7, 2011 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226491 Share on other sites More sharing options...
gristoi Posted June 7, 2011 Share Posted June 7, 2011 mysql_query("UPDATE users SET rank = '2' WHERE username='$username'"); Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226492 Share on other sites More sharing options...
NLT Posted June 7, 2011 Author Share Posted June 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226495 Share on other sites More sharing options...
gristoi Posted June 7, 2011 Share Posted June 7, 2011 always best to refer to the paypal api is your unsure: https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_reference Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226496 Share on other sites More sharing options...
NLT Posted June 7, 2011 Author Share Posted June 7, 2011 always best to refer to the paypal api is your unsure: https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_reference Okay, I think that's it. Thanks to everyone who helped. Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226497 Share on other sites More sharing options...
NLT Posted June 7, 2011 Author Share Posted June 7, 2011 Delete this post. Solved. Quote Link to comment https://forums.phpfreaks.com/topic/238668-paypal/#findComment-1226500 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.