public function delete_album($id) { $bundle = Bundle::find($id); if (!is_null($bundle)) { if ($bundle->artist != Auth::user()->id) { return Redirect::to('/'); } else { $bundle->delete(); return Redirect::to('/artist/' . Auth::user()->profile_url); } } }
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); } }
public function add_bundle_to_cart($bundle) { $bundle = Bundle::find($bundle); if (!is_null($bundle)) { $data = ['id' => $bundle->id, 'title' => $bundle->name, 'price' => $bundle->price]; Session::push('cart.bundles', $data); return Response::json(['id' => $bundle->id, 'price' => $bundle->price]); } else { App::abort('404'); } }