drtldt55533 2018-09-15 04:40
浏览 68

区块链api问题[重复]

This question already has an answer here:

I am using PHP 7.2 and laravel this my blockchain api code

$blockchain_receive_root = "https://api.blockchain.info/";
    $secret = "ABIR";
    $my_api_key = $gateway->account;
    $my_xpub = $gateway->val1;

    $invoice_id = $transaction->hash;
    $callback_url = route('ipn.blockchain', ['invoice_id' => $invoice_id, 'secret' => $secret]);

    $resp = $blockchain_receive_root . "v2/receive?key=" . $my_api_key . "&callback=" . urlencode($callback_url) . "&xpub=" . $my_xpub;

    //BITCOIN API HAVING ISSUE. PLEASE TRY LATER
    if (!$resp) {
        return redirect()->route('account')->with('error', trans('site.blockchain.error'));
        exit;
    }
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $resp);
                curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $laste = curl_exec($ch);
                curl_close($ch);

    $response = json_decode($laste);

    $var = "bitcoin:$response->address?amount=$transaction->btc_amo";
    $code =  "<img src=\"https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=$var&choe=UTF-8\" title='' style='width:300px;' />";

and this is my callback url file

        if($request->input('invoice_id') && $request->input('secret')) {

        $track = $request->input('invoice_id');
        $secret = $request->input('secret');
        $value = $request->input('value');
        $confirmations = $request->input('confirmations');
        $value_in_btc = $value / 100000000;
        $trx_hash = $request->input('transaction_hash');

        $order = Transaction::where('hash',$track)->first();

        if($order->status == 0){

            if ($order->btc_amo==$value_in_btc && $secret=="ABIR" && $confirmations >= 1){
                $savedata['confirmation'] = $trx_hash;
                $savedata['gateway_response'] = json_encode($request->all());
                $savedata['status'] = 'paid';

                //Update product sales
                $this->salesupdate($order->product_id);
                //Save order
                $this->neworder($order->user_id,$order->product_id,$order->price,$order->hash,$order->id);
                //Save user transaction
                $this->newusertransaction($order->user_id,$order->price);
                //Credit seller
                $this->creditseller($order->product_id);


                $order->update($savedata);
                 $request->session()->flash('success',trans('Your payments has been done!'));
                  return redirect()->route('account.mypurchases',$track);
            }
        }
    }

now the issue is the callback URL doesn't do the function inside him like credit the seller and update product sales

and when i checked my logs i found this

[2018-09-15 04:27:07] production.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '119' for key 'transaction_id' (SQL: insert into buys (user_id, product_id, price, hash, transaction_id, updated_at, created_at) values (2, 104, 0.20, 92b6564b75f60396590d744e5efacbbe, 119, 2018-09-15 04:27:07, 2018-09-15 04:27:07)) {"exception":"[object] (Illuminate\Database\QueryException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '119' for key 'transaction_id' (SQL: insert into buys (user_id, product_id, price, hash, transaction_id, updated_at, created_at) values (2, 104, 0.20, 92b6564b75f60396590d744e5efacbbe, 119, 2018-09-15 04:27:07, 2018-09-15 04:27:07)) at /srv/data/web/vhosts/heliux.pw/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '119' for key 'transaction_id' at /srv/data/web/vhosts/heliux.pw/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458) [stacktrace]

please some one tell me where is the error and how to fix it

</div>
  • 写回答

1条回答 默认 最新

  • dopuz8728 2018-09-15 05:14
    关注

    It looks like the buys table has a UNIQUE index on transaction_id and that the table already has this transaction_id in the table.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)