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/demo.sports-crowd.com/app/Core/Payment/PaymentMethodContext.php
<?php

declare(strict_types=1);

namespace App\Core\Payment;

use App\Core\Academy\Application\AcademyPurchaseService;
use App\Core\Academy\Application\AcademyTournamentPaymentService;
use App\Core\Academy\Application\ExperiencePaymentService;
use App\Core\Academy\Application\MembershipOrderService;
use App\Core\Order\Application\OrderService;
use App\Core\Payment\Entities\Payment;
use App\Core\Payment\Entities\PaymentRetrieveResponse;
use App\Core\Payment\Exceptions\PaymentMethodException;
use App\Core\Payment\Methods\Nmi\NmiStrategy;
use App\Core\Payment\Methods\Nuvei\NuveiStrategy;
use App\Core\Payment\Methods\Onepay\OnepayFanaticadasStrategy;
use App\Core\Payment\Methods\Onepay\OnepayStrategy;
use App\Core\Payment\Methods\Onvo\OnvoStrategy;
use App\Core\Payment\Methods\Openpay\OpenpayCardStrategy;
use App\Core\Payment\Methods\Openpay\OpenpayPseStrategy;
use App\Core\Payment\Methods\Pagoplux\PagopluxStrategy;
use App\Core\Payment\Methods\PayU\PayUStrategy;
use App\Core\Payment\Methods\PlaceToPay\PlaceToPayCaliStrategy;
use App\Core\Payment\Methods\PlaceToPay\PlaceToPayStrategy;
use App\Core\Payment\Methods\Stripe\StripeStrategy;
use App\Core\Payment\Methods\Webpay\WebpayStrategy;
use App\Core\Payment\Methods\Wompi\WompiStrategy;
use App\Core\Payment\Methods\WompiApi\WompiApiStrategy;
use App\Core\Payment\Methods\Yappy\YappyStrategy;
use App\Core\Payment\Methods\ZonaPagos\ZonaPagosStrategy;
use App\Core\Ticket\Application\TicketService;
use App\GatewayPayment;

class PaymentMethodContext
{
    private $strategy;
    private $gatewayParameters;
    private $orderService;
    private $ticketService;
    private $academyPurchaseService;
    private $academyTournamentPaymentService;
    private $membershipOrderService;
    private $experiencePaymentService;

    public function __construct(
        array $gatewayParameters
    ) {
        $this->orderService = new OrderService();
        $this->ticketService = new TicketService();
        $this->academyPurchaseService = new AcademyPurchaseService();
        $this->academyTournamentPaymentService = new AcademyTournamentPaymentService();
        $this->membershipOrderService = new MembershipOrderService();
        $this->experiencePaymentService = new ExperiencePaymentService();
        $this->gatewayParameters = (object) $gatewayParameters;
        $this->gatewayParameters->extraConfirmUrlData = [];
        $this->gatewayParameters->marketplaceId = null;

        switch ($this->gatewayParameters->page_response_for_gateway) {
            case 'wompi':
                $this->strategy = new WompiStrategy($this->gatewayParameters);
                break;

            case 'placetopay':
                $this->strategy = new PlaceToPayStrategy($this->gatewayParameters);
                break;

            case 'stripe':
                $this->strategy = new StripeStrategy($this->gatewayParameters);
                break;

            case 'zonapagos':
                $this->strategy = new ZonaPagosStrategy($this->gatewayParameters);
                break;

            case 'onvo':
                $this->strategy = new OnvoStrategy($this->gatewayParameters);
                break;

            case 'wompiapi':
                $this->strategy = new WompiApiStrategy($this->gatewayParameters);
                break;

            case 'openpaycard':
                $this->strategy = new OpenpayCardStrategy($this->gatewayParameters);
                break;

            case 'openpaypse':
                $this->strategy = new OpenpayPseStrategy($this->gatewayParameters);
                break;

            case 'nmi':
                $this->strategy = new NmiStrategy($this->gatewayParameters);
                break;

            case 'yappy':
                $this->strategy = new YappyStrategy($this->gatewayParameters);
                break;

            case 'webpay':
                $this->strategy = new WebpayStrategy($this->gatewayParameters);
                break;

            case 'nuvei':
                $this->strategy = new NuveiStrategy($this->gatewayParameters);
                break;

            case 'pagoplux':
                $this->strategy = new PagopluxStrategy($this->gatewayParameters);
                break;

            case 'placetopaycali':
                $this->strategy = new PlaceToPayCaliStrategy($this->gatewayParameters);
                break;

            case 'onepay':
                $this->strategy = new OnepayStrategy($this->gatewayParameters);
                break;

            case 'onepayfanaticadas':
                $this->strategy = new OnepayFanaticadasStrategy($this->gatewayParameters);
                break;

            case 'payu':
                $this->strategy = new PayUStrategy($this->gatewayParameters);
                break;

            default:
                throw new PaymentMethodException(
                    sprintf(
                        "The payment method '%s' does not exist or is not implemented.",
                        $this->gatewayParameters->page_response_for_gateway
                    )
                );
                break;
        }
    }

    public static function init(int $paymentGatewayId)
    {
        $gatewayData = GatewayPayment::findOrFail($paymentGatewayId);
        return new self($gatewayData->toArray());
    }

    public function parameters()
    {
        return clone $this->gatewayParameters;
    }

    public function payOrder($order)
    {
        $payment = $this->orderService->buildPayment($order);
        return $this->strategy->pay($payment);
    }

    public function payTicket($ticket)
    {
        $payment = $this->ticketService->buildPayment($ticket);
        return $this->strategy->pay($payment);
    }

    public function payAcademyPurchase($academyPurchase)
    {
        $payment = $this->academyPurchaseService->buildPayment($academyPurchase);
        return $this->strategy->pay($payment);
    }

    public function payAcademyTournament($academyTournament)
    {
        $payment = $this->academyTournamentPaymentService->buildPayment($academyTournament);
        return $this->strategy->pay($payment);
    }

    public function payMembership($membershipOrder)
    {
        $payment = $this->membershipOrderService->buildPayment($membershipOrder);
        return $this->strategy->pay($payment);
    }

    public function payExperience($experience)
    {
        $payment = $this->experiencePaymentService->buildPayment($experience);
        return $this->strategy->pay($payment);
    }

    public function retrieve(Payment $payment)
    {
        if (is_null($payment->paymentGatewayId())) {
            return PaymentRetrieveResponse::createPending();
        }
        return $this->strategy->retrieve($payment);
    }

    public function retrieveOrderPayment($order)
    {
        if (is_null($order->gateway_payments_id)) {
            return PaymentRetrieveResponse::createPending();
        }
        $payment = $this->orderService->buildPayment($order);
        return $this->strategy->retrieve($payment);
    }

    public function retrieveTicketPayment($ticket)
    {
        if (is_null($ticket->gateway_payments_id)) {
            return PaymentRetrieveResponse::createPending();
        }
        $payment = $this->ticketService->buildPayment($ticket);
        return $this->strategy->retrieve($payment);
    }

    public function setExtraConfirmUrlData(array $extraConfirmUrlData): void
    {
        $this->gatewayParameters->extraConfirmUrlData = $extraConfirmUrlData;
    }

    public function setMarketplaceId($marketplaceId): void
    {
        $this->gatewayParameters->marketplaceId = $marketplaceId;
    }
}