Example #1
0
 /**
  * @param Bill $bill
  * @return JsonResponse
  */
 public function payAction(Bill $bill)
 {
     try {
         $command = new PayBillCommand($bill);
         $this->commandBus->execute($command);
         return new JsonResponse(['bill' => $bill->getId(), 'has_been_paid' => $bill->hasBeenPaid()]);
     } catch (BillAlreadyPaidException $e) {
         throw new HttpException(409, $e->getMessage(), $e);
     }
 }
Example #2
0
 /**
  * @test
  */
 public function it_should_correctly_report_payment_status()
 {
     $bill = Bill::create($this->getAccount(), new \DateTime('now'));
     $this->assertSame(false, $bill->hasBeenPaid());
     $bill->pay();
     $this->assertSame(true, $bill->hasBeenPaid());
 }
Example #3
0
 /**
  * @return Bill
  */
 public function getBill()
 {
     $service = Service::fromName(new ProvidedService('foo'));
     $account = Account::open($service, new AccountNumber('abc123'), Money::fromFloat(20.0), new \DateTime('now'), new BillingPeriod('P30D'));
     $bill = Bill::create($account, new \DateTime('now'));
     $this->injectId($bill);
     return $bill;
 }
 /**
  * @param CreateBillsForAccountCommand $command
  * @return void
  */
 public function handle($command)
 {
     $account = $command->getAccount();
     $billingPeriod = new \DatePeriod($account->getBillingStartDate(), $account->getBillingInterval(), $account->dateToClose());
     foreach ($billingPeriod as $billDate) {
         $bill = Bill::create($account, $billDate);
         $this->billRepository->save($bill);
     }
 }
 /**
  * @test
  */
 public function it_should_pay_a_bill()
 {
     $dispatcher = $this->getMockForAbstractClass('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $account = $this->getMockBuilder('\\HCLabs\\Bills\\Model\\Account')->disableOriginalConstructor()->getMock();
     $charge = Money::fromInteger(2000);
     $account->expects($this->once())->method('getRecurringCharge')->willReturn($charge);
     $billRepository = new BillRepository();
     $commandHandler = new PayBillCommandHandler($dispatcher, $billRepository);
     $bill = Bill::create($account, new \DateTime('tomorrow'));
     $command = new PayBillCommand($bill);
     $this->assertFalse($bill->hasBeenPaid());
     $commandHandler->handle($command);
     $this->assertTrue($bill->hasBeenPaid());
 }