/**
  * This event is handled after a successful funds transfer
  *
  * It will send an email to both members, summarizing their last account
  * transaction
  *
  * @param TransferFundsNotification $notification
  * @return bool
  */
 public function notify(TransferFundsNotification $notification)
 {
     $fromMember = $this->members->with($notification->fromMemberId());
     $toMember = $this->members->with($notification->toMemberId());
     $this->sender->sendFundsTransferredEmail($fromMember->information(), $toMember->information(), $notification->amount(), $notification->occurredOn());
     $this->sender->sendDepositReceivedEmail($fromMember->information(), $toMember->information(), $notification->amount(), $notification->occurredOn());
 }
 /**
  * @param TransferFundsRequest $request
  */
 public function transfer(TransferFundsRequest $request)
 {
     $fromMember = $this->members->with($request->fromMemberId());
     $toMember = $this->members->with($request->toMemberId());
     $fromMember->transfer($request->amount(), $toMember);
     $this->members->update($fromMember);
     $this->members->update($toMember);
     $this->publisher()->publish($fromMember->events());
     $this->notifier()->transferCompleted(new TransferFundsResponse($fromMember, $toMember));
 }
 function it_should_transfer_funds_between_accounts(Members $members, TransferFundsNotifier $notifier)
 {
     $fromMember = A::member()->withBalance(2000)->build();
     $toMember = A::member()->withBalance(1000)->build();
     $members->with($fromMember->information()->id())->willReturn($fromMember);
     $members->with($toMember->information()->id())->willReturn($toMember);
     $members->update($fromMember)->shouldBeCalled();
     $members->update($toMember)->shouldBeCalled();
     $this->beConstructedWith($members);
     $this->attach($notifier);
     $this->transfer(TransferFundsRequest::from(['fromMemberId' => (string) $fromMember->information()->id(), 'toMemberId' => (string) $toMember->information()->id(), 'amount' => 5]));
     $notifier->transferCompleted(Argument::type(TransferFundsResponse::class))->shouldHaveBeenCalled();
 }