Exemplo n.º 1
0
 /**
  * @param array|Payout[] $payouts
  * @return array|Payout[]
  * @throws \Bml\CoinBundle\Exception\RequestException
  * @throws \Exception
  */
 private function _realisePayouts(array $payouts)
 {
     $sumPayout = 0;
     foreach ($payouts as $payout) {
         $sumPayout += $payout->getAmount();
     }
     do {
         if ($sumPayout < $this->round->getMinDeposit()) {
             // we will not payout less than min deposit
             // this is probably only paying out referrer
             // referrer payout amount is less than payout tx fee
             // it makes no sense to pay it out alone
             return [];
         }
         try {
             $tx = $this->walletManager->sendPayouts($payouts);
         } catch (RequestException $e) {
             if ($e->getCode() != -6) {
                 throw $e;
             }
             // this is probably insufficient founds error
             // that's because of fee added by client
             // we will try to pop last payout to see if then we will fit within fee+payout_amount<balance
             $last = array_pop($payouts);
             /* @var $payout Payout */
             $sumPayout -= $last->getAmount();
             continue;
         }
         foreach ($payouts as $payout) {
             $payout->setPaid(true);
             $payout->setTx($tx);
             $payout->setPaidOutTime(new \DateTime());
         }
         $this->em->flush();
         break;
     } while (!empty($payouts));
     return $payouts;
 }