Exemplo n.º 1
0
 public function handle(DepositCommand $command)
 {
     $account = $this->accounting->getAccount(AccountNumber::fromString($command->getAccountNumber()));
     $deposit = new Deposit(Transaction::generate(), $command->getAmount());
     $account->deposit($deposit);
     $this->accounting->commit();
 }
Exemplo n.º 2
0
 public function handle(WithdrawCommand $command)
 {
     $account = $this->accounting->getAccount(AccountNumber::fromString($command->getAccountNumber()));
     $withdraw = new Withdraw(Transaction::generate(), $command->getAmount());
     $account->withdraw($withdraw);
     $this->accounting->commit();
 }
Exemplo n.º 3
0
 public function handle(TransferCommand $command)
 {
     $account = $this->accounting->getAccount(AccountNumber::fromString($command->getSourceAccountNumber()));
     $transfer = new Transfer(Transaction::generate(), AccountNumber::fromString($command->getTargetAccountNumber()), $command->getAmount());
     $account->transfer($transfer);
     $this->accounting->commit();
 }
 function it_appends_deposit_entry_when_money_were_withdrawn()
 {
     $accountNumber = AccountNumber::fromString('123ABC');
     $openAccount = new AccountOpenedEvent($accountNumber);
     $this->onAccountOpened(AccountOpenedEnvelope::wrap($openAccount));
     $withdraw = new MoneyWereWithdrawnEvent($accountNumber, new Withdraw(Transaction::generate(), 100));
     $this->onMoneyWereWithdrawn(MoneyWereWithdrawnEnvelope::wrap($withdraw));
     $this->getAccount('123ABC')->getHistory()[1]->getAmount()->shouldReturn(100);
 }
 function it_decreases_balance_when_money_were_withdrawn()
 {
     $accountNumber = AccountNumber::fromString('123ABC');
     $openAccount = new AccountOpenedEvent($accountNumber);
     $event = AccountOpenedEnvelope::wrap($openAccount);
     $this->onAccountOpened($event);
     $withdraw = new MoneyWereWithdrawnEvent($accountNumber, new Withdraw(Transaction::generate(), 100));
     $event = MoneyWereWithdrawnEnvelope::wrap($withdraw);
     $this->onMoneyWereWithdrawn($event);
     $this->getAccount('123ABC')->getBalance()->shouldReturn(-100);
 }