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 intobuys
(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>