original_string: public function getCheckout($itemId)
      {
          $item = Item::findOrFail($itemId);
  
          if ($item->seller->userId == Auth::user()->userId) {
              return redirect($item->url)->withErrors([
                  'You cannot purchase your own items.'
              ]);
          }
  
          if ($item->auction && !$item->isActive() && $item->purchases->count()) {
              return redirect('/pay/' . $item->purchases->first()->purchaseId);
          }
  
          // Check for unpaid item
          if ($unpaid = $item->purchases()->where('user_id', Auth::user()->userId)->where('paid', 0)->first()) {
              return redirect('/pay/' . $unpaid->purchaseId);
          }
  
          if (!$item->isActive() && !$item->auction) {
              return redirect($item->url)->withErrors([
                  'This item has ended.'
              ]);
          }
  
          if ($item->isActive() && !$item->hasFixed()) {
              return redirect($item->url)->withErrors([
                  'This auction has no fixed price, so cannot be bought outright.'
              ]);
          }
  
          if (!$item->isActive() && $item->auction && !$item->winningBid) {
              return redirect($item->url)->withStatus(
                  'Please wait while this auction is processed.'
              );
          }
  
          return view('mustard::purchase.checkout', [
              'countries' => Iso3166::all(),
              'item' => $item,
              'item_total' => ($item->auction && !$item->isActive())
                  ? $item->biddingPrice
                  : $item->fixedPrice,
          ]);
      }
code: public function getCheckout($itemId)
      {
          $item = Item::findOrFail($itemId);
  
          if ($item->seller->userId == Auth::user()->userId) {
              return redirect($item->url)->withErrors([
                  'You cannot purchase your own items.'
              ]);
          }
  
          if ($item->auction && !$item->isActive() && $item->purchases->count()) {
              return redirect('/pay/' . $item->purchases->first()->purchaseId);
          }
  
          // Check for unpaid item
          if ($unpaid = $item->purchases()->where('user_id', Auth::user()->userId)->where('paid', 0)->first()) {
              return redirect('/pay/' . $unpaid->purchaseId);
          }
  
          if (!$item->isActive() && !$item->auction) {
              return redirect($item->url)->withErrors([
                  'This item has ended.'
              ]);
          }
  
          if ($item->isActive() && !$item->hasFixed()) {
              return redirect($item->url)->withErrors([
                  'This auction has no fixed price, so cannot be bought outright.'
              ]);
          }
  
          if (!$item->isActive() && $item->auction && !$item->winningBid) {
              return redirect($item->url)->withStatus(
                  'Please wait while this auction is processed.'
              );
          }
  
          return view('mustard::purchase.checkout', [
              'countries' => Iso3166::all(),
              'item' => $item,
              'item_total' => ($item->auction && !$item->isActive())
                  ? $item->biddingPrice
                  : $item->fixedPrice,
          ]);
      }
code_tokens: public function getCheckout ( $ itemId ) { $ item = Item :: findOrFail ( $ itemId ) ; if ( $ item -> seller -> userId == Auth :: user ( ) -> userId ) { return redirect ( $ item -> url ) -> withErrors ( [ 'You cannot purchase your own items.' ] ) ; } if ( $ item -> auction && ! $ item -> isActive ( ) && $ item -> purchases -> count ( ) ) { return redirect ( '/pay/' . $ item -> purchases -> first ( ) -> purchaseId ) ; } // Check for unpaid item if ( $ unpaid = $ item -> purchases ( ) -> where ( 'user_id' , Auth :: user ( ) -> userId ) -> where ( 'paid' , 0 ) -> first ( ) ) { return redirect ( '/pay/' . $ unpaid -> purchaseId ) ; } if ( ! $ item -> isActive ( ) && ! $ item -> auction ) { return redirect ( $ item -> url ) -> withErrors ( [ 'This item has ended.' ] ) ; } if ( $ item -> isActive ( ) && ! $ item -> hasFixed ( ) ) { return redirect ( $ item -> url ) -> withErrors ( [ 'This auction has no fixed price, so cannot be bought outright.' ] ) ; } if ( ! $ item -> isActive ( ) && $ item -> auction && ! $ item -> winningBid ) { return redirect ( $ item -> url ) -> withStatus ( 'Please wait while this auction is processed.' ) ; } return view ( 'mustard::purchase.checkout' , [ 'countries' => Iso3166 :: all ( ) , 'item' => $ item , 'item_total' => ( $ item -> auction && ! $ item -> isActive ( ) ) ? $ item -> biddingPrice : $ item -> fixedPrice , ] ) ; }
docstring: Return the item checkout view.
  
  @return \Illuminate\View\View
docstring_tokens: Return the item checkout view .