dsznndq4912405 2015-02-17 01:30
浏览 33
已采纳

OKPAY Callback API更新数据库

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

  • 写回答

1条回答 默认 最新

  • douwei3280 2015-02-17 13:01
    关注
    if ($res != "VERIFIED")
    {
        exit('Not verified');
    }
    

    Here is your mistake. When you use "IPN Testing tool" status will be "TEST" instead of "VERIFIED"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换