Esempio n. 1
0
 /**
  * @param string $eventJson
  * @throws UnknownEventException
  */
 public function on(string $eventJson)
 {
     $data = json_decode($eventJson, true);
     if (!array_key_exists('name', $data) || $data['name'] !== Events::CUSTOMER_PLACED_ORDER) {
         throw UnknownEventException::unexpected(Events::CUSTOMER_PLACED_ORDER, $data['name']);
     }
     $this->orders->add(new Order(new OrderId($data['order_id']), new \DateTimeImmutable($data['date'])));
 }
Esempio n. 2
0
 /**
  * @param AcceptOrder $command
  * @throws OrderNotFoundException
  * @throws InvalidTransitionException
  */
 public function handle(AcceptOrder $command)
 {
     $order = $this->orders->getById(new OrderId($command->orderId()));
     $order->accept();
 }
Esempio n. 3
0
 /**
  * @param RefundOrder $command
  * @throws InvalidTransitionException
  * @throws OrderNotFoundException
  */
 public function handle(RefundOrder $command)
 {
     $order = $this->orders->getById(new OrderId($command->orderId()));
     $order->refund();
 }
Esempio n. 4
0
 /**
  * @param CreatePayment $command
  * @throws OrderNotFoundException
  */
 public function handle(CreatePayment $command)
 {
     $order = $this->orders->getById(new OrderId($command->orderId()));
     $this->payments->add(new Payment(new PaymentId($command->paymentId()), $order));
 }
Esempio n. 5
0
 function it_creates_new_customer_service_order_when_customer_place_order(Orders $orders)
 {
     $orders->add(Argument::type(Order::class))->shouldBeCalled();
     $this->on(json_encode(['name' => Events::CUSTOMER_PLACED_ORDER, 'order_id' => (string) OrderId::generate(), 'date' => '2015-01-01 12:12:12']));
 }
Esempio n. 6
0
 /**
  * @param PrepareOrder $command
  * @throws InvalidTransitionException
  */
 public function handle(PrepareOrder $command)
 {
     $order = $this->orders->getById(new OrderId($command->orderId()));
     $order->prepare();
 }