From dea00bf227eaa335400d4e403756f26126984ccf Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Wed, 23 Oct 2024 15:06:07 +0200 Subject: [PATCH] Add WalletGatewayService --- .../Economy/Payment/WalletGatewayService.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/Library/Economy/Payment/WalletGatewayService.php diff --git a/src/Library/Economy/Payment/WalletGatewayService.php b/src/Library/Economy/Payment/WalletGatewayService.php new file mode 100644 index 0000000..63fa5a8 --- /dev/null +++ b/src/Library/Economy/Payment/WalletGatewayService.php @@ -0,0 +1,44 @@ +getCurrency()); + $statements = $this->walletStatementRepository->findByAccounting($accounting); + + foreach ($statements as $statement) { + $transaction = $statement->getTransaction(); + $money = Brick\Money::ofMinor( + $transaction->getMoney()->amount, + $transaction->getMoney()->currency + ); + + switch ($statement->getDirection()) { + case WalletStatementDirection::Incoming: + $available = $available->plus($money); + break; + case WalletStatementDirection::Outgoing: + $available = $available->minus($money); + break; + } + } + + return new Money( + $available->getMinorAmount()->toInt(), + $available->getCurrency()->getCurrencyCode() + ); + } +}