Okay I am using OKPAY to initate an IPN callback on payment complete, I have used to test tool to send the request of a successful payment, but it's not updating my information
$market = isset($_GET['ok_txn_currency']) ? $_GET['ok_txn_currency'] : '';
$amount = isset($_GET['ok_txn_net']) ? $_GET['ok_txn_net'] : '';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$status = isset($_GET['ok_txn_status']) ? $_GET['ok_txn_status'] : '';
$txid = isset($_GET['ok_txn_id']) ? $_GET['ok_txn_id'] : '';
// Read the post from OKPAY and add 'ok_verify'
$req = 'ok_verify=true';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// Post back to OKPAY to validate
$header .= "POST /ipn-verify.html HTTP/1.0
";
$header .= "Host: www.okpay.com
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "
";
$fp = fsockopen ('www.okpay.com', 80, $errno, $errstr, 30);
if (!$fp)
{
exit('Error postback');
}
fputs ($fp, $header . $req);
while (!feof($fp))
$res = fgets ($fp, 1024);
fclose ($fp);
if ($res != "VERIFIED")
{
exit('Not verified');
}
if($_POST['ok_txn_status'] !== 'completed')
exit('Invalid ok_txn_status');
$checktx = $this->db->prepare("SELECT * FROM transactions WHERE txid=? LIMIT 1");
$checktx->execute(array($txid));
$result = $checktx->fetch();
if(!$result):
if(isset($market) && isset($amount)):
//insert into transactions and update balance
$transaction = $this->db->prepare("INSERT INTO transactions(market,amount,
username,txid,transaction,status) VALUES(?,?,?,?,?,?)");
$transaction->execute(array($market,$amount,$username,$invoice,'deposit','1'));
if($transaction):
echo 'debug 1';
echo $market;
//get the user and their balance
$getuserbalance = $this->db->prepare("SELECT * FROM user WHERE username=?");
$getuserbalance->execute(array($username));
$userbalance = $getuserbalance->fetch();
//this is their new balance
$newbalance = $amount + $userbalance->{$market};
$updateuser = $this->db->prepare("UPDATE user SET ".htmlentities($market)."=? WHERE username=?");
$updateuser->execute(array($newbalance,$username));
endif;
endif;
endif;
It's giving me a 200OK return, but not uodating the database. Sorry for the long code