I am trying to change value in mysql database based on paypal ipn.
my ipn.php:
$db=mysqli_connect("localhost","root","toor","database");
// 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.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to 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'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if($payment_status=='Completed'){
$paylog = $db->query("UPDATE database.users SET money='$payment_amount' WHERE username='$item_name'");
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
c# pay button:
private void pictureBox1_Click(object sender, EventArgs e)
{
int value;
if (Int32.TryParse(textBox1.Text, out value))
{
if (value >= 10)
{
Process myProcess = new Process();
try
{
// true is the default, but it is important not to set it to false
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = "https://www.sandbox.paypal.com/cgi-bin/webscr?&cmd=_xclick&[email protected]¤cy_code=EUR&amount=" + this.textBox1.Text + "&item_name=" + Form1.sendusername + "¬ify_url=http://stormclap.it/ipn/ipn.php";
myProcess.Start();
}
catch (Exception em)
{
Console.WriteLine(em.Message);
}
}
else
{
MessageBox.Show("Minimum deposit is 10 EUR!");
}
}
}
Just to understand. I set item_name = username of c# windows form user. User choose payment value and type it into textbox1. Must be >= 10.
When button is clicked ... url to sandbox paypal opens with no problem. Payment is processed and set to completed.
business sandbox ipn url is entered in button and paypal profile.
Value is mysql is not changed. What I did wrong? Please help. Thanks!