Exemplo n.º 1
0
 public function wallet($app)
 {
     if (!$app->user->isLoggedIn()) {
         $app->output->redirect('/account/login');
     }
     $request = $app->router->flight->request();
     $page = $request->query->p ?: 0;
     $offset = $page * self::MAX_CASHOUTS_SHOWN;
     $page_total = CashoutRequest::count(array('conditions' => array('user_id = ?', $app->user->id))) / self::MAX_CASHOUTS_SHOWN;
     $page_total = ceil($page_total);
     if ($offset < 0 || $page > $page_total) {
         $app->output->redirect('/account/wallet');
     }
     $cashout_requests = CashoutRequest::find('all', array('conditions' => array('user_id = ?', $app->user->id), 'limit' => self::MAX_CASHOUTS_SHOWN, 'offset' => $offset, 'order' => 'updated_at DESC'));
     $listings = Listing::find('all', array('conditions' => array('user_id = ? AND stage = ?', $app->user->id, Listing::STAGE_COMPLETE)));
     $total = 0;
     $items = array();
     foreach ($listings as $idx => $listing) {
         if ($listing->description->stackable == 1) {
             if (empty($items[$listing->description->id])) {
                 $items[$listing->description->id] = array('listing' => $listing, 'qty' => 1, 'subtotal' => $listing->price);
             } else {
                 $items[$listing->description->id] = array('listing' => $listing, 'qty' => $items[$listing->description->id]['qty'] + 1, 'subtotal' => $items[$listing->description->id]['subtotal'] + $listing->price);
             }
         } else {
             $items[$listing->id] = array('listing' => $listing, 'qty' => 1, 'subtotal' => $listing->price);
         }
     }
     foreach ($items as $idx => &$item) {
         $item['unit_price'] = $item['subtotal'] / $item['qty'];
     }
     $total += array_reduce($items, function ($carry, $item) {
         $carry += $item['subtotal'];
         return $carry;
     });
     $total_taxed = round($total * 0.95, 2);
     if (empty($items)) {
         $app->output->alert('You have no listings to cash out on yet. [Why not check on them?](' . $app->config->get('core.url') . '/account/listings)');
     }
     if (empty($app->user->paypal)) {
         $app->output->alert('We ask that all users intending to **cashout using PayPal** store their PayPal e-mail address in their settings.', 'info');
     }
     if ($app->user->cooldown) {
         $app->output->alert('Your last cashout was made within a week ago--please wait another week until requesting another cashout.');
     }
     $app->output->addBreadcrumb('', 'CSGOShop');
     $app->output->addBreadcrumb('account/wallet', 'My Wallet');
     $app->output->setTitle('Wallet');
     $app->output->setActiveTab('account');
     $app->output->render('account.wallet', ['items' => $items, 'total' => $total, 'total_taxed' => $total_taxed, 'cashout_requests' => $cashout_requests, 'page_num' => $page, 'page_total' => $page_total]);
 }
Exemplo n.º 2
0
    public function processCashout($app)
    {
        if (!$app->user->isLoggedIn() || !$app->user->isRank('Managing Director')) {
            $app->logger->log('Unauthorized access to Admin CP', 'ALERT', array(), 'admin');
            $app->output->redirect('/');
        }
        $request = $app->router->flight->request();
        $cashout_id = $request->query->cashout_id ?: -1;
        try {
            $cashout_id_dec = $app->hashids->decrypt($cashout_id);
            $cashout = CashoutRequest::find($cashout_id_dec);
            $cashout->status = CashoutRequest::STATUS_PAID;
            $cashout->save();
            switch ($cashout->provider) {
                case 'coinbase':
                    Notification::create(['user_id' => $cashout->user_id, 'receiver_id' => $cashout->user_id, 'title' => 'MONEY', 'body' => '**Funds for your Cashout Request #' . $app->hashids->encrypt($cashout->id) . ' have been dispursed!** You have been credited ' . money_format('$%.2n', $cashout->total) . '. 
[Claim your BTC](http://coinbase.com/claim/' . $cashout->provider_identifier . ') at your convenience.']);
                    break;
                case 'stripe':
                    Notification::create(['user_id' => $cashout->user_id, 'receiver_id' => $cashout->user_id, 'title' => 'MONEY', 'body' => '**Funds for your Cashout Request #' . $app->hashids->encrypt($cashout->id) . ' have been dispursed!** You have been credited ' . money_format('$%.2n', $cashout->total) . '. From Stripe\'s FAQ:
	For bank accounts, transfers will be available in the bank account the next business day if created before 21:00 UTC (2pm PST). If the transfer fails (due to a typo in the bank details, for example), it can take up to five business days for Stripe to be notified.

	Transfers to debit cards can take 1 to 2 days to complete. However, unlike with bank accounts, we\'ll know instantaneously if the debit card is not valid when it is added to the recipient.']);
                    break;
                default:
                    Notification::create(['user_id' => $cashout->user_id, 'receiver_id' => $cashout->user_id, 'title' => 'MONEY', 'body' => '**Funds for your Cashout Request #' . $app->hashids->encrypt($cashout->id) . ' have been dispursed!** You have been credited ' . money_format('$%.2n', $cashout->total) . ' via PayPal.']);
                    break;
            }
        } catch (Hashids_Invalid $e) {
            $app->logger->log('CashoutRequest ID given was invalid', 'ERROR', array('object' => 'CashoutRequest', 'id' => $id, 'pathway' => 'processCashout'), 'admin');
            $app->output->notFound();
        } catch (ActiveRecord\RecordNotFound $e) {
            $app->logger->log('No such CashoutRequest found', 'ERROR', array('object' => 'CashoutRequest', 'id' => $cashout_id, 'id_dec' => $cashout_id_dec, 'pathway' => 'processCashout'), 'admin');
            $app->output->notFound();
        }
        $app->output->redirect('/admin/cashouts');
    }
Exemplo n.º 3
0
 public function get_cooldown()
 {
     $last_cashout = CashoutRequest::find('first', array('conditions' => array('user_id = ?', $this->id), 'order' => 'created_at DESC'));
     if (empty($last_cashout)) {
         return false;
     }
     $diff = time() - strtotime($last_cashout->created_at->format('db'));
     if ($diff > self::CASHOUT_LIMIT) {
         return false;
     }
     return $diff;
 }