0

I am trying to integrate coinpayment. By using this - https://github.com/hexters/CoinPayment

But I got error says:

exception: "ErrorException"
file: "C:\xampp\htdocs\coinpayment\vendor\hexters\coinpayment\src\Http\Controllers\CoinPaymentController.php"
line: 45
message: "Division by zero"

enter image description here

wowkin2
  • 5,895
  • 5
  • 23
  • 66
Nasir Khan
  • 753
  • 1
  • 9
  • 22

1 Answers1

1

Please Refer to author new commits in the git repository as he updated the package https://github.com/hexters/CoinPayment/commit/cf7de99e18948fe385e75dfa8ded0fb378c33ad4

In case the link is not working then go to your app route and then to vendor folder and follow path vendor/hexters/coinpayment/src/Http/Controllers and update CoinPaymentController.php file's public function ajax_rates() function with the below given code

public function ajax_rates(Request $req, $usd){
  $coins = [];
  $aliases = [];
  $rates = CoinPayment::api_call('rates', [
    'accepted' => 1
  ])['result'];
  $rateBtc = $rates['BTC']['rate_btc'];
  $rateUsd = $rates[config('coinpayment.default_currency')]['rate_btc'];
  $rateAmount = $rateUsd * $usd;
  $fiat = [];
  $coins_accept = [];
  foreach($rates as $i => $coin){
    if((FLOAT) $rates[$i]['rate_btc'] > 0) {
      if((INT) $coin['is_fiat'] === 0){
        $rate = ($rateAmount / $rates[$i]['rate_btc']);
        $coins[] = [
          'name' => $coin['name'],
          'rate' => number_format($rate,8,'.',''),
          'iso' => $i,
          'icon' => 'https://www.coinpayments.net/images/coins/' . $i . '.png',
          'selected' => $i == 'BTC' ? true : false,
          'accepted' => $coin['accepted']
        ];

        $aliases[$i] = $coin['name'];
      }

      if((INT) $coin['is_fiat'] === 0 && $coin['accepted'] == 1){
        $rate = ($rateAmount / $rates[$i]['rate_btc']);
        $coins_accept[] = [
          'name' => $coin['name'],
          'rate' => number_format($rate,8,'.',''),
          'iso' => $i,
          'icon' => 'https://www.coinpayments.net/images/coins/' . $i . '.png',
          'selected' => $i == 'BTC' ? true : false,
          'accepted' => $coin['accepted']
        ];
      }


      if((INT) $coin['is_fiat'] === 1){
        $fiat[$i] = $coin;
      }
    }
  }
  return response()->json([
    'coins' => $coins,
    'coins_accept' => $coins_accept,
    'aliases' => $aliases,
    'fiats' =>$fiat
  ]);
}