HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/qas.sports-crowd.com/app/Http/Controllers/PaymentTransactionController.php
<?php

namespace App\Http\Controllers;

use App\Core\Payment\Application\PaymentTransactionService;
use App\PaymentTransaction;
use Carbon\Carbon;

class PaymentTransactionController extends Controller
{
    private $paymentTransactionService;

    public function __construct()
    {
        $this->paymentTransactionService = new PaymentTransactionService();
    }

    public function updatePaymentTransactionByReference($paymentReference, $paymentState, $paymentComment, $paymentTransactionId)
    {
        $paymentTransaction = PaymentTransaction::when($paymentReference, function ($query) use ($paymentReference) {
            return $query->where('reference', $paymentReference);
        })
            ->when($paymentTransactionId, function ($query) use ($paymentTransactionId) {
                return $query->orWhere('gateway_transaction_id', $paymentTransactionId);
            })
            ->first();

        if ($paymentTransaction == null) {
            return false;
        }
        $paymentTransaction->state = $paymentState;
        $paymentTransaction->comment = $paymentComment;
        $paymentTransaction->gateway_transaction_id = $paymentTransactionId;
        $paymentTransaction->payment_date = new \DateTime();
        $paymentTransaction->reference = $paymentReference;
        $paymentTransaction->update();

        if ($paymentState == 'CONFIRMED') {
            if ($paymentTransaction->origin_class && !$paymentTransaction->finish_payment) {
                $paymentTransaction->update(['finish_payment' => true]);
                $originClass = new $paymentTransaction->origin_class;
                $originClass->finishPayment($paymentTransaction);
            }
        }
    }

    public function updatePendingStatusTransaction($paymentTransaction, $add_time = false)
    {
        $add_time_text = $add_time ? '_' . microtime(true) : '';
        if ($paymentTransaction->reference) {
            $reference = explode('_', $paymentTransaction->reference);
            array_pop($reference);
            $paymentTransaction->reference = (implode('_', $reference) . $add_time_text);
        } else
            $paymentTransaction->reference = strtoupper(hash("md5", $paymentTransaction->id)) . '_' . $paymentTransaction->pin . $add_time_text;
        $paymentTransaction->update();
    }

    public function validatePayments($validateHistoricalPayments = false)
    {
        $paymentTransactions = PaymentTransaction::where('state', '!=', 'CONFIRMED')->whereNotNull('gateway_payments_id')
            ->where(function ($query) use ($validateHistoricalPayments) {
                if ($validateHistoricalPayments) {
                    $query->where('payment_transactions.created_at', '>', Carbon::now()->subDays(3)->startOfDay());
                } else {
                    $query->where('payment_transactions.created_at', '>', Carbon::now()->subHours(3));
                }
            })
            ->get();

        foreach ($paymentTransactions as $paymentTransaction) {
            try {
                $this->paymentTransactionService->validatePayment($paymentTransaction);
            } catch (\Throwable $th) {
                $error = [
                    'paymentTransaction'    => $paymentTransaction,
                    'message'               => $th->getMessage(),
                    'getFile'               => $th->getFile(),
                    'getLine'               => $th->getLine(),
                ];
                $util = new UtilController;
                $util->logFile(json_encode($error));
            }
        }

        return array(
            'r' => true,
            'data' => null,
            'm' => 'Se validaron ' . count($paymentTransactions) . ' pagos pendientes.'
        );
    }


    public function validatePayment($paymentTransaction)
    {
        $this->paymentTransactionService->validatePayment($paymentTransaction);
    }
}