feat(tenant): expose ticket refund configuration

This commit is contained in:
ncoronel 2026-09-10 15:29:41 -03:00
parent 471a941587
commit 1564985259
4 changed files with 121 additions and 0 deletions

View File

@ -117,6 +117,15 @@ class StoreTenantRequest extends FormRequest
],
'display_cart_item_images' => ['sometimes', 'boolean'],
'scanner_category_validation_enabled' => ['sometimes', 'boolean'],
'allow_ticket_total_refund' => ['sometimes', 'boolean'],
'allow_ticket_partial_refund' => ['sometimes', 'boolean'],
'ticket_partial_refund_percentage' => [
'sometimes',
'numeric',
'decimal:0,2',
'min:0',
'max:99.99',
],
'website_type_code' => [
'required_with:extras',
'sometimes',

View File

@ -138,6 +138,15 @@ class UpdateTenantRequest extends FormRequest
],
'display_cart_item_images' => ['sometimes', 'boolean'],
'scanner_category_validation_enabled' => ['sometimes', 'boolean'],
'allow_ticket_total_refund' => ['sometimes', 'boolean'],
'allow_ticket_partial_refund' => ['sometimes', 'boolean'],
'ticket_partial_refund_percentage' => [
'sometimes',
'numeric',
'decimal:0,2',
'min:0',
'max:99.99',
],
];
}
}

View File

@ -82,6 +82,9 @@ class TenantResource extends JsonResource
'checkout_editing_policy' => CartEditingPolicyResource::make($this->checkout_editing_policy),
'display_cart_item_images' => $this->display_cart_item_images,
'scanner_category_validation_enabled' => $this->scanner_category_validation_enabled,
'allow_ticket_total_refund' => $this->allow_ticket_total_refund,
'allow_ticket_partial_refund' => $this->allow_ticket_partial_refund,
'ticket_partial_refund_percentage' => $this->ticket_partial_refund_percentage,
'social_media' => $this->whenLoaded(
'socialMedia',
fn () => $this->socialMedia

View File

@ -0,0 +1,100 @@
<?php
namespace Tests\Feature\Tenant;
use App\Domains\Attachable\Enums\AttachmentType;
use App\Domains\Attachable\Models\Attachment;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Tests\TestCase;
class TenantRefundConfigurationTest extends TestCase
{
use RefreshDatabase;
public function test_refund_configuration_has_database_defaults_and_is_exposed_by_the_api(): void
{
$tenant = $this->createTenant('refund-defaults');
$this->assertFalse($tenant->allow_ticket_total_refund);
$this->assertFalse($tenant->allow_ticket_partial_refund);
$this->assertSame('0.00', $tenant->ticket_partial_refund_percentage);
$this->getJson("/api/tenants/{$tenant->codigo}")
->assertOk()
->assertJsonPath('data.allow_ticket_total_refund', false)
->assertJsonPath('data.allow_ticket_partial_refund', false)
->assertJsonPath('data.ticket_partial_refund_percentage', '0.00');
}
public function test_refund_configuration_can_be_updated_and_validates_its_precision(): void
{
$tenant = $this->createTenant('refund-update');
$this->putJson("/api/tenants/{$tenant->codigo}", [
'allow_ticket_total_refund' => true,
'allow_ticket_partial_refund' => true,
'ticket_partial_refund_percentage' => 25.50,
])
->assertOk()
->assertJsonPath('data.allow_ticket_total_refund', true)
->assertJsonPath('data.allow_ticket_partial_refund', true)
->assertJsonPath('data.ticket_partial_refund_percentage', '25.50');
$this->assertDatabaseHas('tenants', [
'id' => $tenant->id,
'allow_ticket_total_refund' => true,
'allow_ticket_partial_refund' => true,
'ticket_partial_refund_percentage' => 25.50,
]);
$this->putJson("/api/tenants/{$tenant->codigo}", [
'ticket_partial_refund_percentage' => 100,
])->assertUnprocessable()
->assertJsonValidationErrors('ticket_partial_refund_percentage');
$this->putJson("/api/tenants/{$tenant->codigo}", [
'ticket_partial_refund_percentage' => 12.345,
])->assertUnprocessable()
->assertJsonValidationErrors('ticket_partial_refund_percentage');
}
private function createTenant(string $code): Tenant
{
$attachmentIds = collect(['header', 'footer'])->map(function (string $name): int {
$key = (string) Str::uuid();
return Attachment::query()->create([
'key' => $key,
'path' => "tenants/{$key}.png",
'filename' => "{$name}.png",
'type' => AttachmentType::Image,
'mime_type' => 'image/png',
])->id;
});
$clientId = DB::table('clients')->insertGetId([
'code' => $code,
'name' => Str::headline($code),
]);
$tenantId = DB::table('tenants')->insertGetId([
'client_id' => $clientId,
'codigo' => $code,
'nombre' => Str::headline($code),
'dominio' => "{$code}.test",
'primary_color' => '#000000',
'secondary_color' => '#000000',
'danger_color' => '#000000',
'success_color' => '#000000',
'header_bg_color' => '#ffffff',
'footer_bg_color' => '#ffffff',
'header_logo_id' => $attachmentIds[0],
'footer_logo_id' => $attachmentIds[1],
]);
return Tenant::query()->findOrFail($tenantId);
}
}