Example #1
1
 /**
  * Withdraw Money Command Handle
  *
  * Processes business logic for the withdraw money command.
  * @param  WithdrawMoney $command Command object.
  * @return MoneyWithdrawn         Event object.
  */
 protected function handleWithdrawMoney(WithdrawMoney $command)
 {
     $data = $command->getPayload();
     $withdrawal = new UsDollar($data->withdrawal);
     if ($withdrawal->getValue() < 0) {
         throw new MinimumWithdrawalException('You cannot withdraw a negative amount.');
     }
     if ($withdrawal->getValue() > $this->root->balance->getValue()) {
         throw new InsufficientFundsException(sprintf('Insufficient funds. You tried to withdraw $%s but only have $%s in your account.', $withdrawal->getValue(), $this->balance->getValue()));
     }
     return new MoneyWithdrawn($command->getId(), compact('withdrawal'));
 }