public function notify(RequestVerifiedEvent $event)
 {
     $payment = $event->getPayment();
     $status = $event->getStatus()->getValue();
     switch ($status) {
         case GetHumanStatus::STATUS_AUTHORIZED:
         case GetHumanStatus::STATUS_CAPTURED:
         case GetHumanStatus::STATUS_REFUNDED:
             $this->repository->clearCart();
             $type = 'success';
             break;
         case GetHumanStatus::STATUS_CANCELED:
         case GetHumanStatus::STATUS_EXPIRED:
         case GetHumanStatus::STATUS_FAILED:
             $type = 'danger';
             break;
         case GetHumanStatus::STATUS_PENDING:
         case GetHumanStatus::STATUS_SUSPENDED:
             $this->repository->clearCart();
             $type = 'warning';
             break;
         case GetHumanStatus::STATUS_NEW:
         case GetHumanStatus::STATUS_UNKNOWN:
             $this->repository->clearCart();
             $type = 'info';
             break;
         default:
             throw new \RuntimeException('Unknown status ' . $status);
     }
     $formatter = new \NumberFormatter($this->translator->getLocale(), \NumberFormatter::CURRENCY);
     $this->session->getFlashBag()->add($type, $this->translator->trans('flash.payment.' . $type, ['%status%' => $this->translator->trans('meta.status.' . $status), '%amount%' => $formatter->formatCurrency($payment->getTotalAmount() / 100, $payment->getCurrencyCode())]));
 }
Example #2
0
 public function createOrder(CreateOrderCommand $command)
 {
     $cart = $this->cartRepository->getCart();
     if ($cart->getLineItems()->count() === 0) {
         throw new \RuntimeException("The cart is empty");
     }
     $address = $command->getAddress();
     $order = new Order(new UuidIdentity(Uuid::uuid4()), $this->tokenStorage->getToken()->getUser(), new Address($address->getCountry(), $address->getCity(), $address->getStreet(), $address->getZipCode()));
     foreach ($cart->getLineItems() as $lineItem) {
         $order->addProduct($lineItem->getProduct(), $lineItem->getQuantity());
     }
     $this->orderRepository->save($order);
     $event = new OrderCreatedEvent($order, $command->getGatewayName());
     $this->eventBus->handle($event);
 }
Example #3
0
 public function removeProduct(RemoveProductCommand $command)
 {
     $cart = $this->repository->getCart();
     $cart->removeProduct(new UuidIdentity($command->getId()));
     $this->repository->setCart($cart);
 }