'Delete Paid Group Transaction', 'message' => 'You have successfully deleted this Group Transaction' ]; } /** @var FetchesGroup */ private $fetchesGroup; /** @var DeletesGroup */ private $deletesGroup; /** * DeleteGroupLogic constructor. * @param updatesTransactionStatus $updatesTransactionStatus * @param FetchesGroup $fetchesGroup * @param DeletesTransaction $deletesTransaction */ public function __construct(FetchesGroup $fetchesGroup, DeletesGroup $deletesGroup) { $this->fetchesGroup = $fetchesGroup; $this->deletesGroup = $deletesGroup; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\MalformedRequestException */ public function logic(Request $request): JsonResponse { $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); foreach ($group->groupTransactions as $groupTransaction) { $invoice = $groupTransaction->transaction; $paymentTransaction = $invoice->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first(); if ($paymentTransaction->payment_method == PaymentMethodType::WALLET) { // Store the transaction ID before deleting $transactionId = Transaction::where('bill_no', $paymentTransaction->payment_reference)->first()->id; // Delete the transaction Transaction::where('id', $transactionId)->first()->delete(); // Now you have the transaction ID available in $transactionId Log::channel('deletePaidGroupOrder')->info("Deleted payment reference transaction ID: " . $transactionId); } else { Log::channel('deletePaidGroupOrder')->info("no transaction found. Invoice Id ->" . $invoice->id); } // Store the transaction ID before deleting $transactionId = $paymentTransaction->id; // Delete the payment transaction $paymentTransaction->delete(); Log::channel('deletePaidGroupOrder')->info("Deleted payment transaction ID: " . $transactionId); } Log::channel('deletePaidGroupOrder')->info("Deleted Group -> " . $group->id); $this->deletesGroup->execute($group); return $this->response([]); } }