feat: sms rates

This commit is contained in:
loks0n
2025-01-09 18:33:07 +00:00
parent 76e1b27cef
commit 7c9c3d9214
2 changed files with 7 additions and 7 deletions
+6 -6
View File
@@ -31,8 +31,8 @@ App::get('/v1/project/usage')
->param('period', '1d', new WhiteList(['1h', '1d']), 'Period used', true)
->inject('response')
->inject('dbForProject')
->inject('getSmsPrice')
->action(function (string $startDate, string $endDate, string $period, Response $response, Database $dbForProject, callable $getSmsPrice) {
->inject('smsRates')
->action(function (string $startDate, string $endDate, string $period, Response $response, Database $dbForProject, array $smsRates) {
$stats = $total = $usage = [];
$format = 'Y-m-d 00:00:00';
$firstDay = (new DateTime($startDate))->format($format);
@@ -285,15 +285,15 @@ App::get('/v1/project/usage')
$value = $metric->getAttribute('value', 0);
if (is_callable($getSmsPrice)) {
$authPhoneEstimate += $value * $getSmsPrice($countryCode);
if (!empty($smsRates[$countryCode])) {
$authPhoneEstimate += $value * $smsRates[$countryCode];
}
$authPhoneCountryBreakdown[] = [
'name' => $countryCode,
'value' => $value,
'estimate' => is_callable($getSmsPrice)
? $value * $getSmsPrice($countryCode)
'estimate' => !empty($smsRates[$countryCode])
? $value * $smsRates[$countryCode]
: 0.0,
];
}
+1 -1
View File
@@ -1844,7 +1844,7 @@ App::setResource('plan', function (array $plan = []) {
return [];
});
App::setResource('getSmsPrice', function () {
App::setResource('smsRates', function () {
return [];
});