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/comfama.sports-crowd.com/app/Core/Payment/Methods/Yappy/YappyStrategy.php
<?php

declare(strict_types=1);

namespace App\Core\Payment\Methods\Yappy;

use App\BgFirma;
use App\Core\Payment\Entities\Payment;
use App\Core\Payment\Entities\PaymentIntentResponse;
use App\Core\Payment\Entities\PaymentRetrieveResponse;
use App\Core\Payment\PaymentMethodInterface;
use App\Core\Payment\PaymentStatusEnum;

class YappyStrategy implements PaymentMethodInterface
{
    private $parameters;

    public function __construct(
        $parameters
    ) {
        $this->parameters = $parameters;
    }

    public function pay(Payment $payment): PaymentIntentResponse
    {
        $payment->amount()->setCurrency($this->parameters->currency);
        $domain = config('app.url');

        $response = BgFirma::checkCredentials(
            $this->parameters->merchant_id,
            $this->parameters->client_secret,
            $domain
        );

        if (!$response['success']) {
            throw new \Exception('Error al verificar las credenciales');
        }

        $confirmUrl = $domain .
                '/store/payment?paymentGatewayId=' .
                $payment->paymentGatewayId() .
                '&reference=' .$payment->pin();

        //Inicializar objeto para poder generar el url de exito
        $bg = new BgFirma(
            $payment->amount()->total(), // Total + Taxes
            $this->parameters->merchant_id,
            $payment->amount()->currency(),
            $payment->amount()->total(), // Subtotal
            0.0, // Taxes
            $response['unixTimestamp'],
            'YAP',
            'VEN',
            $payment->pin(),
            $confirmUrl, // confirm
            $confirmUrl, // error
            $domain,
            $this->parameters->client_secret,
            !$this->parameters->is_productive, // Sandbox
            $response['accessToken'],
            $payment->customer()->mobile()
        );

        $response = $bg->createHash();

        if (!$response['success']) {
            throw new \Exception($response['msg']);
        }

        $paymentIntentResponse = new PaymentIntentResponse(
            PaymentIntentResponse::ACTION_REDIRECT,
            null
        );

        $paymentIntentResponse->setRedirectUrl($response['url']);

        return $paymentIntentResponse;
    }

    public function retrieve(Payment $payment): PaymentRetrieveResponse
    {
        return new PaymentRetrieveResponse(
            $payment->paymentGatewayTxId(),
            PaymentStatusEnum::PENDING,
            'nothing to do here'
        );
    }
}