feat(integrations): resolve payment context from events

This commit is contained in:
2026-09-28 19:14:23 +00:00
parent 7996d53e12
commit 3f9b773367
7 changed files with 173 additions and 42 deletions

View File

@@ -2,20 +2,22 @@
namespace Tests\Feature\Integration;
use App\Shared\Attachable\Enums\AttachmentType;
use App\Shared\Attachable\Models\Attachment;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Commerce\Cart\Models\Cart;
use App\Domains\Commerce\Catalog\Enums\InventoryPolicy;
use App\Domains\Commerce\Catalog\Models\CatalogItem;
use App\Domains\Commerce\Catalog\Models\Category;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Commerce\Catalog\Models\Variant;
use App\Shared\Integration\Models\Integration;
use App\Domains\Commerce\Purchase\Models\Purchase;
use App\Domains\Commerce\Purchase\Models\TelepagosPayment;
use App\Domains\Commerce\Purchase\Services\CheckoutService;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Core\Client\Models\Client;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Event\Models\Event;
use App\Shared\Attachable\Enums\AttachmentType;
use App\Shared\Attachable\Models\Attachment;
use App\Shared\Integration\Models\Integration;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
@@ -227,6 +229,77 @@ class TelepagosWebhookTest extends TestCase
]);
}
public function test_transfer_webhook_matches_the_client_configured_on_the_event(): void
{
$tenant = $this->createTenant('multi-event', 'Multi Event', 'multi-event.com.ar');
$eventClient = Client::query()->create([
'code' => 'event-client',
'name' => 'Event Client',
]);
Integration::query()->create([
'integration_code' => 'telepagos_homo',
'name' => 'Telepagos',
'url' => 'https://api.telepagos.com.ar',
'integration_data_schema' => [
'username' => 'required|string',
'password' => 'required|string',
],
]);
$this->createClientIntegration([
'client_id' => $eventClient->id,
'integration_code' => 'telepagos_homo',
'integration_data' => ['username' => 'event-user', 'password' => 'event-password'],
]);
$event = Event::query()->create([
'client_id' => $eventClient->id,
'tenant_code' => $tenant->codigo,
'title' => 'Event with its own client',
]);
$tenant->update(['active_event_id' => $event->id]);
$user = User::factory()->create();
$variant = $this->createVariantForTenant($tenant->codigo, 10, '50.00');
$purchase = $this->createPendingTransferPurchase(
$tenant,
$user->id,
$variant->id,
1,
'12345678',
);
Http::fake([
'https://api.telepagos.com.ar/v2/auth/token' => Http::response([
'status' => 'ok',
'token' => 'event-client-token',
'expires_at' => now()->addHour()->toIso8601String(),
]),
'https://api.telepagos.com.ar/v2/payment/cashin/event-client-payment' => Http::response([
'status' => 'ok',
'data' => [
'amount' => 50,
'operation_id' => 1,
'transaction_id' => 'tx-event-client',
'buyer' => ['cuit' => '20123456789'],
],
]),
]);
$this->postJson('/api/webhooks/telepagos/event-client', [
'id' => 'event-client-payment',
])->assertOk()->assertJsonPath('status', 'success');
$this->assertSame($event->id, $purchase->event_id);
$this->assertDatabaseHas('compras', [
'id' => $purchase->id,
'event_id' => $event->id,
'status' => Purchase::STATUS_PAID,
]);
$this->assertDatabaseHas('telepagos_payments', [
'compra_id' => $purchase->id,
'transaction_id' => 'tx-event-client',
]);
}
public function test_transfer_webhook_buys_unlimited_inventory_without_reducing_real_stock(): void
{
$tenant = $this->createTenant('unlimited', 'Unlimited', 'unlimited.com.ar');