File: /var/www/vhost/disk-apps/alq-cali.bikenow.co/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\MercadoPago\MercadoPagoStrategy;
use App\Core\Payment\Methods\MercadoPagoMKT\MercadoPagoMKTStrategy;
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;
case 'mercadopago':
$this->strategy = new MercadoPagoStrategy($this->gatewayParameters);
break;
case 'mercadopagoMKT':
$this->strategy = new MercadoPagoMKTStrategy($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;
}
}