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'
);
}
}