feat(tenant): add allow_refund and allow_partial_refund methods

This commit is contained in:
2026-09-10 17:04:34 -03:00
parent beb5d18b29
commit 210c854fee
2 changed files with 69 additions and 0 deletions

View File

@@ -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.
*

View File

@@ -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 {