Files
shopit-back/app/Domains/Ticket/Exceptions/TicketGenerationException.php
ncoronel ff9d7728e8 Implement localization for API responses and error messages
- Added localization support for API responses in English and Spanish.
- Introduced a middleware to set the API locale based on the Accept-Language header.
- Updated various exception messages and validation responses to use localized strings.
- Created new language files for English and Spanish translations.
- Refactored existing code to replace hardcoded messages with localized strings.
- Added tests to verify localization functionality and response correctness.
2026-07-28 10:19:39 -03:00

54 lines
1.6 KiB
PHP

<?php
namespace App\Domains\Ticket\Exceptions;
use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Purchase\Models\Purchase;
use App\Domains\Purchase\Models\PurchaseItem;
use RuntimeException;
class TicketGenerationException extends RuntimeException
{
public static function invalidQuantity(): self
{
return new self(__('api.ticket.positive_quantity'));
}
public static function emptyBundle(CatalogItem $bundle): self
{
return new self(__('api.ticket.empty_bundle', ['bundle' => $bundle->id]));
}
public static function ticketsDisabled(CatalogItem $catalogItem): self
{
return new self(__('api.ticket.disabled', ['product' => $catalogItem->id]));
}
public static function maximumUseDateReached(CatalogItem $catalogItem): self
{
return new self(__('api.ticket.expired', ['product' => $catalogItem->id]));
}
public static function variantNotFound(
CatalogItem $catalogItem,
int $variantId,
): self {
return new self(
__('api.ticket.invalid_variant', [
'variant' => $variantId,
'product' => $catalogItem->id,
]),
);
}
public static function purchaseWithoutUser(Purchase $purchase): self
{
return new self(__('api.ticket.purchase_without_user', ['purchase' => $purchase->id]));
}
public static function catalogItemNotFound(PurchaseItem $purchaseItem): self
{
return new self(__('api.ticket.product_not_found', ['purchase_item' => $purchaseItem->id]));
}
}