easehispain Posted January 30, 2011 Share Posted January 30, 2011 Hello Everyone, I am pretty new to the forums and was curious if i could get some help here. Basically, in a nutshell, i have PayPal integrated into my website. I will use this to collect money from clients. when a client logs into his/her account they see their balance (which is pulled from the database to correspond with the user that's logged-in). Now, everytime a payment is submitted a notify_url is contacted after payment has been verified, that notify_url is the code written below. What I am trying to execute here is when this notify_url is called the current balance is reduced from the amount paid through paypal. In the second If condition, you will see that the word success is being entered into the paypal.txt file, which is working perfectly fine. Now, you will also see the variable $update_balance; which is suppose to update the original balance with the balance paid through PayPal BUT IT'S NOT!! WHY?? LOL Thank You in advance! <?php ob_start(); session_start(); include_once ('/home/rdewebde/public_html/includes/paypal.php'); $myPaypal = new Paypal(); $myPaypal->ipnLog = TRUE; include_once "/home/rdewebde/public_html/includes/_config.php"; $username = "".$_SESSION['username'].""; $users_data = mysql_query("SELECT * FROM `members` WHERE `username`='".$username."'"); $user_info = mysql_fetch_array($users_data); $current_amount = $user_info['balance']; $deduct_amount = $myPaypal->ipnData['payment_gross']; $new_amount = $current_amount - $deduct_amount; $update_balance = mysql_query("UPDATE `members` SET `balance` = '$new_amount' WHERE `username` = '".$username."'"); if ($myPaypal->validateIpn()) { if ($myPaypal->ipnData['payment_status'] == 'Completed') { $update_balance; file_put_contents('/home/rdewebde/public_html/lounge/paypal.txt', 'SUCCESS'); } else { file_put_contents('/home/rdewebde/public_html/lounge/paypal.txt', "FAILURE\n\n" . $myPaypal->ipnData); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226093-having-trouble-updating-a-variable-to-database-paypal-integration/ Share on other sites More sharing options...
BlueSkyIS Posted January 30, 2011 Share Posted January 30, 2011 is the update query running at all? Quote Link to comment https://forums.phpfreaks.com/topic/226093-having-trouble-updating-a-variable-to-database-paypal-integration/#findComment-1167147 Share on other sites More sharing options...
easehispain Posted January 30, 2011 Author Share Posted January 30, 2011 yeah its weird, i tested it by changing the variable $deduct_amount to an integer of 0.01 and echoed variable $new_amount and this worked, everytime i refreshed the page the amount was reduced by one penny and i can stick the ipn data of payment_gross into paypal.txt too, but it doesnt want to work the way i want it to Quote Link to comment https://forums.phpfreaks.com/topic/226093-having-trouble-updating-a-variable-to-database-paypal-integration/#findComment-1167155 Share on other sites More sharing options...
PFMaBiSmAd Posted January 30, 2011 Share Posted January 30, 2011 What paypal class are you using? Either post a link to the Author's site or post the script. Your program logic is out of order. You have a bunch of logic before the if ($myPaypal->validateIpn()) { statement. All the logic that attempts to access any of the ipn data should be inside the conditional that has tested if the payment_status is 'Completed'. I'm going to guess that none of the $myPaypal->ipnData values exist until after you call $myPaypal->validateIpn(). Quote Link to comment https://forums.phpfreaks.com/topic/226093-having-trouble-updating-a-variable-to-database-paypal-integration/#findComment-1167285 Share on other sites More sharing options...
easehispain Posted January 30, 2011 Author Share Posted January 30, 2011 well its weird cause this script, you can enabler test mode which goes through paypal sandbox, when i have this enabled, it works, but in real mode, it doesnt heres my revised code <?php ob_start(); session_start(); include_once ('/home/rdewebde/public_html/includes/paypal.php'); include_once "/home/rdewebde/public_html/includes/header.php"; $myPaypal = new Paypal(); $myPaypal->ipnLog = TRUE; include_once "/home/rdewebde/public_html/includes/_config.php"; $username = "".$_SESSION['username'].""; $users_data = mysql_query("SELECT * FROM `members` WHERE `username`='".$username."'"); $user_info = mysql_fetch_array($users_data); if ($myPaypal->validateIpn()) { if ($myPaypal->ipnData['payment_status'] == 'Completed') { file_put_contents('/home/rdewebde/public_html/lounge/paypal.txt', 'SUCCESS'); $new_amount = $user_info['balance'] - $myPaypal->ipnData['mc_gross']; mysql_query("UPDATE members SET balance = $new_amount WHERE username = '".$username."'") or die(mysql_error()); } else { file_put_contents('/home/rdewebde/public_html/lounge/paypal.txt', "FAILURE\n\n" . $myPaypal->ipnData); } } ?> and the link to the script is: http://phpfour.com/blog/2009/02/php-payment-gateway-library-for-paypal-authorizenet-and-2checkout/ thx again! Quote Link to comment https://forums.phpfreaks.com/topic/226093-having-trouble-updating-a-variable-to-database-paypal-integration/#findComment-1167405 Share on other sites More sharing options...
Skylight_lady Posted January 31, 2011 Share Posted January 31, 2011 Did you previously echo the query $update_balance (to see if the values are inputted) ?? Tho, i have seen from your latest code: mysql_query("UPDATE members SET balance = $new_amount WHERE username = '".$username."'") or die(mysql_error()); Try and make the $new_amount the same as $username (like '".$new_amount."') e.g: mysql_query("UPDATE members SET balance = '".$new_amount."' WHERE username = '".$username."'") or die(mysql_error()); Also: $username = "".$_SESSION['username'].""; doesn't look right. Shouldn't it be: $username = $_SESSION['username']; Quote Link to comment https://forums.phpfreaks.com/topic/226093-having-trouble-updating-a-variable-to-database-paypal-integration/#findComment-1167921 Share on other sites More sharing options...
Skylight_lady Posted February 1, 2011 Share Posted February 1, 2011 I also noticed that you are using ob_start() for output buffering. You do know that you are also required to close it with ob_end_flush(). However, from what i have seen and tested, they are only required if you are using the following in your code: <html> <head> </head> <body> May i ask how you are using session_start() ? are u using this on every page of those 6 paypal pages or just this paypal_ipn.php? Quote Link to comment https://forums.phpfreaks.com/topic/226093-having-trouble-updating-a-variable-to-database-paypal-integration/#findComment-1168140 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.