Exemple #1
0
 public function get(Request $request, $bookingId)
 {
     $this->request = $request;
     if (!$this->getAuth()->hasRole('get-ticket')) {
         return new Response(NULL, 403);
     }
     $booking = Booking::findOrFail($bookingId);
     if (!$booking->ticketsGenerated) {
         $data = $this->generateTickets($booking);
     } else {
         $data = $this->getTicketData($bookingId);
     }
     return (new Response($data))->withHeaders(['Content-Type' => 'application/pdf']);
 }
Exemple #2
0
 public function fire()
 {
     $toDispatch = Booking::where('state', BookingState::CONFIRMED)->where('ticketsSent', 0)->get();
     $xport = \Swift_MailTransport::newInstance();
     $mailer = \Swift_Mailer::newInstance($xport);
     foreach ($toDispatch as $booking) {
         $customer = $booking->customer()->first();
         $seatSet = $booking->seatSet()->first();
         $this->info("Dispatching #{$booking->id} to {$booking->name}: {$customer->email}");
         $mail = $this->getTicketMail($this->generateTickets($booking, $seatSet, $customer), $booking, $customer);
         $mailer->send($mail);
         $booking->ticketsSent = 1;
         $booking->save();
     }
     $n = count($toDispatch);
     $this->info("Dispatched {$n} bookings.");
 }
Exemple #3
0
 public function fire()
 {
     DB::transaction(function () {
         $booking = Booking::findOrFail($this->argument('bookingId'));
         $refunds = $booking->refunds()->lists('id');
         if (count($refunds)) {
             $nos = implode(', ', $refunds->toArray());
             throw new \RuntimeException("Not re-processing; refunds already exist [{$nos}]");
         }
         $sSet = $booking->seatSet()->first();
         $sSet->annulled = TRUE;
         $sSet->save();
         foreach ($sSet->getHeldSeats() as $seat) {
             DB::table('booking_seats')->where('seat_set_id', $sSet->id)->where('seat_id', $seat->seat_id)->update(['refundAmount' => $seat->pricePaid, 'void' => TRUE, 'seat_held' => FALSE]);
         }
         $refund = new Refund();
         $refund->booking()->associate($booking);
         $refund->net = $booking->net;
         $refund->fees = $booking->fees;
         $refund->gross = $booking->gross;
         $refund->save();
     });
 }
Exemple #4
0
 public function complete(Request $r)
 {
     if (!($tok = $r->input('token'))) {
         return new Response('no tok', 400);
     }
     if (!($src = $r->input('source'))) {
         return new Response('no src', 400);
     }
     try {
         $token = new BookingToken();
         $token->token = $tok;
         $token->disposition = BookingToken::FRESH;
         $token->source = BookingToken::classify($src);
         $token->validateToken();
         $token->save();
     } catch (\Illuminate\Database\QueryException $e) {
         // Integrity violation -> dupe token?
         if ($e->getCode() == 23000) {
             return new Response('duplicate token', 410);
         }
         throw $e;
     } catch (\Demeter\BookingTokenException $e) {
         return new Response('Bad token', 400);
     }
     $comp = $src == BookingToken::TYPE_COMP;
     $doStripe = $src == BookingToken::TYPE_STRIPE;
     $invalid = FALSE;
     DB::beginTransaction();
     $seatSet = app(SeatsetController::class)->getSS(FALSE);
     if (!$seatSet) {
         $token->disposition = BookingToken::NO_SS;
         $token->save();
         DB::commit();
         return new Response('No SS', 404);
     }
     try {
         DB::table('seat_sets')->where('id', $seatSet->id)->sharedLock()->get();
         // May have changed pending the lock, so let's refresh
         $seatSet->fresh();
     } catch (\Illuminate\Database\QueryException $e) {
         DB::commit();
         return new Response('no lock', 503);
     }
     if (!$seatSet->ephemeral || $seatSet->annulled) {
         $token->disposition = BookingToken::SS_INVALID;
         $token->save();
         DB::commit();
         return new Response('SS Invalid', 409);
     }
     try {
         $cust = new Customer();
         foreach (['email' => 'email', 'pymtAddrLine1' => 'addrLine', 'pymtAddrCity' => 'addrCity', 'pymtAddrZip' => 'addrPostcode', 'pymtAddrCountry' => 'addrCountry'] as $input => $field) {
             $cust->{$field} = $r->input($input);
         }
         $cust->save();
         $booking = new Booking();
         $booking->name = $r->input('name');
         $booking->state = BookingState::BOOKED;
         $booking->token()->associate($token);
         $booking->customer()->associate($cust);
         $booking->seatSet()->associate($seatSet);
         $totals = $this->determineCurrentTotals($seatSet, $comp, $doStripe);
         $booking->net = $totals['net'];
         $booking->gross = $totals['gross'];
         $booking->fees = $totals['fee'];
         $booking->save();
         $seatSet->ephemeral = FALSE;
         $seatSet->freezePrices($comp);
         $seatSet->save();
         $token->disposition = BookingToken::READY;
         $token->save();
         DB::commit();
     } catch (\Illuminate\Database\QueryException $e) {
         // If something went wrong here, we probably had
         // bad/missing data.
         DB::rollback();
         $token->disposition = BookingToken::BOOK_FAIL;
         $token->save();
         error_log($e);
         return new Response('sql bounce', 400);
     }
     $bookData = ['booking' => $booking->id];
     if (!$doStripe || $this->takePayment($booking, $token, $declined, $e)) {
         DB::transaction(function () use($booking, $token) {
             $booking->state = BookingState::CONFIRMED;
             $token->disposition = BookingToken::CHARGED_OK;
             $booking->save();
             $token->save();
         });
         return $bookData;
     } else {
         DB::transaction(function () use($booking, $token, $seatSet, $declined, $e) {
             $booking->state = BookingState::ABORTED;
             $token->disposition = $declined ? BookingToken::CHARGED_DECLINED : BookingToken::CHARGED_FAIL;
             $seatSet->ephemeral = TRUE;
             error_log($e);
             // TODO: Store charge exception
             $booking->save();
             $token->save();
             $seatSet->save();
         });
         return new Response($bookData, 402);
     }
 }