paypal ipn - PP IPN doesn't update my database(PHP) -
first of i'd i'm lost when comes these things have spoonfed.
anyway, i'm using pp ipn right people on upcoming project can upgrade "premium" give them functions , such. however, script works in way, doesn't update database information.
in database have field called "vip" set "0" when signing up. if buy premium should change "1". problem doesn't update information, though payment goes through.
i'm on live webserver well. i've followed tutorial made phpacademy this, again, i'm clueless. , forum seems rather dead atm.
ipn.php
<?php include 'core/init.php'; // read post paypal system , add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_post $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post paypal system validate $header .= "post /cgi-bin/webscr http/1.1\r\n"; $header .= "content-type: application/x-www-form-urlencoded\r\n"; $header .= "content-length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables local variables $item_name = $_post['item_name']; $item_number = $_post['item_number']; $payment_status = $_post['payment_status']; $payment_amount = $_post['mc_gross']; $payment_currency = $_post['mc_currency']; $txn_id = $_post['txn_id']; $receiver_email = $_post['receiver_email']; $payer_email = $_post['payer_email']; $user_id = $_post['custom']; // our user's id if (!$fp) { // http error } else { fputs ($fp, $header . $req); while(!feof($fp)) { $res = fgets ($fps, 1024); if (strcmp ($res, "verified") == 0) { if ($payment_status == 'completed') { $txn_id_check = mysql_query("select `txn_id` `log` `txn_id` = '".$txn_id."'"); if (mysql_num_rows($txn_id_check) !=1) { if ($receiver_email == 'h1f5gaming@gmail.com') { if ($payment_amount == '0.01' && $payment_currency == 'eur') { // add txn_id database $log_query = mysql_query("insert `log` values ('','".$txn_id."','".$payer_email."') ") or die(mysql_error()); // update premium 1 $update_vip = mysql_query("update `users` set vip='1' `user_id` = '".$user_id."'") or die(mysql_error()); } } } } } else if(strcmp ($res, "invalid") == 0) { // log manual investigation } } fclose ($fp); } ?>
as can see have "or die(mysql_error())" on 2 lines @ query i'd it's testing purposes. doesn't give me errors @ all.
here's form:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="h1f5gaming@gmail.com"> <input type="hidden" name="item_name" value="premium membership"> <input type="hidden" name="amount" value="0.01"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="eur"> <input type="hidden" name="lc" value="eu"> <input type="hidden" name="bn" value="pp-buynowbf"> <input type="hidden" name="return" value="http://www.h1f5.eu/thanks.php"> <input type="hidden" name="cancel_return" value="http://www.h1f5.eu/"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="notify_url" value="http://www.h1f5.eu/ipn.php" /> <input type="hidden" name="custom" value="<?php echo $_session['user_id']; ?>"> <input type="submit" value="upgrade premium" /> </form>
thank in advance.
Comments
Post a Comment