public function checkout() { $payer = new Payer(); $payer->setPaymentMethod('paypal'); $items = []; $session = Session::get('cart.songs'); $bundles = Session::get('cart.bundles'); $total = 0; if (count($session) == 0 && count($bundles) == 0) { die('No Items in you cart'); } $songs_string = ""; $bundles_string = ""; if (count($session) != 0) { foreach ($session as $s) { $song = Song::find($s['id']); $item = new Item(); $item->setName($song->title)->setCurrency('AUD')->setQuantity(1)->setPrice($song->price); $items[] = $item; $total += $song->price; $songs_string .= "," . $song->id; } } if (count($bundles) != 0) { foreach ($bundles as $s) { $bundles = Bundle::find($s['id']); $item = new Item(); $item->setName($bundles->name)->setCurrency('AUD')->setQuantity(1)->setPrice($bundles->price); $items[] = $item; $total += $bundles->price; $bundles_string .= "," . $bundles->id; } } $item_list = new ItemList(); $item_list->setItems($items); $amount = new Amount(); $amount->setCurrency('AUD')->setTotal($total); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Music Equity Song Purchase'); $redirect_urls = new RedirectUrls(); $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status')); $payment = new Payment(); $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction)); try { $payment->create($this->_api_context); } catch (\PayPal\Exception\PPConnectionException $ex) { if (\Config::get('app.debug')) { echo "Exception: " . $ex->getMessage() . PHP_EOL; $err_data = json_decode($ex->getData(), true); exit; } else { die('Some error occur, sorry for inconvenient'); } } foreach ($payment->getLinks() as $link) { if ($link->getRel() == 'approval_url') { $redirect_url = $link->getHref(); break; } } $t = new MyTransaction(); $t->amount = $total; if (Auth::check()) { $t->customer = Auth::user()->id; } else { $t->customer = '0'; } $t->songs = $songs_string; $t->bundles = $bundles_string; $t->status = 'OPEN'; $t->paypal_id = $payment->getId(); $t->save(); // add payment ID to session Session::put('paypal_payment_id', $payment->getId()); if (isset($redirect_url)) { // redirect to paypal return Redirect::away($redirect_url); } }
/** * Display an index of the admin panel. * GET /admin * * @return Response */ public function index() { //$start = new Carbon('first day of this month'); if (Input::has('daterange')) { $range = explode(" ", Input::get('daterange')); try { $start = Carbon::createFromFormat('m/d/Y', $range[0]); } catch (Exception $ex) { $start = new Carbon('last month'); } try { $finish = Carbon::createFromFormat('m/d/Y', $range[2]); } catch (Exception $ex) { $finish = new Carbon('today'); } } else { $start = new Carbon('last month'); $finish = new Carbon('today'); } $range = $start->format('m/d/Y') . " - " . $finish->format('m/d/Y'); $graph = ['songs' => [], 'artists' => [], 'transactions' => [], 'axis' => []]; $interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod($start, $interval, $finish); $i = 0; foreach ($period as $date) { $graph['axis'][$i] = $date->format('d.m.y'); $graph['songs'][$i] = 0; $graph['artists'][$i] = 0; $graph['transactions'][$i] = 0; $i++; } $last = $i - 1; $songs = Song::where('completed', '=', '1')->where('created_at', '>', $start); $artists = User::where('type', '=', 'artist')->where('created_at', '>', $start); $transactions = MyTransaction::where('created_at', '>', $start); $stats['songs_count'] = $songs->count(); $stats['artist_count'] = $artists->count(); $stats['transactions_count'] = $transactions->count(); /*foreach ($songs->get() as $s) { $c = new Carbon( $s->created_at ); if(isset($graph['songs'][$c->format('d.m')])) { $graph['songs'][$c->format('d.m.y')]++; } else { $graph['songs'][$c->format('d.m.y')] = 1; } }*/ foreach ($songs->get() as $s) { $c = new Carbon($s->created_at); for ($i = 0; $i <= $last; $i++) { if ($graph['axis'][$i] == $c->format('d.m.y')) { $graph['songs'][$i]++; } } } foreach ($artists->get() as $s) { $c = new Carbon($s->created_at); for ($i = 0; $i <= $last; $i++) { if ($graph['axis'][$i] == $c->format('d.m.y')) { $graph['artists'][$i]++; } } } foreach ($transactions->get() as $s) { $c = new Carbon($s->created_at); for ($i = 0; $i <= $last; $i++) { if ($graph['axis'][$i] == $c->format('d.m.y')) { $graph['transactions'][$i]++; } } } /*foreach ($artists->get() as $s) { $c = new Carbon( $s->created_at ); if(isset($graph['artists'][$c->format('d')])) { $graph['artists'][$c->format('j')]++; } else { $graph['artists'][$c->format('j')] = 1; } } foreach ($transactions->get() as $s) { $c = new Carbon( $s->created_at ); if(isset($graph['transactions'][$c->format('d')])) { $graph['transactions'][$c->format('j')]++; } else { $graph['transactions'][$c->format('j')] = 1; } }*/ return View::make('admin.dashboard', ['stats' => $stats, 'range' => $range, 'graph' => $graph]); }