mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-12 09:48:35 +02:00
Fixed issue with application pricing
This commit is contained in:
parent
8dc01d65d0
commit
a0a16f4bfb
4 changed files with 190 additions and 102 deletions
|
@ -228,14 +228,23 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
$exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0;
|
$exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0;
|
||||||
|
|
||||||
// Check for premium pricing
|
// Check for premium pricing
|
||||||
$premiumPrice = $redis->get("premium_price_{$domain_name}_{$tld_id}") ?: fetchSingleValue(
|
$premiumCacheKey = "premium_price_{$domain_name}_{$tld_id}";
|
||||||
$pdo,
|
$premiumPrice = json_decode($redis->get($premiumCacheKey), true);
|
||||||
'SELECT c.category_price
|
|
||||||
FROM premium_domain_pricing p
|
if ($premiumPrice === null || $premiumPrice == 0) {
|
||||||
JOIN premium_domain_categories c ON p.category_id = c.category_id
|
$premiumPrice = fetchSingleValue(
|
||||||
WHERE p.domain_name = ? AND p.tld_id = ?',
|
$pdo,
|
||||||
[$domain_name, $tld_id]
|
'SELECT c.category_price
|
||||||
);
|
FROM premium_domain_pricing p
|
||||||
|
JOIN premium_domain_categories c ON p.category_id = c.category_id
|
||||||
|
WHERE p.domain_name = ? AND p.tld_id = ?',
|
||||||
|
[$domain_name, $tld_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
||||||
|
$redis->setex($premiumCacheKey, 1800, json_encode($premiumPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
||||||
$money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency);
|
$money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency);
|
||||||
|
@ -247,46 +256,65 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
|
|
||||||
// Check for active promotions
|
// Check for active promotions
|
||||||
$currentDate = date('Y-m-d');
|
$currentDate = date('Y-m-d');
|
||||||
$promo = json_decode($redis->get("promo_{$tld_id}"), true) ?: fetchSingleRow(
|
$promoCacheKey = "promo_{$tld_id}";
|
||||||
$pdo,
|
$promo = json_decode($redis->get($promoCacheKey), true);
|
||||||
"SELECT discount_percentage, discount_amount
|
|
||||||
FROM promotion_pricing
|
|
||||||
WHERE tld_id = ?
|
|
||||||
AND promo_type = 'full'
|
|
||||||
AND status = 'active'
|
|
||||||
AND start_date <= ?
|
|
||||||
AND end_date >= ?",
|
|
||||||
[$tld_id, $currentDate, $currentDate]
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($promo) {
|
if ($promo === null) {
|
||||||
$redis->setex("promo_{$tld_id}", 3600, json_encode($promo));
|
$promo = fetchSingleRow(
|
||||||
|
$pdo,
|
||||||
|
"SELECT discount_percentage, discount_amount
|
||||||
|
FROM promotion_pricing
|
||||||
|
WHERE tld_id = ?
|
||||||
|
AND promo_type = 'full'
|
||||||
|
AND status = 'active'
|
||||||
|
AND start_date <= ?
|
||||||
|
AND end_date >= ?",
|
||||||
|
[$tld_id, $currentDate, $currentDate]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($promo) {
|
||||||
|
$redis->setex($promoCacheKey, 3600, json_encode($promo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get regular price from DB
|
// Get regular price from DB
|
||||||
$priceColumn = "m" . (int) $date_add;
|
$priceColumn = "m" . (int) $date_add;
|
||||||
$regularPrice = json_decode($redis->get("regular_price_{$tld_id}_{$command}_{$registrar_id}"), true) ?: fetchSingleValue(
|
$regularPriceCacheKey = "regular_price_{$tld_id}_{$command}_{$date_add}_{$registrar_id}";
|
||||||
$pdo,
|
$regularPrice = json_decode($redis->get($regularPriceCacheKey), true);
|
||||||
"SELECT $priceColumn
|
|
||||||
FROM domain_price
|
if ($regularPrice === null || $regularPrice == 0) {
|
||||||
WHERE tldid = ? AND command = ?
|
$regularPrice = fetchSingleValue(
|
||||||
AND (registrar_id = ? OR registrar_id IS NULL)
|
$pdo,
|
||||||
ORDER BY registrar_id DESC LIMIT 1",
|
"SELECT $priceColumn
|
||||||
[$tld_id, $command, $registrar_id]
|
FROM domain_price
|
||||||
);
|
WHERE tldid = ? AND command = ?
|
||||||
|
AND (registrar_id = ? OR registrar_id IS NULL)
|
||||||
|
ORDER BY registrar_id DESC LIMIT 1",
|
||||||
|
[$tld_id, $command, $registrar_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!is_null($regularPrice) && $regularPrice !== false) {
|
||||||
|
$redis->setex($regularPriceCacheKey, 1800, json_encode($regularPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_null($regularPrice) && $regularPrice !== false) {
|
if (!is_null($regularPrice) && $regularPrice !== false) {
|
||||||
$redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice));
|
$redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice));
|
||||||
|
|
||||||
$finalPrice = $regularPrice * 100; // Convert DB float to cents
|
$finalPrice = $regularPrice * 100; // Convert DB float to cents
|
||||||
if ($promo) {
|
if ($promo) {
|
||||||
if (!empty($promo['discount_percentage'])) {
|
if ($finalPrice > 0) {
|
||||||
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
if (!empty($promo['discount_percentage'])) {
|
||||||
|
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
||||||
|
} else {
|
||||||
|
$discountAmount = (int) ($promo['discount_amount'] * 100);
|
||||||
|
}
|
||||||
|
$finalPrice = max(0, $finalPrice - $discountAmount);
|
||||||
|
$type = 'promotion';
|
||||||
} else {
|
} else {
|
||||||
$discountAmount = (int) ($promo['discount_amount'] * 100);
|
$finalPrice = 0;
|
||||||
|
$type = 'promotion';
|
||||||
}
|
}
|
||||||
$finalPrice = max(0, $finalPrice - $discountAmount);
|
|
||||||
$type = 'promotion';
|
|
||||||
} else {
|
} else {
|
||||||
$type = 'regular';
|
$type = 'regular';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1134,6 +1134,16 @@ class ApplicationsController extends Controller
|
||||||
$returnValue = getDomainPrice($db, $domainName, $tld_id, $date_add, 'create', $clid, $currency);
|
$returnValue = getDomainPrice($db, $domainName, $tld_id, $date_add, 'create', $clid, $currency);
|
||||||
$price = $returnValue['price'];
|
$price = $returnValue['price'];
|
||||||
|
|
||||||
|
if (!$price) {
|
||||||
|
$this->container->get('flash')->addMessage('error', 'Error creating domain: The price, period and currency for such TLD are not declared');
|
||||||
|
return $response->withHeader('Location', '/application/create')->withStatus(302);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($registrar_balance + $creditLimit) < $price) {
|
||||||
|
$this->container->get('flash')->addMessage('error', 'Error creating domain: Low credit: minimum threshold reached');
|
||||||
|
return $response->withHeader('Location', '/application/create')->withStatus(302);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$db->beginTransaction();
|
$db->beginTransaction();
|
||||||
|
|
||||||
|
|
|
@ -467,13 +467,20 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = '
|
||||||
$exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0;
|
$exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0;
|
||||||
|
|
||||||
// Check for premium pricing
|
// Check for premium pricing
|
||||||
$premiumPrice = $redis->get("premium_price_{$domain_name}_{$tld_id}") ?: $db->selectValue(
|
$premiumPrice = $redis->get("premium_price_{$domain_name}_{$tld_id}");
|
||||||
'SELECT c.category_price
|
if ($premiumPrice === null || $premiumPrice == "0") {
|
||||||
FROM premium_domain_pricing p
|
$premiumPrice = $db->selectValue(
|
||||||
JOIN premium_domain_categories c ON p.category_id = c.category_id
|
'SELECT c.category_price
|
||||||
WHERE p.domain_name = ? AND p.tld_id = ?',
|
FROM premium_domain_pricing p
|
||||||
[$domain_name, $tld_id]
|
JOIN premium_domain_categories c ON p.category_id = c.category_id
|
||||||
);
|
WHERE p.domain_name = ? AND p.tld_id = ?',
|
||||||
|
[$domain_name, $tld_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
||||||
|
$redis->setex("premium_price_{$domain_name}_{$tld_id}", 1800, json_encode($premiumPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
||||||
$money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency);
|
$money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency);
|
||||||
|
@ -485,44 +492,59 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = '
|
||||||
|
|
||||||
// Check for active promotions
|
// Check for active promotions
|
||||||
$currentDate = date('Y-m-d');
|
$currentDate = date('Y-m-d');
|
||||||
$promo = json_decode($redis->get("promo_{$tld_id}"), true) ?: $db->selectRow(
|
$promo = json_decode($redis->get("promo_{$tld_id}"), true);
|
||||||
"SELECT discount_percentage, discount_amount
|
if ($promo === null) {
|
||||||
FROM promotion_pricing
|
$promo = $db->selectRow(
|
||||||
WHERE tld_id = ?
|
"SELECT discount_percentage, discount_amount
|
||||||
AND promo_type = 'full'
|
FROM promotion_pricing
|
||||||
AND status = 'active'
|
WHERE tld_id = ?
|
||||||
AND start_date <= ?
|
AND promo_type = 'full'
|
||||||
AND end_date >= ?",
|
AND status = 'active'
|
||||||
[$tld_id, $currentDate, $currentDate]
|
AND start_date <= ?
|
||||||
);
|
AND end_date >= ?",
|
||||||
|
[$tld_id, $currentDate, $currentDate]
|
||||||
|
);
|
||||||
|
|
||||||
if ($promo) {
|
if ($promo) {
|
||||||
$redis->setex("promo_{$tld_id}", 3600, json_encode($promo));
|
$redis->setex("promo_{$tld_id}", 3600, json_encode($promo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get regular price from DB
|
// Get regular price from DB
|
||||||
$priceColumn = "m" . (int) $date_add;
|
$priceColumn = "m" . (int) $date_add;
|
||||||
$regularPrice = json_decode($redis->get("regular_price_{$tld_id}_{$command}_{$registrar_id}"), true) ?: $db->selectValue(
|
$regularPrice = json_decode($redis->get("regular_price_{$tld_id}_{$command}_{$date_add}_{$registrar_id}"), true);
|
||||||
"SELECT $priceColumn
|
if ($regularPrice === null || $regularPrice == 0) {
|
||||||
FROM domain_price
|
$regularPrice = $db->selectValue(
|
||||||
WHERE tldid = ? AND command = ?
|
"SELECT $priceColumn
|
||||||
AND (registrar_id = ? OR registrar_id IS NULL)
|
FROM domain_price
|
||||||
ORDER BY registrar_id DESC LIMIT 1",
|
WHERE tldid = ? AND command = ?
|
||||||
[$tld_id, $command, $registrar_id]
|
AND (registrar_id = ? OR registrar_id IS NULL)
|
||||||
);
|
ORDER BY registrar_id DESC LIMIT 1",
|
||||||
|
[$tld_id, $command, $registrar_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!is_null($regularPrice) && $regularPrice !== false) {
|
||||||
|
$redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_null($regularPrice) && $regularPrice !== false) {
|
if (!is_null($regularPrice) && $regularPrice !== false) {
|
||||||
$redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice));
|
$redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice));
|
||||||
|
|
||||||
$finalPrice = $regularPrice * 100; // Convert DB float to cents
|
$finalPrice = $regularPrice * 100; // Convert DB float to cents
|
||||||
if ($promo) {
|
if ($promo) {
|
||||||
if (!empty($promo['discount_percentage'])) {
|
if ($finalPrice > 0) {
|
||||||
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
if (!empty($promo['discount_percentage'])) {
|
||||||
|
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
||||||
|
} else {
|
||||||
|
$discountAmount = (int) ($promo['discount_amount'] * 100);
|
||||||
|
}
|
||||||
|
$finalPrice = max(0, $finalPrice - $discountAmount);
|
||||||
|
$type = 'promotion';
|
||||||
} else {
|
} else {
|
||||||
$discountAmount = (int) ($promo['discount_amount'] * 100);
|
$finalPrice = 0;
|
||||||
|
$type = 'promotion';
|
||||||
}
|
}
|
||||||
$finalPrice = max(0, $finalPrice - $discountAmount);
|
|
||||||
$type = 'promotion';
|
|
||||||
} else {
|
} else {
|
||||||
$type = 'regular';
|
$type = 'regular';
|
||||||
}
|
}
|
||||||
|
|
|
@ -671,14 +671,23 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
$exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0;
|
$exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0;
|
||||||
|
|
||||||
// Check for premium pricing
|
// Check for premium pricing
|
||||||
$premiumPrice = $redis->get("premium_price_{$domain_name}_{$tld_id}") ?: fetchSingleValue(
|
$premiumCacheKey = "premium_price_{$domain_name}_{$tld_id}";
|
||||||
$pdo,
|
$premiumPrice = json_decode($redis->get($premiumCacheKey), true);
|
||||||
'SELECT c.category_price
|
|
||||||
FROM premium_domain_pricing p
|
if ($premiumPrice === null || $premiumPrice == 0) {
|
||||||
JOIN premium_domain_categories c ON p.category_id = c.category_id
|
$premiumPrice = fetchSingleValue(
|
||||||
WHERE p.domain_name = ? AND p.tld_id = ?',
|
$pdo,
|
||||||
[$domain_name, $tld_id]
|
'SELECT c.category_price
|
||||||
);
|
FROM premium_domain_pricing p
|
||||||
|
JOIN premium_domain_categories c ON p.category_id = c.category_id
|
||||||
|
WHERE p.domain_name = ? AND p.tld_id = ?',
|
||||||
|
[$domain_name, $tld_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
||||||
|
$redis->setex($premiumCacheKey, 1800, json_encode($premiumPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
if (!is_null($premiumPrice) && $premiumPrice !== false) {
|
||||||
$money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency);
|
$money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency);
|
||||||
|
@ -690,46 +699,65 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
|
|
||||||
// Check for active promotions
|
// Check for active promotions
|
||||||
$currentDate = date('Y-m-d');
|
$currentDate = date('Y-m-d');
|
||||||
$promo = json_decode($redis->get("promo_{$tld_id}"), true) ?: fetchSingleRow(
|
$promoCacheKey = "promo_{$tld_id}";
|
||||||
$pdo,
|
$promo = json_decode($redis->get($promoCacheKey), true);
|
||||||
"SELECT discount_percentage, discount_amount
|
|
||||||
FROM promotion_pricing
|
|
||||||
WHERE tld_id = ?
|
|
||||||
AND promo_type = 'full'
|
|
||||||
AND status = 'active'
|
|
||||||
AND start_date <= ?
|
|
||||||
AND end_date >= ?",
|
|
||||||
[$tld_id, $currentDate, $currentDate]
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($promo) {
|
if ($promo === null) {
|
||||||
$redis->setex("promo_{$tld_id}", 3600, json_encode($promo));
|
$promo = fetchSingleRow(
|
||||||
|
$pdo,
|
||||||
|
"SELECT discount_percentage, discount_amount
|
||||||
|
FROM promotion_pricing
|
||||||
|
WHERE tld_id = ?
|
||||||
|
AND promo_type = 'full'
|
||||||
|
AND status = 'active'
|
||||||
|
AND start_date <= ?
|
||||||
|
AND end_date >= ?",
|
||||||
|
[$tld_id, $currentDate, $currentDate]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($promo) {
|
||||||
|
$redis->setex($promoCacheKey, 3600, json_encode($promo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get regular price from DB
|
// Get regular price from DB
|
||||||
$priceColumn = "m" . (int) $date_add;
|
$priceColumn = "m" . (int) $date_add;
|
||||||
$regularPrice = json_decode($redis->get("regular_price_{$tld_id}_{$command}_{$registrar_id}"), true) ?: fetchSingleValue(
|
$regularPriceCacheKey = "regular_price_{$tld_id}_{$command}_{$date_add}_{$registrar_id}";
|
||||||
$pdo,
|
$regularPrice = json_decode($redis->get($regularPriceCacheKey), true);
|
||||||
"SELECT $priceColumn
|
|
||||||
FROM domain_price
|
if ($regularPrice === null || $regularPrice == 0) {
|
||||||
WHERE tldid = ? AND command = ?
|
$regularPrice = fetchSingleValue(
|
||||||
AND (registrar_id = ? OR registrar_id IS NULL)
|
$pdo,
|
||||||
ORDER BY registrar_id DESC LIMIT 1",
|
"SELECT $priceColumn
|
||||||
[$tld_id, $command, $registrar_id]
|
FROM domain_price
|
||||||
);
|
WHERE tldid = ? AND command = ?
|
||||||
|
AND (registrar_id = ? OR registrar_id IS NULL)
|
||||||
|
ORDER BY registrar_id DESC LIMIT 1",
|
||||||
|
[$tld_id, $command, $registrar_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!is_null($regularPrice) && $regularPrice !== false) {
|
||||||
|
$redis->setex($regularPriceCacheKey, 1800, json_encode($regularPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_null($regularPrice) && $regularPrice !== false) {
|
if (!is_null($regularPrice) && $regularPrice !== false) {
|
||||||
$redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice));
|
$redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice));
|
||||||
|
|
||||||
$finalPrice = $regularPrice * 100; // Convert DB float to cents
|
$finalPrice = $regularPrice * 100; // Convert DB float to cents
|
||||||
if ($promo) {
|
if ($promo) {
|
||||||
if (!empty($promo['discount_percentage'])) {
|
if ($finalPrice > 0) {
|
||||||
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
if (!empty($promo['discount_percentage'])) {
|
||||||
|
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
||||||
|
} else {
|
||||||
|
$discountAmount = (int) ($promo['discount_amount'] * 100);
|
||||||
|
}
|
||||||
|
$finalPrice = max(0, $finalPrice - $discountAmount);
|
||||||
|
$type = 'promotion';
|
||||||
} else {
|
} else {
|
||||||
$discountAmount = (int) ($promo['discount_amount'] * 100);
|
$finalPrice = 0;
|
||||||
|
$type = 'promotion';
|
||||||
}
|
}
|
||||||
$finalPrice = max(0, $finalPrice - $discountAmount);
|
|
||||||
$type = 'promotion';
|
|
||||||
} else {
|
} else {
|
||||||
$type = 'regular';
|
$type = 'regular';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue