Exemplo n.º 1
1
 public function postWithdraw()
 {
     $amount = Bitcoin::toSatoshi(floatval(Input::get('amount', 0)));
     $address = Input::get('address');
     if ($amount < Config::get('bitcoin.minimum_withdrawal')) {
         return Redirect::back()->withInput()->with('error', 'Amount is less than the minimum.');
     } else {
         if ($amount > Auth::user()->getBalance()) {
             return Redirect::back()->withInput()->with('error', 'You do not have the required funds.');
         }
     }
     if (!Bitcoin::checkAddress($address)) {
         return Redirect::back()->withInput()->with('error', 'Invalid bitcoin address.');
     }
     $api_url = 'https://blockchain.info/merchant/' . urlencode(Config::get('bitcoin.guid')) . '/payment';
     $api_url .= '?password='******'bitcoin.password'));
     $api_url .= '&to=' . urlencode($address);
     $withdraw_amount = $amount - Config::get('bitcoin.withdrawal_fee');
     $api_url .= '&amount=' . urlencode($withdraw_amount);
     $response = file_get_contents($api_url);
     $response = json_decode($response);
     if (!property_exists($response, 'tx_hash')) {
         return Redirect::back()->withInput()->with('error', $response->error);
     } else {
         Auth::user()->subtractFromBalance($amount);
     }
     $withdraw = new Withdraw();
     $withdraw->user_id = Auth::user()->id;
     $withdraw->amount = $amount;
     $withdraw->btc_address = $address;
     $withdraw->transaction_hash = $response->tx_hash;
     if (property_exists($response, 'notice')) {
         $withdraw->notice = $response->notice;
     }
     if (property_exists($response, 'message')) {
         $withdraw->message = $response->message;
     }
     if (!$withdraw->save()) {
         Notify::alert('Withdraw couldn\'t be saved!');
     }
     return Redirect::back()->with('success', 'Withdraw processed.');
 }
Exemplo n.º 2
0
 public function postCreate()
 {
     if (!Auth::check()) {
         return array('success' => false, 'errors' => 'You must be logged in to place any bets.');
     }
     $bet_amount = Bitcoin::toSatoshi(floatval(Input::get('bet_amount')));
     $cross_bet_amount = Bitcoin::toSatoshi(floatval(Input::get('cross_bet_amount')));
     if ($bet_amount > Auth::user()->getBalance()) {
         return array('success' => false, 'errors' => array('bet_amount' => 'You don\'t have enough funds to place that bet.'));
     }
     if ($bet_amount < Config::get('bitcoin.minimum_bet')) {
         return array('success' => false, 'errors' => array('bet_amount' => 'Minimum bet amount is ' . Bitcoin::toBTC(Config::get('bitcoin.minimum_bet')) . ' BTC'));
     }
     if ($cross_bet_amount < Config::get('bitcoin.minimum_bet')) {
         return array('success' => false, 'errors' => array('cross_bet_amount' => 'Minimum bet amount is ' . Bitcoin::toBTC(Config::get('bitcoin.minimum_bet')) . ' BTC'));
     }
     $type = Input::get('type');
     if (!in_array($type, $this->valid_types)) {
         return array('success' => false, 'errors' => array('type' => 'Invalid.'));
     }
     $expiration = intval(Input::get('expiration'));
     if ($expiration < Config::get('bitcoin.minimum_bet_expiration') || $expiration > Config::get('bitcoin.maximum_bet_expiration')) {
         return array('success' => false, 'errors' => array('expiration' => 'Invalid.'));
     }
     $bet = new Bet();
     $bet->type = $type;
     $bet->created_by_user_id = Auth::user()->id;
     $bet->bet_amount = $bet_amount;
     $bet->cross_bet_amount = $cross_bet_amount;
     $bet->target_price = floatval(Input::get('target_price'));
     $bet->price_when_created = Bitcoin::toUSD();
     $expiresAt = Carbon::now()->addSeconds($expiration);
     $bet->expires_at = $expiresAt;
     if ($bet->save()) {
         Auth::user()->subtractFromBalance($bet_amount);
         return array('success' => true);
     } else {
         return array('success' => false, 'errors' => 'Bet couldn\'t be created.');
     }
 }