diff --git a/app/app/Exceptions/Billing/InsufficientBalanceException.php b/app/app/Exceptions/Billing/InsufficientBalanceException.php index 4a7ad45c..47882cc1 100644 --- a/app/app/Exceptions/Billing/InsufficientBalanceException.php +++ b/app/app/Exceptions/Billing/InsufficientBalanceException.php @@ -5,27 +5,30 @@ declare(strict_types=1); namespace App\Exceptions\Billing; use RuntimeException; +use Throwable; /** - * Выбрасывается LedgerService::chargeForDelivery, когда tenant не имеет - * ни prepaid-лидов (balance_leads >= 1), ни рублей под текущую tier-цену - * (balance_rub * 100 >= priceKopecks). + * Выбрасывается LedgerService::chargeForDelivery, когда у tenant нет + * рублей под текущую tier-цену (balance_rub * 100 < priceKopecks). * * Ловится в RouteSupplierLeadJob::createDealCopyForProject — инициирует * auto-pause flow (см. spec §4.2). + * + * Billing v2 Spec A: prepaid-лиды убраны, поэтому balance_leads больше не отражается + * в сообщении/полях; источник — единый ₽-баланс. */ final class InsufficientBalanceException extends RuntimeException { public function __construct( public readonly int $priceKopecks, public readonly string $balanceRub, - public readonly int $balanceLeads, - ?\Throwable $previous = null, + ?Throwable $previous = null, ) { parent::__construct( sprintf( - 'Insufficient balance: price_kopecks=%d, balance_rub=%s, balance_leads=%d', - $priceKopecks, $balanceRub, $balanceLeads, + 'Insufficient balance: price_kopecks=%d, balance_rub=%s', + $priceKopecks, + $balanceRub, ), previous: $previous, ); diff --git a/app/app/Jobs/RouteSupplierLeadJob.php b/app/app/Jobs/RouteSupplierLeadJob.php index 4de6e9fe..111bef74 100644 --- a/app/app/Jobs/RouteSupplierLeadJob.php +++ b/app/app/Jobs/RouteSupplierLeadJob.php @@ -384,7 +384,6 @@ class RouteSupplierLeadJob implements ShouldQueue 'supplier_lead_id' => $lead->id, 'price_kopecks' => $e->priceKopecks, 'balance_rub' => $e->balanceRub, - 'balance_leads' => $e->balanceLeads, ]); } diff --git a/app/app/Services/Billing/LedgerService.php b/app/app/Services/Billing/LedgerService.php index 9c6658e0..9638e77d 100644 --- a/app/app/Services/Billing/LedgerService.php +++ b/app/app/Services/Billing/LedgerService.php @@ -129,7 +129,6 @@ final class LedgerService throw new InsufficientBalanceException( priceKopecks: $priceKopecks, balanceRub: (string) $tenant->balance_rub, - balanceLeads: (int) $tenant->balance_leads, ); } diff --git a/app/tests/Unit/Exceptions/InsufficientBalanceExceptionTest.php b/app/tests/Unit/Exceptions/InsufficientBalanceExceptionTest.php new file mode 100644 index 00000000..5cc2ebc5 --- /dev/null +++ b/app/tests/Unit/Exceptions/InsufficientBalanceExceptionTest.php @@ -0,0 +1,27 @@ +priceKopecks)->toBe(12000); + expect($e->balanceRub)->toBe('50.00'); + expect(property_exists($e, 'balanceLeads'))->toBeFalse(); +}); + +it('formats message without balance_leads', function () { + $e = new InsufficientBalanceException( + priceKopecks: 12000, + balanceRub: '50.00', + ); + + expect($e->getMessage())->not->toContain('balance_leads'); + expect($e->getMessage())->toContain('12000'); + expect($e->getMessage())->toContain('50.00'); +});