Esempio 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.');
 }
Esempio n. 2
0
 function notify()
 {
     $order_id = $_GET['order_id'];
     $type = strtolower($_GET['type']);
     $type_arr = array('cancel', 'alert');
     if (!in_array($type, $type_arr)) {
         echo 'no_type';
         exit;
     }
     $order_model = M('Order');
     // 查找订单
     $order = $order_model->find($order_id);
     if (empty($order)) {
         echo 'no_order';
         exit;
     }
     if ($order['status'] > 1) {
         echo 'type_error';
         exit;
     }
     // 更改订单状态
     if ($type == 'cancel') {
         $order_model->setStatus($order['store_id'], $order['order_id'], 5);
         echo 'ok';
         exit;
     }
     if ($type == 'alert') {
         import('source.class.Notify');
         Notify::alert('尊敬的会员' . $order['address_user'] . '您好,您的订单号:' . $order_id . '未付款,请及时付款');
     }
 }
Esempio n. 3
0
 public function handleWinner()
 {
     if ($this->winner_paid) {
         return false;
     }
     $btc_price = Bitcoin::toUSD();
     if ($this->type == 'above') {
         $winner = $btc_price > $this->target_price ? $this->created_by_user_id : $this->accepted_by_user_id;
     } else {
         if ($this->type == 'under') {
             $winner = $btc_price < $this->target_price ? $this->created_by_user_id : $this->accepted_by_user_id;
         }
     }
     $this->winner_user_id = $winner;
     $winnings = (1 - Config::get('bitcoin.winnings_fee')) * (intval($this->bet_amount) + intval($this->cross_bet_amount));
     $winner_model = User::where('id', $winner)->first();
     $winner_model->addToBalance($winnings);
     Notify::alert("User {$winner} paid " . Bitcoin::toBTC($winnings) . " BTC");
     $this->winner_paid = 1;
     $this->save();
     return true;
 }
 public function getCallback()
 {
     if (Input::get('secret') != Config::get('bitcoin.secret')) {
         Notify::alert('Invalid secret provided: ' . Input::get('secret', ''));
         App::abort(404);
     }
     $destination_address = Input::get('destination_address');
     if ($destination_address != Config::get('bitcoin.wallet_address')) {
         Notify::alert('Invalid destination address: ' . $destination_address);
         App::abort(404);
     }
     $input_address = Input::get('input_address');
     $user = User::where('deposit_btc_address', $input_address)->first();
     if (count($user) != 1) {
         Notify::alert('Invalid user deposit address: ' . $input_address);
         App::abort(404);
     }
     $transaction_hash = Input::get('transaction_hash');
     $input_transaction_hash = Input::get('input_transaction_hash');
     $value_in_satoshi = Input::get('value');
     $deposit = new ExternalDeposit();
     $deposit->amount = $value_in_satoshi;
     $deposit->user_id = $user->id;
     $deposit->confirmations = Input::get('confirmations');
     $deposit->input_address = $input_address;
     $deposit->destination_address = $destination_address;
     $deposit->transaction_hash = $transaction_hash;
     $deposit->input_transaction_hash = $input_transaction_hash;
     if ($deposit->save()) {
         if (intval(Input::get('confirmations')) >= Config::get('bitcoin.num_confirmations_deposit')) {
             Notify::alert('Money deposited!');
             $user->addToBalance($value_in_satoshi);
             echo "*ok*";
         }
     } else {
         Notify::alert('Unable to make external deposit!');
         App::abort(404);
     }
 }
Esempio n. 5
0
import('source.class.Notify');
// md5进行验证
$data = array();
$data['order_id'] = $order_id;
$data['type'] = $type;
$data['appid'] = $appid;
$md5 = Notify::encrypt_key($data, $notify_key);
if ($md5 != $auth_key) {
    echo 'auth error';
    exit;
}
$order_model = M('Order');
// 查找订单
$order = $order_model->find($order_id);
if (empty($order)) {
    echo 'no_order';
    exit;
}
if ($order['status'] > 1) {
    echo 'type_error';
    exit;
}
// 更改订单状态
if ($type == 'cancel') {
    $order_model->cancelOrder($order, 0);
    echo 'ok';
    exit;
}
if ($type == 'alert') {
    Notify::alert('尊敬的会员' . $order['address_user'] . '您好,您的订单号:' . $order_id . '未付款,请及时付款');
}