refactor(billing-v2): drop balanceLeads from InsufficientBalanceException

This commit is contained in:
Дмитрий
2026-05-23 12:52:31 +03:00
parent cedf4ae5c4
commit 515741bb42
4 changed files with 37 additions and 9 deletions
@@ -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,
);
-1
View File
@@ -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,
]);
}
@@ -129,7 +129,6 @@ final class LedgerService
throw new InsufficientBalanceException(
priceKopecks: $priceKopecks,
balanceRub: (string) $tenant->balance_rub,
balanceLeads: (int) $tenant->balance_leads,
);
}
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
use App\Exceptions\Billing\InsufficientBalanceException;
it('exposes priceKopecks and balanceRub but no balanceLeads', function () {
$e = new InsufficientBalanceException(
priceKopecks: 12000,
balanceRub: '50.00',
);
expect($e->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');
});