Пример #1
3
 /**
  * @param TicketsOrder $order
  * @param string $format 'S': data string - 'I' to see in browser
  * @return string
  */
 public function getPdfFileData(TicketsOrder $order, $format = 'S')
 {
     $pdf = new \TCPDF();
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Billets du Louvre');
     $pdf->SetTitle('Commande ' . $order->getRef());
     $pdf->setPrintHeader(false);
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // set style for barcode
     $style = array('border' => 0, 'vpadding' => 'auto', 'hpadding' => 'auto', 'fgcolor' => array(0, 0, 0), 'bgcolor' => false, 'module_width' => 1, 'module_height' => 1);
     /** @var Ticket $ticket */
     foreach ($order->getTickets() as $ticket) {
         $pdf->AddPage();
         $html = $this->renderTicket(array('visit_date' => $order->getVisitDate()->format('d/m/Y'), 'visit_duration' => $order->getVisitDuration(), 'code' => $order->getRef(), 'ticket_name' => $ticket->getName(), 'price' => $ticket->getPrice(), 'details' => $ticket->getTicketDetails()));
         $pdf->writeHTML($html, true, false, true);
         $pdf->write2DBarcode($order->getRef(), 'QRCODE,H', 150, 10, 50, 50, $style, 'N');
         $pdf->lastPage();
     }
     return $pdf->Output('tickets.pdf', $format);
 }
 public function testGetOrderTotalAmount()
 {
     $order = new TicketsOrder();
     $ticket = new Ticket();
     $ticket->setPrice(20);
     $order->addTicket($ticket);
     $ticket = new Ticket();
     $ticket->setPrice(25);
     $order->addTicket($ticket);
     $ticket = new Ticket();
     $ticket->setPrice(36);
     $order->addTicket($ticket);
     $ticketsOrderRepository = $this->getMockBuilder(TicketsOrderRepository::class)->disableOriginalConstructor()->setMethods(array('findOneBy'))->getMock();
     $ticketsOrderRepository->expects($this->at(0))->method('findOneBy')->will($this->returnValue(null));
     $ticketsOrderRepository->expects($this->at(1))->method('findOneBy')->will($this->returnValue($order));
     $this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($ticketsOrderRepository));
     try {
         $amount = $this->paymentOrderInformation->getOrderTotalAmount(1, 'AAAAA');
         $this->fail('a null order must throw an exception');
     } catch (HttpException $e) {
         $this->assertEquals('400', $e->getStatusCode());
     }
     $amount = $this->paymentOrderInformation->getOrderTotalAmount(1, 'AAAAA');
     $this->assertEquals(81, $amount);
 }
Пример #3
0
 /**
  * @param TicketsOrder $order
  * @param TicketDetail $ticketDetail
  * @param $visitorData
  * @throws HttpException if the visitor age is not according with the ticket
  */
 public function controlVisitorData(TicketsOrder $order, TicketDetail $ticketDetail, $visitorData)
 {
     $visitDate = $order->getVisitDate();
     $visitorBirthdate = $visitorData['birthdate'];
     $dateDiff = date_diff($visitorBirthdate, $visitDate);
     $visitorAge = $dateDiff->y;
     $ageMin = $ticketDetail->getAgeMin();
     $ageMax = $ticketDetail->getAgeMax();
     if ($visitorAge < $ageMin || $visitorAge > $ageMax) {
         throw new HttpException('400', 'The age of the visitor will not be valid at the visit date');
     }
 }
 /**
  * @View()
  * @Post("/api/v1/order.{_format}", requirements={"_format"="json, xml"}, name="post_order", defaults={"_format"="json"})
  * @RequestParam(name="visit_date", requirements="[0-9]{4}-[0-9]{2}-[0-9]{2}", description="date of the visit formatted as yyyy-mm-dd")
  * @RequestParam(name="visit_duration", requirements="(JOURNEE)|(DEMI_JOURNEE)", description="time of the visit (day or half day) : 'JOURNEE' or 'DEMI_JOURNEE'")
  * @ApiDoc(description="create an order")
  */
 public function postOrderAction(ParamFetcher $paramFetcher)
 {
     $visitDate = new DateTime($paramFetcher->get('visit_date'));
     $visitDuration = $paramFetcher->get('visit_duration');
     $validator = $this->get('app.validator');
     $validator->controlDateValidity($visitDate);
     $validator->controlTicketType($visitDuration, $visitDate);
     $order = new TicketsOrder();
     $order->setVisitDate($visitDate);
     $order->setVisitDuration($visitDuration);
     $order->setRef($this->createNewOrderRef());
     $this->saveOrder($order);
     return $order;
 }
 public function testGetMessage()
 {
     $data = $this->getPdfData();
     $order = new TicketsOrder();
     $order->setMail('*****@*****.**');
     /** @var \Swift_Message $message */
     $message = $this->ticketsSender->getMessage($order, $data);
     $this->assertArrayHasKey('*****@*****.**', $message->getTo());
     $this->assertArrayHasKey('*****@*****.**', $message->getFrom());
     $this->assertEquals('Billets du Louvre - Votre commande', $message->getSubject());
     /** @var array $children */
     $children = $message->getChildren();
     $this->assertEquals(1, count($children));
     $this->assertArrayHasKey(0, $children);
     $this->assertEquals('application/pdf', $children[0]->getContentType());
 }
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $orders = array(array('ref' => 'AAAA', 'visitDate' => new \DateTime('2015-11-13'), 'visitDuration' => 'JOURNEE', 'validate' => false, 'tickets' => array(array('name' => 'Normal', 'longDescription' => 'De 12 ans à 59 ans', 'shortDescription' => '12 à 59 ans', 'price' => 16.0, 'details' => array(array('number' => 1, 'ageMin' => 12, 'ageMax' => 59, 'visitor' => array('lastName' => 'DUPONT', 'firstName' => 'Alain', 'country' => 'France', 'birthdate' => new \DateTime('1970-02-17'))))))));
     foreach ($orders as $order) {
         $ticketsOrder = new TicketsOrder();
         $ticketsOrder->setRef($order['ref']);
         $ticketsOrder->setVisitDate($order['visitDate']);
         $ticketsOrder->setVisitDuration($order['visitDuration']);
         $ticketsOrder->setValidate($order['validate']);
         foreach ($order['tickets'] as $orderedTicket) {
             $ticket = new Ticket();
             $ticket->setName($orderedTicket['name']);
             $ticket->setLongDescription($orderedTicket['longDescription']);
             $ticket->setShortDescription($orderedTicket['shortDescription']);
             $ticket->setPrice($orderedTicket['price']);
             foreach ($orderedTicket['details'] as $detail) {
                 $ticketDetail = new TicketDetail();
                 $ticketDetail->setNumber($detail['number']);
                 $ticketDetail->setAgeMin($detail['ageMin']);
                 $ticketDetail->setAgeMax($detail['ageMax']);
                 $visitor = new Visitor();
                 $visitor->setLastName($detail['visitor']['lastName']);
                 $visitor->setFirstName($detail['visitor']['firstName']);
                 $visitor->setCountry($detail['visitor']['country']);
                 $visitor->setBirthdate($detail['visitor']['birthdate']);
                 $ticketDetail->setVisitor($visitor);
                 $ticket->addTicketDetail($ticketDetail);
             }
             $ticketsOrder->addTicket($ticket);
         }
         $manager->persist($ticketsOrder);
     }
     $manager->flush();
 }
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $orders = array(array('ref' => 'AD5BF6C12356981F', 'visitDate' => new \DateTime('2015-11-13'), 'visitDuration' => 'JOURNEE', 'validate' => false, 'tickets' => array(array('name' => 'Normal', 'longDescription' => 'De 12 ans à 59 ans', 'shortDescription' => '12 à 59 ans', 'price' => 16.0, 'details' => array(array('number' => 1, 'ageMin' => 12, 'ageMax' => 59, 'visitor' => array('lastName' => 'DUPONT', 'firstName' => 'Alain', 'country' => 'France', 'birthdate' => new \DateTime('1970-02-17'))))), array('name' => 'Réduit', 'longDescription' => 'A partir de 12 ans', 'shortDescription' => 'Plus de 12 ans', 'price' => 10.0, 'details' => array(array('number' => 1, 'ageMin' => 12, 'ageMax' => 999, 'visitor' => array('lastName' => 'DUPONT', 'firstName' => 'Hélène', 'country' => 'Belgique', 'birthdate' => new \DateTime('1967-11-12'))))))), array('ref' => 'DFE3A25C43123B2A', 'visitDate' => new \DateTime('2015-11-14'), 'visitDuration' => 'DEMI_JOURNEE', 'validate' => false, 'tickets' => array(array('name' => 'Famille', 'longDescription' => 'Famille (2 adultes et 2 enfants de même nom de famille', 'shortDescription' => 'Famille: 2adu./2enf.', 'price' => 35.0, 'details' => array(array('number' => 1, 'ageMin' => 12, 'ageMax' => 999, 'visitor' => array('lastName' => 'FRANCE', 'firstName' => 'Lucien', 'country' => 'France', 'birthdate' => new \DateTime('1953-06-11'))), array('number' => 1, 'ageMin' => 12, 'ageMax' => 999, 'visitor' => array('lastName' => 'FRANCE', 'firstName' => 'Lucie', 'country' => 'France', 'birthdate' => new \DateTime('1959-11-06'))), array('number' => 3, 'ageMin' => 4, 'ageMax' => 11, 'visitor' => array('lastName' => 'FRANCE', 'firstName' => 'Paul', 'country' => 'France', 'birthdate' => new \DateTime('2004-02-06'))), array('number' => 3, 'ageMin' => 4, 'ageMax' => 11, 'visitor' => array('lastName' => 'FRANCE', 'firstName' => 'Claire', 'country' => 'France', 'birthdate' => new \DateTime('2007-05-15'))))))), array('ref' => 'EAABC456A234B6FA', 'visitDate' => new \DateTime('2016-01-02'), 'visitDuration' => 'JOURNEE', 'validate' => true, 'tickets' => array(array('name' => 'Sénior', 'longDescription' => 'A partir de 60 ans', 'shortDescription' => 'Plus de 60 ans', 'price' => 12.0, 'details' => array(array('number' => 1, 'ageMin' => 60, 'ageMax' => 999, 'visitor' => array('lastName' => 'MICHOU', 'firstName' => 'Michelle', 'country' => 'France', 'birthdate' => new \DateTime('1953-02-14'))))))));
     foreach ($orders as $order) {
         $ticketsOrder = new TicketsOrder();
         $ticketsOrder->setRef($order['ref']);
         $ticketsOrder->setVisitDate($order['visitDate']);
         $ticketsOrder->setVisitDuration($order['visitDuration']);
         $ticketsOrder->setValidate($order['validate']);
         foreach ($order['tickets'] as $orderedTicket) {
             $ticket = new Ticket();
             $ticket->setName($orderedTicket['name']);
             $ticket->setLongDescription($orderedTicket['longDescription']);
             $ticket->setShortDescription($orderedTicket['shortDescription']);
             $ticket->setPrice($orderedTicket['price']);
             foreach ($orderedTicket['details'] as $detail) {
                 $ticketDetail = new TicketDetail();
                 $ticketDetail->setNumber($detail['number']);
                 $ticketDetail->setAgeMin($detail['ageMin']);
                 $ticketDetail->setAgeMax($detail['ageMax']);
                 $visitor = new Visitor();
                 $visitor->setLastName($detail['visitor']['lastName']);
                 $visitor->setFirstName($detail['visitor']['firstName']);
                 $visitor->setCountry($detail['visitor']['country']);
                 $visitor->setBirthdate($detail['visitor']['birthdate']);
                 $ticketDetail->setVisitor($visitor);
                 $ticket->addTicketDetail($ticketDetail);
             }
             $ticketsOrder->addTicket($ticket);
         }
         $manager->persist($ticketsOrder);
     }
     $manager->flush();
 }
 /**
  * @return int
  */
 private function createOrder()
 {
     $order = new TicketsOrder();
     $order->setRef('AZERTY1234AZE123');
     $order->setVisitDate(new \DateTime('2031-04-17'));
     $order->setVisitDuration('DEMI_JOURNEE');
     $this->entityManager->persist($order);
     $this->entityManager->flush();
     return $order->getId();
 }
Пример #9
0
 public function getMessage(TicketsOrder $order, $data)
 {
     $attachement = \Swift_Attachment::newInstance($data, 'billets.pdf', 'application/pdf');
     $message = \Swift_Message::newInstance()->setFrom('*****@*****.**')->setTo($order->getMail())->setSubject('Billets du Louvre - Votre commande')->setBody('<p>Bonjour,</p><p>Voici vos billets</p>', 'text/html')->attach($attachement);
     return $message;
 }
 private function getOrder()
 {
     $order = new TicketsOrder();
     $order->setRef('AD5BF6C12356981F');
     $order->setVisitDate(new \DateTime('2015-11-13'));
     $order->setVisitDuration('JOURNEE');
     $order->setMail('*****@*****.**');
     $order->setValidate(false);
     $ticket = new Ticket();
     $ticket->setName('Normal');
     $ticket->setLongDescription('De 12 ans à 59 ans');
     $ticket->setShortDescription('12 à 59 ans');
     $ticket->setPrice(16.0);
     $detail = new TicketDetail();
     $detail->setAgeMin(12);
     $detail->setAgeMax(59);
     $visitor = new Visitor();
     $visitor->setFirstName('Alain');
     $visitor->setLastName('DUPONT');
     $visitor->setCountry('Belgique');
     $visitor->setBirthdate(new \DateTime('1970-02-17'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $order->addTicket($ticket);
     $ticket = new Ticket();
     $ticket->setName('Famille');
     $ticket->setLongDescription('Famille (2 adultes et 2 enfants de même nom de famille');
     $ticket->setShortDescription('Famille: 2adu./2enf.');
     $ticket->setPrice(35.0);
     $detail = new TicketDetail();
     $detail->setAgeMin(12);
     $detail->setAgeMax(999);
     $visitor = new Visitor();
     $visitor->setFirstName('Lucien');
     $visitor->setLastName('FRANCE');
     $visitor->setCountry('France');
     $visitor->setBirthdate(new \DateTime('1953-06-11'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $detail = new TicketDetail();
     $detail->setAgeMin(12);
     $detail->setAgeMax(999);
     $visitor = new Visitor();
     $visitor->setFirstName('Lucie');
     $visitor->setLastName('FRANCE');
     $visitor->setCountry('France');
     $visitor->setBirthdate(new \DateTime('1959-11-06'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $detail = new TicketDetail();
     $detail->setAgeMin(4);
     $detail->setAgeMax(11);
     $visitor = new Visitor();
     $visitor->setFirstName('Paul');
     $visitor->setLastName('FRANCE');
     $visitor->setCountry('France');
     $visitor->setBirthdate(new \DateTime('2004-02-06'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $detail = new TicketDetail();
     $detail->setAgeMin(4);
     $detail->setAgeMax(11);
     $visitor = new Visitor();
     $visitor->setFirstName('Claire');
     $visitor->setLastName('FRANCE');
     $visitor->setCountry('France');
     $visitor->setBirthdate(new \DateTime('2007-05-15'));
     $detail->setVisitor($visitor);
     $ticket->addTicketDetail($detail);
     $order->addTicket($ticket);
     return $order;
 }
 public function testControlVisitorData()
 {
     $detail = new TicketDetail();
     $detail->setAgeMin(10);
     $detail->setAgeMax(15);
     $visitorData = array('birthdate' => new \DateTime('2000/01/01'));
     $order = new TicketsOrder();
     try {
         $order->setVisitDate(new \DateTime('2010-01-01'));
         $this->dataValidator->controlVisitorData($order, $detail, $visitorData);
         $order->setVisitDate(new \DateTime('2015-12-31'));
         $this->dataValidator->controlVisitorData($order, $detail, $visitorData);
     } catch (HttpException $e) {
         $this->fail('Do not have an Exception');
     }
     try {
         $order->setVisitDate(new \DateTime('2009-12-31'));
         $this->dataValidator->controlVisitorData($order, $detail, $visitorData);
         $this->fail('Must throw an exception 400');
     } catch (HttpException $e) {
         $this->assertEquals(400, $e->getStatusCode());
     }
     try {
         $order->setVisitDate(new \DateTime('2016-01-01'));
         $this->dataValidator->controlVisitorData($order, $detail, $visitorData);
         $this->fail('Must throw an exception 400');
     } catch (HttpException $e) {
         $this->assertEquals(400, $e->getStatusCode());
     }
 }