Пример #1
0
 public function process(BookInterface $book, User $user, $token)
 {
     $charge = $user->charge(number_format($book->price, 2, "", ""), ['source' => $token, 'receipt_email' => $user->email]);
     if ($charge) {
         Order::create(['user_id' => $user->id, 'book_id' => $book->id, 'price' => $book->price]);
         return true;
     }
     return false;
 }
 public function download($id)
 {
     $order = Order::find($id);
     if ($order->user_id == auth()->user()->id) {
         $book = $order->book;
         if (file_exists(storage_path("books/{$book->id}/book.zip"))) {
             return response()->download(storage_path("books/{$book->id}/book.zip"));
         }
     }
 }