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,7 +228,11 @@ 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}";
|
||||||
|
$premiumPrice = json_decode($redis->get($premiumCacheKey), true);
|
||||||
|
|
||||||
|
if ($premiumPrice === null || $premiumPrice == 0) {
|
||||||
|
$premiumPrice = fetchSingleValue(
|
||||||
$pdo,
|
$pdo,
|
||||||
'SELECT c.category_price
|
'SELECT c.category_price
|
||||||
FROM premium_domain_pricing p
|
FROM premium_domain_pricing p
|
||||||
|
@ -237,6 +241,11 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
[$domain_name, $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);
|
||||||
$result = ['type' => 'premium', 'price' => formatMoney($money)];
|
$result = ['type' => 'premium', 'price' => formatMoney($money)];
|
||||||
|
@ -247,7 +256,11 @@ 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}";
|
||||||
|
$promo = json_decode($redis->get($promoCacheKey), true);
|
||||||
|
|
||||||
|
if ($promo === null) {
|
||||||
|
$promo = fetchSingleRow(
|
||||||
$pdo,
|
$pdo,
|
||||||
"SELECT discount_percentage, discount_amount
|
"SELECT discount_percentage, discount_amount
|
||||||
FROM promotion_pricing
|
FROM promotion_pricing
|
||||||
|
@ -260,12 +273,17 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($promo) {
|
if ($promo) {
|
||||||
$redis->setex("promo_{$tld_id}", 3600, json_encode($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}";
|
||||||
|
$regularPrice = json_decode($redis->get($regularPriceCacheKey), true);
|
||||||
|
|
||||||
|
if ($regularPrice === null || $regularPrice == 0) {
|
||||||
|
$regularPrice = fetchSingleValue(
|
||||||
$pdo,
|
$pdo,
|
||||||
"SELECT $priceColumn
|
"SELECT $priceColumn
|
||||||
FROM domain_price
|
FROM domain_price
|
||||||
|
@ -275,11 +293,17 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
[$tld_id, $command, $registrar_id]
|
[$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 ($finalPrice > 0) {
|
||||||
if (!empty($promo['discount_percentage'])) {
|
if (!empty($promo['discount_percentage'])) {
|
||||||
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
||||||
} else {
|
} else {
|
||||||
|
@ -287,6 +311,10 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
}
|
}
|
||||||
$finalPrice = max(0, $finalPrice - $discountAmount);
|
$finalPrice = max(0, $finalPrice - $discountAmount);
|
||||||
$type = 'promotion';
|
$type = 'promotion';
|
||||||
|
} else {
|
||||||
|
$finalPrice = 0;
|
||||||
|
$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,7 +467,9 @@ 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}");
|
||||||
|
if ($premiumPrice === null || $premiumPrice == "0") {
|
||||||
|
$premiumPrice = $db->selectValue(
|
||||||
'SELECT c.category_price
|
'SELECT c.category_price
|
||||||
FROM premium_domain_pricing p
|
FROM premium_domain_pricing p
|
||||||
JOIN premium_domain_categories c ON p.category_id = c.category_id
|
JOIN premium_domain_categories c ON p.category_id = c.category_id
|
||||||
|
@ -475,6 +477,11 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = '
|
||||||
[$domain_name, $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);
|
||||||
$result = ['type' => 'premium', 'price' => formatMoney($money)];
|
$result = ['type' => 'premium', 'price' => formatMoney($money)];
|
||||||
|
@ -485,7 +492,9 @@ 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);
|
||||||
|
if ($promo === null) {
|
||||||
|
$promo = $db->selectRow(
|
||||||
"SELECT discount_percentage, discount_amount
|
"SELECT discount_percentage, discount_amount
|
||||||
FROM promotion_pricing
|
FROM promotion_pricing
|
||||||
WHERE tld_id = ?
|
WHERE tld_id = ?
|
||||||
|
@ -499,10 +508,13 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = '
|
||||||
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);
|
||||||
|
if ($regularPrice === null || $regularPrice == 0) {
|
||||||
|
$regularPrice = $db->selectValue(
|
||||||
"SELECT $priceColumn
|
"SELECT $priceColumn
|
||||||
FROM domain_price
|
FROM domain_price
|
||||||
WHERE tldid = ? AND command = ?
|
WHERE tldid = ? AND command = ?
|
||||||
|
@ -511,11 +523,17 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = '
|
||||||
[$tld_id, $command, $registrar_id]
|
[$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 ($finalPrice > 0) {
|
||||||
if (!empty($promo['discount_percentage'])) {
|
if (!empty($promo['discount_percentage'])) {
|
||||||
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
||||||
} else {
|
} else {
|
||||||
|
@ -523,6 +541,10 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = '
|
||||||
}
|
}
|
||||||
$finalPrice = max(0, $finalPrice - $discountAmount);
|
$finalPrice = max(0, $finalPrice - $discountAmount);
|
||||||
$type = 'promotion';
|
$type = 'promotion';
|
||||||
|
} else {
|
||||||
|
$finalPrice = 0;
|
||||||
|
$type = 'promotion';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$type = 'regular';
|
$type = 'regular';
|
||||||
}
|
}
|
||||||
|
|
|
@ -671,7 +671,11 @@ 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}";
|
||||||
|
$premiumPrice = json_decode($redis->get($premiumCacheKey), true);
|
||||||
|
|
||||||
|
if ($premiumPrice === null || $premiumPrice == 0) {
|
||||||
|
$premiumPrice = fetchSingleValue(
|
||||||
$pdo,
|
$pdo,
|
||||||
'SELECT c.category_price
|
'SELECT c.category_price
|
||||||
FROM premium_domain_pricing p
|
FROM premium_domain_pricing p
|
||||||
|
@ -680,6 +684,11 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
[$domain_name, $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);
|
||||||
$result = ['type' => 'premium', 'price' => formatMoney($money)];
|
$result = ['type' => 'premium', 'price' => formatMoney($money)];
|
||||||
|
@ -690,7 +699,11 @@ 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}";
|
||||||
|
$promo = json_decode($redis->get($promoCacheKey), true);
|
||||||
|
|
||||||
|
if ($promo === null) {
|
||||||
|
$promo = fetchSingleRow(
|
||||||
$pdo,
|
$pdo,
|
||||||
"SELECT discount_percentage, discount_amount
|
"SELECT discount_percentage, discount_amount
|
||||||
FROM promotion_pricing
|
FROM promotion_pricing
|
||||||
|
@ -703,12 +716,17 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($promo) {
|
if ($promo) {
|
||||||
$redis->setex("promo_{$tld_id}", 3600, json_encode($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}";
|
||||||
|
$regularPrice = json_decode($redis->get($regularPriceCacheKey), true);
|
||||||
|
|
||||||
|
if ($regularPrice === null || $regularPrice == 0) {
|
||||||
|
$regularPrice = fetchSingleValue(
|
||||||
$pdo,
|
$pdo,
|
||||||
"SELECT $priceColumn
|
"SELECT $priceColumn
|
||||||
FROM domain_price
|
FROM domain_price
|
||||||
|
@ -718,11 +736,17 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
[$tld_id, $command, $registrar_id]
|
[$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 ($finalPrice > 0) {
|
||||||
if (!empty($promo['discount_percentage'])) {
|
if (!empty($promo['discount_percentage'])) {
|
||||||
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
$discountAmount = (int) ($finalPrice * ($promo['discount_percentage'] / 100));
|
||||||
} else {
|
} else {
|
||||||
|
@ -730,6 +754,10 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command =
|
||||||
}
|
}
|
||||||
$finalPrice = max(0, $finalPrice - $discountAmount);
|
$finalPrice = max(0, $finalPrice - $discountAmount);
|
||||||
$type = 'promotion';
|
$type = 'promotion';
|
||||||
|
} else {
|
||||||
|
$finalPrice = 0;
|
||||||
|
$type = 'promotion';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$type = 'regular';
|
$type = 'regular';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue