From 210c854fee3437ca6440249cb8dc9517b389c4b6 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Thu, 10 Sep 2026 17:04:34 -0300 Subject: [PATCH] feat(tenant): add allow_refund and allow_partial_refund methods --- app/Domains/Tenant/Models/Tenant.php | 27 ++++++++++++ .../Tenant/TenantRefundConfigurationTest.php | 42 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/app/Domains/Tenant/Models/Tenant.php b/app/Domains/Tenant/Models/Tenant.php index 3376c0b..7c6938f 100644 --- a/app/Domains/Tenant/Models/Tenant.php +++ b/app/Domains/Tenant/Models/Tenant.php @@ -112,6 +112,33 @@ class Tenant extends Model return $this->scanner_category_validation_enabled; } + public function allow_refund(): bool + { + return (bool) $this->allow_ticket_total_refund || $this->allow_partial_refund(); + } + + public function allow_partial_refund(): bool + { + return (bool) $this->allow_ticket_partial_refund + && $this->ticket_partial_refund_percentage !== null + && (float) $this->ticket_partial_refund_percentage > 0; + } + + public function allowRefund(): bool + { + return $this->allow_refund(); + } + + public function allowPartialRefund(): bool + { + return $this->allow_partial_refund(); + } + + public function getAllowRefundAttribute(): bool + { + return $this->allow_refund(); + } + /** * Get the attributes that should be cast. * diff --git a/tests/Feature/Tenant/TenantRefundConfigurationTest.php b/tests/Feature/Tenant/TenantRefundConfigurationTest.php index 17c5608..b50304a 100644 --- a/tests/Feature/Tenant/TenantRefundConfigurationTest.php +++ b/tests/Feature/Tenant/TenantRefundConfigurationTest.php @@ -61,6 +61,48 @@ class TenantRefundConfigurationTest extends TestCase ->assertJsonValidationErrors('ticket_partial_refund_percentage'); } + public function test_tenant_allow_refund_logic(): void + { + $tenant = new Tenant([ + 'allow_ticket_total_refund' => false, + 'allow_ticket_partial_refund' => false, + 'ticket_partial_refund_percentage' => 0, + ]); + + $this->assertFalse($tenant->allow_refund()); + $this->assertFalse($tenant->allowRefund()); + $this->assertFalse($tenant->allow_refund); + $this->assertFalse($tenant->allow_partial_refund()); + $this->assertFalse($tenant->allowPartialRefund()); + + // Partial refund enabled but percentage is 0 / unset + $tenant->allow_ticket_partial_refund = true; + $tenant->ticket_partial_refund_percentage = 0; + $this->assertFalse($tenant->allow_refund()); + $this->assertFalse($tenant->allow_partial_refund()); + + // Partial refund enabled and percentage is set + $tenant->ticket_partial_refund_percentage = 25.50; + $this->assertTrue($tenant->allow_refund()); + $this->assertTrue($tenant->allowRefund()); + $this->assertTrue($tenant->allow_refund); + $this->assertTrue($tenant->allow_partial_refund()); + $this->assertTrue($tenant->allowPartialRefund()); + + // Total refund enabled, partial refund disabled + $tenant->allow_ticket_partial_refund = false; + $tenant->allow_ticket_total_refund = true; + $tenant->ticket_partial_refund_percentage = 0; + $this->assertTrue($tenant->allow_refund()); + $this->assertFalse($tenant->allow_partial_refund()); + + // Total refund enabled and partial refund enabled with percentage + $tenant->allow_ticket_partial_refund = true; + $tenant->ticket_partial_refund_percentage = 50.00; + $this->assertTrue($tenant->allow_refund()); + $this->assertTrue($tenant->allow_partial_refund()); + } + private function createTenant(string $code): Tenant { $attachmentIds = collect(['header', 'footer'])->map(function (string $name): int {