Fix a problem with storage invoice checking when a payment related transaction is deleted at order page

This commit is contained in:
Dillon Ngo
2024-03-15 03:33:58 +08:00
parent f1b8c6a556
commit 5de2554d63
2 changed files with 21 additions and 2 deletions
@@ -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;
@@ -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]);