diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeletePaymentTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeletePaymentTransactionLogic.php index f1858f49..f2f6cc0b 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/DeletePaymentTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeletePaymentTransactionLogic.php @@ -6,10 +6,13 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transactions\Services\FetchesTransaction; use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; +use App\Classes\Modules\Transactions\Services\FetchesGroup; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Models\Transaction; +use App\Models\Wallet; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; class DeletePaymentTransactionLogic extends AbstractControllerLogic { @@ -24,6 +27,9 @@ class DeletePaymentTransactionLogic extends AbstractControllerLogic ]; } + /** @var FetchesGroup */ + private $fetchesGroup; + /** @var FetchesTransaction */ private $fetchesTransaction; @@ -35,11 +41,13 @@ class DeletePaymentTransactionLogic extends AbstractControllerLogic * SuspendTransactionLogic constructor. * @param FetchesTransaction $fetchesTransaction * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param FetchesGroup $fetchesGroup */ - public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus) + public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, FetchesGroup $fetchesGroup) { $this->fetchesTransaction = $fetchesTransaction; $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->fetchesGroup = $fetchesGroup; } @@ -47,6 +55,17 @@ class DeletePaymentTransactionLogic extends AbstractControllerLogic { $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + if($transaction->owner instanceof Wallet){ + try{ + $group = $this->fetchesGroup->execute(['reference' => $transaction->payment_reference]); + $group->status = ApprovalStatus::SUSPENDED; + $group->save(); + } + catch(\Exception $excaption){ + Log::info('No group associated with transaction with payment_reference - '.$transaction->payment_reference); + } + } + $transaction->delete(); $invoice = $transaction->owner; diff --git a/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php index d5c87ce0..0faca0d2 100644 --- a/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php @@ -328,7 +328,7 @@ class CheckStorageInvoiceTransactionProcessor private function updatePaymentTransactionViaGroupPayment($storageInvoice){ Log::channel('storage_invoices')->info('updatePaymentTransactionViaGroupPayment'); - $groups = $storageInvoice->groups()->get(); + $groups = $storageInvoice->groups()->whereNotIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::SUSPENDED])->get(); foreach ($groups as $grp){ $groupReference = $grp->reference; $walletTransaction = $this->fetchesTransaction->execute(['payment_reference' => $groupReference]);