refactor: remove PaymentProviderInterface and TelepagosProvider, simplify CheckoutService and related tests
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Integration\Services\Contracts;
|
||||
|
||||
interface PaymentProviderInterface
|
||||
{
|
||||
/**
|
||||
* Procesa un pago con las credenciales específicas del Tenant.
|
||||
*
|
||||
* @param array $paymentData Datos del pago, incluyendo el método (ej. qr, transferencia).
|
||||
* @param array $credentials Credenciales encriptadas previamente configuradas por el Tenant.
|
||||
* @return array
|
||||
*/
|
||||
public function process(array $paymentData, array $credentials): array;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Integration\Services;
|
||||
|
||||
use App\Domains\Integration\Services\Contracts\PaymentProviderInterface;
|
||||
use App\Domains\Integration\Services\Providers\TelepagosProvider;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class PaymentProviderFactory
|
||||
{
|
||||
public function make(string $integrationCode): PaymentProviderInterface
|
||||
{
|
||||
return match ($integrationCode) {
|
||||
'telepagos' => new TelepagosProvider(),
|
||||
default => throw new InvalidArgumentException("Integración de pago no soportada: {$integrationCode}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Integration\Services\Providers;
|
||||
|
||||
use App\Domains\Integration\Services\Contracts\PaymentProviderInterface;
|
||||
use BadMethodCallException;
|
||||
|
||||
class TelepagosProvider implements PaymentProviderInterface
|
||||
{
|
||||
public function process(array $paymentData, array $credentials): array
|
||||
{
|
||||
// Mocked response for development and local testing
|
||||
return [
|
||||
'status' => 'approved',
|
||||
'transaction_id' => 'mock_tp_' . uniqid(),
|
||||
'payment_method' => $paymentData['payment_method'] ?? 'qr',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -31,18 +31,11 @@ class PurchaseController extends Controller
|
||||
public function store(StorePurchaseRequest $request, Tenant $tenant, CheckoutService $checkoutService): JsonResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
$integrationCode = $data['integration_code'];
|
||||
$paymentData = $data['payment_data'];
|
||||
|
||||
unset($data['integration_code'], $data['payment_data']);
|
||||
|
||||
$purchase = $checkoutService->processCheckout(
|
||||
$tenant,
|
||||
$request->user()->id,
|
||||
$data,
|
||||
$integrationCode,
|
||||
$paymentData
|
||||
$data
|
||||
);
|
||||
|
||||
return PurchaseResource::make($purchase)->response()->setStatusCode(201);
|
||||
|
||||
@@ -7,7 +7,6 @@ use App\Domains\Purchase\Models\Purchase;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Exception;
|
||||
|
||||
class CheckoutService
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user