diff --git a/app/Classes/Modules/Transactions/Processors/CreateWalletTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateWalletTransactionProcessor.php index 4bde6135..7297c670 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateWalletTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateWalletTransactionProcessor.php @@ -2,30 +2,15 @@ namespace App\Classes\Modules\Transactions\Processors; -use App\Classes\Modules\Bookings\Services\CalculatesBookingPayableAmount; -use App\Classes\Modules\Bookings\Services\CalculatesBookingTransferredAmount; -use App\Classes\Modules\ServiceTypes\Services\FetchesServiceConfigurations; -use App\Classes\Modules\Transactions\Services\ListsTransactions; +use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; use App\Classes\Modules\Transactions\Services\CreatesWalletTransaction; use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; -use App\Classes\Modules\Bookings\Services\CalculatesBookingPaidAmount; -use App\Classes\Modules\Bookings\Services\CalculatesBookingCurrencyAverageRate; -use App\Classes\Modules\Companies\Services\FetchesCompany; -use App\Classes\Modules\Documents\Services\CreatesDocument; -use App\Classes\Modules\Documents\Services\CreatesFiles; -use App\Classes\Modules\Bookings\Services\UpdatesBookingStatus; -use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; - use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\SegmentConstants; use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\ValueObjects\Constants\PaymentMethodType; use App\Models\Wallet; -use App\Models\Document; -use App\Models\SegmentConstant; -use Meneses\LaravelMpdf\Facades\LaravelMpdf; class CreateWalletTransactionProcessor { diff --git a/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php index 95f484a0..7c7277f8 100644 --- a/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php @@ -2,35 +2,16 @@ namespace App\Classes\Modules\Transactions\Processors; -use App\Classes\Modules\Bookings\Services\CalculatesBookingPayableAmount; -use App\Classes\Modules\Bookings\Services\CalculatesBookingTransferredAmount; -use App\Classes\Modules\ServiceTypes\Services\FetchesServiceConfigurations; -use App\Classes\Modules\Transactions\Services\ListsTransactions; -use App\Classes\Modules\Transactions\Services\CreatesWalletTransaction; -use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; -use App\Classes\Modules\Bookings\Services\CalculatesBookingPaidAmount; -use App\Classes\Modules\Bookings\Services\CalculatesBookingCurrencyAverageRate; -use App\Classes\Modules\Companies\Services\FetchesCompany; -use App\Classes\Modules\Documents\Services\CreatesDocument; -use App\Classes\Modules\Documents\Services\CreatesFiles; -use App\Classes\Modules\Bookings\Services\UpdatesBookingStatus; - use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; use App\Classes\Modules\Transactions\Services\FetchesTransaction; use App\Classes\Modules\Wallets\Services\FetchesWallet; use App\Classes\Modules\Wallets\Services\UpdatesWallet; use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; - use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; use App\Classes\ValueObjects\Constants\ApprovalStatus; -use App\Classes\ValueObjects\Constants\SegmentConstants; use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\ValueObjects\Constants\PaymentMethodType; use App\Models\Wallet; -use App\Models\Document; -use App\Models\SegmentConstant; -use Meneses\LaravelMpdf\Facades\LaravelMpdf; class UpdateWalletTransactionProcessor { @@ -65,7 +46,18 @@ class UpdateWalletTransactionProcessor $transaction = $this->fetchesTransaction->execute(['id' => $transactionId]); $wallet = $transaction->wallet; - $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $transaction->amount); + switch($transaction->type){ + case TransactionType::TOP_UP: + $updateWalletAmount = $transaction->amount + $wallet->amount; + break; + case TransactionType::WITHDRAW: + $updateWalletAmount = $wallet->amount - $transaction->amount; + break; + default: + break; + } + + $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); $this->updatesTransactionStatus->execute($transaction, $transactionStatus); diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php index f0a16958..9a613b43 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php @@ -63,22 +63,14 @@ class CreateWalletLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { + $object = new WalletObject($request->input('company_id'), $request->input('currency_id'), $this->generatesWalletCode->execute()); - DB::beginTransaction(); + $this->canCreateCompanyWallet->passes($object); + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); - $object = new WalletObject($request->input('company_id'), $request->input('currency_id'), $this->generatesWalletCode->execute()); - - $this->canCreateCompanyWallet->passes($object); - - $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); - - $wallet = $this->createsWallet->execute($object, $company); - - DB::commit(); - - return $this->resourceResponse(new WalletResource($wallet)); - + $wallet = $this->createsWallet->execute($object, $company); + return $this->resourceResponse(new WalletResource($wallet)); } } diff --git a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php index 817a9038..8497ec32 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php @@ -9,7 +9,7 @@ use App\Classes\Modules\Wallets\Services\ListsWallet; use App\Classes\Modules\Wallets\Services\FetchesWallet; use App\Classes\ValueObjects\Constants\TransactionType; -use App\Classes\Modules\Wallets\Standards\Rules\CanListWallet; +use App\Classes\Modules\Wallets\Standards\Rules\CanTopUpWallet; use App\Http\Resources\WalletResource; use App\Classes\Modules\Transactions\Processors\CreateWalletTransactionProcessor; @@ -30,13 +30,13 @@ class TopUpWalletLogic extends AbstractControllerLogic ]; } - /** @var ListWallet */ + /** @var FetchesWallet */ private $fetchesWallet; - /** @var CanCreateCompanyWallet */ - private $canListWallet; + /** @var CanTopUpWallet */ + private $canTopUpWallet; - /** @var CreateInvoiceTransactionProcessor */ + /** @var CreateWalletTransactionProcessor */ private $createWalletTransactionProcessor; /** @@ -45,8 +45,9 @@ class TopUpWalletLogic extends AbstractControllerLogic * @param GeneratesWalletCode $generatesWalletCode * @param CanCreateCompanyWallet $canCreateCompanyWallet */ - public function __construct(FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor) + public function __construct(CanTopUpWallet $canTopUpWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor) { + $this->canTopUpWallet = $canTopUpWallet; $this->fetchesWallet = $fetchesWallet; $this->createWalletTransactionProcessor = $createWalletTransactionProcessor; } @@ -58,13 +59,14 @@ class TopUpWalletLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - //$this->canListWallet->passes(); $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount')); + + $this->canTopUpWallet->passes($walletOject); + $transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::TOP_UP); return $this->resourceResponse(new WalletResource($wallet)); - } } diff --git a/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php index 3a2bb21a..b1491ab7 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php @@ -9,7 +9,7 @@ use App\Classes\Modules\Wallets\Services\ListsWallet; use App\Classes\Modules\Wallets\Services\FetchesWallet; use App\Classes\ValueObjects\Constants\TransactionType; -use App\Classes\Modules\Wallets\Standards\Rules\CanListWallet; +use App\Classes\Modules\Wallets\Standards\Rules\CanWithdrawWallet; use App\Http\Resources\WalletResource; use App\Classes\Modules\Transactions\Processors\CreateWalletTransactionProcessor; @@ -30,13 +30,13 @@ class WithdrawWalletLogic extends AbstractControllerLogic ]; } - /** @var ListWallet */ + /** @var FetchesWallet */ private $fetchesWallet; - /** @var CanCreateCompanyWallet */ - private $canListWallet; + /** @var CanWithdrawWallet */ + private $canWithdrawWallet; - /** @var CreateInvoiceTransactionProcessor */ + /** @var CreateWalletTransactionProcessor */ private $createWalletTransactionProcessor; /** @@ -45,8 +45,9 @@ class WithdrawWalletLogic extends AbstractControllerLogic * @param GeneratesWalletCode $generatesWalletCode * @param CanCreateCompanyWallet $canCreateCompanyWallet */ - public function __construct(FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor) + public function __construct(CanWithdrawWallet $canWithdrawWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor) { + $this->canWithdrawWallet = $canWithdrawWallet; $this->fetchesWallet = $fetchesWallet; $this->createWalletTransactionProcessor = $createWalletTransactionProcessor; } @@ -58,13 +59,14 @@ class WithdrawWalletLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - //$this->canListWallet->passes(); $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount')); + + $this->canWithdrawWallet->passes($walletOject); + $transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::WITHDRAW); return $this->resourceResponse(new WalletResource($wallet)); - } } diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWallet.php b/app/Classes/Modules/Wallets/Services/UpdatesWallet.php index 24ce2415..8b268fab 100644 --- a/app/Classes/Modules/Wallets/Services/UpdatesWallet.php +++ b/app/Classes/Modules/Wallets/Services/UpdatesWallet.php @@ -16,7 +16,7 @@ class UpdatesWallet extends AbstractUpdateRecord * @throws \App\Classes\Exceptions\MalformedRequestException */ public function execute(Wallet $model, WalletObject $object) { - $model->amount += $object->getAmount(); + $model->amount = $object->getAmount(); $model->code = $object->getCode(); $model->currency_id = $object->getCurrency();