refactor: remove PaymentProviderInterface and TelepagosProvider, simplify CheckoutService and related tests
This commit is contained in:
parent
057e6757dc
commit
0cb1c37566
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class TelepagosIntegrationSeeder extends Seeder
|
|||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$integration = Integration::updateOrCreate(
|
||||
Integration::updateOrCreate(
|
||||
['integration_code' => 'telepagos'],
|
||||
[
|
||||
'name' => 'Telepagos',
|
||||
|
|
@ -24,7 +24,7 @@ class TelepagosIntegrationSeeder extends Seeder
|
|||
]
|
||||
);
|
||||
|
||||
$integrationHomo = Integration::updateOrCreate(
|
||||
Integration::updateOrCreate(
|
||||
['integration_code' => 'telepagos_homo'],
|
||||
[
|
||||
'name' => 'Telepagos Homologación',
|
||||
|
|
@ -35,16 +35,5 @@ class TelepagosIntegrationSeeder extends Seeder
|
|||
]
|
||||
]
|
||||
);
|
||||
|
||||
// Seed association for sonder tenant
|
||||
$tenantIntegrationService = app(\App\Domains\Integration\Services\TenantIntegrationService::class);
|
||||
$tenantIntegrationService->updateOrCreateIntegration(
|
||||
'sonder',
|
||||
$integration,
|
||||
[
|
||||
'username' => 'sonder_telepagos',
|
||||
'password' => 'secret123',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace Tests\Feature\Purchase;
|
|||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Catalog\Models\Product;
|
||||
use App\Domains\Catalog\Models\ProductVariant;
|
||||
use App\Domains\Integration\Models\Integration;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
|
@ -19,33 +18,12 @@ class StorePurchaseTest extends TestCase
|
|||
// 1. Setup Tenant
|
||||
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
|
||||
// 2. Setup Integration
|
||||
$integration = Integration::create([
|
||||
'integration_code' => 'telepagos',
|
||||
'name' => 'Telepagos',
|
||||
'url' => 'https://api.telepagos.com.ar',
|
||||
'integration_data_schema' => [
|
||||
'username' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
]
|
||||
]);
|
||||
|
||||
$tenantIntegrationService = app(\App\Domains\Integration\Services\TenantIntegrationService::class);
|
||||
$tenantIntegrationService->updateOrCreateIntegration(
|
||||
'sonder',
|
||||
$integration,
|
||||
[
|
||||
'username' => 'sonder_telepagos',
|
||||
'password' => 'secret123',
|
||||
]
|
||||
);
|
||||
|
||||
// 3. Setup User
|
||||
// 2. Setup User
|
||||
$user = User::factory()->create([
|
||||
'email' => 'buyer@example.com'
|
||||
]);
|
||||
|
||||
// 4. Setup Product & Variant
|
||||
// 3. Setup Product & Variant
|
||||
$category = \App\Domains\Catalog\Models\Category::query()->create([
|
||||
'tenant_code' => 'sonder',
|
||||
'nombre' => 'Test Category',
|
||||
|
|
@ -68,7 +46,7 @@ class StorePurchaseTest extends TestCase
|
|||
'precio' => '50.00',
|
||||
]);
|
||||
|
||||
// 5. Add item to user's cart
|
||||
// 4. Add item to user's cart
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->postJson('/api/tenants/sonder/cart/items', [
|
||||
'product_variant_id' => $variant->id,
|
||||
|
|
@ -82,17 +60,14 @@ class StorePurchaseTest extends TestCase
|
|||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
// 6. Submit Purchase
|
||||
// 5. Submit Purchase with payment_method at root
|
||||
$response = $this->actingAs($user, 'sanctum')
|
||||
->postJson('/api/tenants/sonder/compras', [
|
||||
'dni' => '987654321',
|
||||
'telefono' => '+54 9 341 555-4321',
|
||||
'nombre_apellido' => 'Juan Perez',
|
||||
'email' => 'juan.perez@example.com',
|
||||
'integration_code' => 'telepagos',
|
||||
'payment_data' => [
|
||||
'payment_method' => 'transferencia',
|
||||
],
|
||||
'payment_method' => 'transferencia',
|
||||
'items' => [
|
||||
[
|
||||
'producto_variante_id' => $variant->id,
|
||||
|
|
@ -101,7 +76,7 @@ class StorePurchaseTest extends TestCase
|
|||
]
|
||||
]);
|
||||
|
||||
// 7. Assertions
|
||||
// 6. Assertions
|
||||
$response->assertCreated();
|
||||
$response->assertJsonPath('data.dni', '987654321');
|
||||
$response->assertJsonPath('data.telefono', '+54 9 341 555-4321');
|
||||
|
|
|
|||
Loading…
Reference in New Issue