From a8a4c44590d7ae36c9a5fc81ea48de6c98eda1f4 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Fri, 15 Dec 2023 07:06:36 +0200 Subject: [PATCH] Added new pricing calculation method; testing needed --- automation/auto-approve-transfer.php | 5 +- automation/change-domain-status.php | 3 +- automation/helpers.php | 63 +++++++++++++++++++++ cp/app/Controllers/DomainsController.php | 70 ++++++++---------------- cp/bootstrap/helper.php | 60 ++++++++++++++++++++ epp/src/epp-create.php | 13 ++--- epp/src/epp-delete.php | 27 +++++---- epp/src/epp-renew.php | 21 +++---- epp/src/epp-transfer.php | 17 +++--- epp/src/helpers.php | 63 +++++++++++++++++++++ 10 files changed, 250 insertions(+), 92 deletions(-) diff --git a/automation/auto-approve-transfer.php b/automation/auto-approve-transfer.php index 1d118fb..5eb051e 100644 --- a/automation/auto-approve-transfer.php +++ b/automation/auto-approve-transfer.php @@ -47,8 +47,9 @@ try { break; } } - - [$price] = $dbh->query("SELECT m$date_add FROM domain_price WHERE tldid = '$tld_id' AND command = 'transfer' LIMIT 1")->fetch(PDO::FETCH_NUM); + + $returnValue = getDomainPrice($dbh, $name, $tld_id, $date_add, 'transfer'); + $price = $returnValue['price']; if (($registrar_balance + $creditLimit) < $price) { $log->notice($name . ': The registrar who took over this domain has no money to pay the renewal period that resulted from the transfer request'); diff --git a/automation/change-domain-status.php b/automation/change-domain-status.php index 63d98bb..3039023 100644 --- a/automation/change-domain-status.php +++ b/automation/change-domain-status.php @@ -44,7 +44,8 @@ try { if ($set_autorenewPeriod) { list($registrar_balance, $creditLimit) = $dbh->query("SELECT accountBalance, creditLimit FROM registrar WHERE id = '$clid' LIMIT 1")->fetch(PDO::FETCH_NUM); - $price = $dbh->query("SELECT m12 FROM domain_price WHERE tldid = '$tldid' AND command = 'renew' LIMIT 1")->fetchColumn(); + $returnValue = getDomainPrice($dbh, $name, $tldid, 12, 'renew'); + $price = $returnValue['price']; if (($registrar_balance + $creditLimit) > $price) { $dbh->exec("UPDATE domain SET rgpstatus = 'autoRenewPeriod', exdate = DATE_ADD(exdate, INTERVAL 12 MONTH), autoRenewPeriod = '12', renewedDate = exdate WHERE id = '$domain_id'"); diff --git a/automation/helpers.php b/automation/helpers.php index fa1d287..e3d8ffd 100644 --- a/automation/helpers.php +++ b/automation/helpers.php @@ -102,4 +102,67 @@ function processUrlhausData($data) { function checkUrlhaus($domain, Map $urlhausData) { return $urlhausData->get($domain, false); +} + +function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = 'create') { + // Check if the domain is a premium domain + $stmt = $pdo->prepare(" + 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 = ? + "); + $stmt->execute([$domain_name, $tld_id]); + if ($stmt->rowCount() > 0) { + return ['type' => 'premium', 'price' => $stmt->fetch()['category_price']]; + } + + // Check if there is a promotion for the domain + $currentDate = date('Y-m-d'); + $stmt = $pdo->prepare(" + SELECT discount_percentage, discount_amount + FROM promotion_pricing + WHERE tld_id = ? + AND promo_type = 'full' + AND status = 'active' + AND start_date <= ? + AND end_date >= ? + "); + $stmt->execute([$tld_id, $currentDate, $currentDate]); + if ($stmt->rowCount() > 0) { + $promo = $stmt->fetch(); + $discount = null; + + // Determine discount based on percentage or amount + if (!empty($promo['discount_percentage'])) { + $discount = $promo['discount_percentage']; // Percentage discount + } elseif (!empty($promo['discount_amount'])) { + $discount = $promo['discount_amount']; // Fixed amount discount + } + } else { + $discount = null; + } + + // Get regular price for the specified period + $priceColumn = "m" . $date_add; + $stmt = $pdo->prepare("SELECT $priceColumn FROM domain_price WHERE tldid = ? AND command = '$command' LIMIT 1"); + $stmt->execute([$tld_id]); + + if ($stmt->rowCount() > 0) { + $regularPrice = $stmt->fetch()[$priceColumn]; + + if ($discount !== null) { + if (isset($promo['discount_percentage'])) { + $discountAmount = $regularPrice * ($promo['discount_percentage'] / 100); + } else { + $discountAmount = $discount; + } + $price = $regularPrice - $discountAmount; + return ['type' => 'promotion', 'price' => $price]; + } + + return ['type' => 'regular', 'price' => $regularPrice]; + } + + return ['type' => 'not_found', 'price' => 0]; } \ No newline at end of file diff --git a/cp/app/Controllers/DomainsController.php b/cp/app/Controllers/DomainsController.php index 955dc19..138b710 100644 --- a/cp/app/Controllers/DomainsController.php +++ b/cp/app/Controllers/DomainsController.php @@ -192,12 +192,9 @@ class DomainsController extends Controller $registrar_balance = $result['accountBalance']; $creditLimit = $result['creditLimit']; - - $priceColumn = "m" . $date_add; - $price = $db->selectValue( - 'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "create" LIMIT 1', - [$tld_id] - ); + + $returnValue = getDomainPrice($db, $domainName, $tld_id, $date_add, 'create'); + $price = $returnValue['price']; if (!$price) { return view($response, 'admin/domains/createDomain.twig', [ @@ -1472,12 +1469,9 @@ class DomainsController extends Controller $registrar_balance = $result['accountBalance']; $creditLimit = $result['creditLimit']; - - $priceColumn = "m" . $date_add; - $price = $db->selectValue( - 'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "renew" LIMIT 1', - [$tld_id] - ); + + $returnValue = getDomainPrice($db, $domainName, $tld_id, $date_add, 'renew'); + $price = $returnValue['price']; if (!$price) { $this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared'); @@ -1773,12 +1767,9 @@ class DomainsController extends Controller ] ); if ($addPeriod_id) { - $priceColumn = "m" . $addPeriod; - $price = $db->selectValue( - 'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "create" LIMIT 1', - [$tld_id] - ); - + $returnValue = getDomainPrice($db, $domainName, $tld_id, $addPeriod, 'create'); + $price = $returnValue['price']; + if (!$price) { $this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared'); return $response->withHeader('Location', '/domains')->withStatus(302); @@ -1901,12 +1892,9 @@ class DomainsController extends Controller ] ); if ($autoRenewPeriod_id) { - $priceColumn = "m" . $autoRenewPeriod; - $price = $db->selectValue( - 'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "renew" LIMIT 1', - [$tld_id] - ); - + $returnValue = getDomainPrice($db, $domainName, $tld_id, $autoRenewPeriod, 'renew'); + $price = $returnValue['price']; + if (!$price) { $this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared'); return $response->withHeader('Location', '/domains')->withStatus(302); @@ -1931,11 +1919,8 @@ class DomainsController extends Controller ] ); if ($renewPeriod_id) { - $priceColumn = "m" . $renewPeriod; - $price = $db->selectValue( - 'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "renew" LIMIT 1', - [$tld_id] - ); + $returnValue = getDomainPrice($db, $domainName, $tld_id, $renewPeriod, 'renew'); + $price = $returnValue['price']; if (!$price) { $this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared'); @@ -1961,12 +1946,9 @@ class DomainsController extends Controller ] ); if ($transferPeriod_id) { - $priceColumn = "m" . $transferPeriod; - $price = $db->selectValue( - 'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "renew" LIMIT 1', - [$tld_id] - ); - + $returnValue = getDomainPrice($db, $domainName, $tld_id, $transferPeriod, 'renew'); + $price = $returnValue['price']; + if (!$price) { $this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared'); return $response->withHeader('Location', '/domains')->withStatus(302); @@ -2149,12 +2131,9 @@ class DomainsController extends Controller $result = $db->selectRow('SELECT accountBalance, creditLimit FROM registrar WHERE id = ?', [$clid]); $registrar_balance = $result['accountBalance']; $creditLimit = $result['creditLimit']; - - $priceColumn = "m" . $date_add; - $price = $db->selectValue( - 'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "transfer" LIMIT 1', - [$tldid] - ); + + $returnValue = getDomainPrice($db, $domainName, $tldid, $date_add, 'transfer'); + $price = $returnValue['price']; if (!$price) { $this->container->get('flash')->addMessage('error', 'The price, period and currency for such TLD are not declared'); @@ -2381,12 +2360,9 @@ class DomainsController extends Controller ] ); - $priceColumn = "m" . $date_add; - $price = $db->selectValue( - 'SELECT ' . $db->quoteIdentifier($priceColumn) . ' FROM domain_price WHERE tldid = ? AND command = "transfer" LIMIT 1', - [$tldid] - ); - + $returnValue = getDomainPrice($db, $domainName, $tldid, $date_add, 'transfer'); + $price = $returnValue['price']; + if (($registrar_balance + $creditLimit) < $price) { $this->container->get('flash')->addMessage('error', 'The registrar who took over this domain has no money to pay the renewal period that resulted from the transfer request'); return $response->withHeader('Location', '/transfers')->withStatus(302); diff --git a/cp/bootstrap/helper.php b/cp/bootstrap/helper.php index a9b4fa7..ff8828b 100644 --- a/cp/bootstrap/helper.php +++ b/cp/bootstrap/helper.php @@ -307,4 +307,64 @@ function extractDomainAndTLD($urlString) { $tld = $result->suffix()->toString(); return ['domain' => $sld, 'tld' => $tld]; +} + +function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = 'create') { + // Check if the domain is a premium domain + $premiumDomain = $db->selectRow( + '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 ($premiumDomain) { + return ['type' => 'premium', 'price' => $premiumDomain['category_price']]; + } + + // Check if there is a promotion for the domain + $currentDate = date('Y-m-d'); + $promo = $db->selectRow( + "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] + ); + + $discount = null; + if ($promo) { + if (!empty($promo['discount_percentage'])) { + $discount = $promo['discount_percentage']; // Percentage discount + } elseif (!empty($promo['discount_amount'])) { + $discount = $promo['discount_amount']; // Fixed amount discount + } + } + + // Get regular price for the specified period + $priceColumn = "m" . $date_add; + $regularPrice = $db->selectValue( + "SELECT $priceColumn FROM domain_price WHERE tldid = ? AND command = ? LIMIT 1", + [$tld_id, $command] + ); + + if ($regularPrice !== false) { + if ($discount !== null) { + if (isset($promo['discount_percentage'])) { + $discountAmount = $regularPrice * ($promo['discount_percentage'] / 100); + } else { + $discountAmount = $discount; + } + $price = $regularPrice - $discountAmount; + return ['type' => 'promotion', 'price' => $price]; + } + + return ['type' => 'regular', 'price' => $regularPrice]; + } + + return ['type' => 'not_found', 'price' => 0]; } \ No newline at end of file diff --git a/epp/src/epp-create.php b/epp/src/epp-create.php index bc49ceb..4625fdc 100644 --- a/epp/src/epp-create.php +++ b/epp/src/epp-create.php @@ -493,12 +493,12 @@ function processHostCreate($conn, $db, $xml, $clid, $database_type, $trans) { foreach ($host_addr_list as $node) { $addr = (string) $node; - + if (empty($addr)) { sendEppError($conn, $db, 2303, 'Error: Address is empty', $clTRID, $trans); return; } - + $addr_type = isset($node['ip']) ? (string) $node['ip'] : 'v4'; if ($addr_type == 'v6') { @@ -671,12 +671,9 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans) { $result = $stmt->fetch(PDO::FETCH_ASSOC); $registrar_balance = $result['accountBalance']; $creditLimit = $result['creditLimit']; - - $priceColumn = "m" . $date_add; - $stmt = $db->prepare("SELECT $priceColumn FROM domain_price WHERE tldid = :tld_id AND command = 'create' LIMIT 1"); - $stmt->bindParam(':tld_id', $tld_id, PDO::PARAM_INT); - $stmt->execute(); - $price = $stmt->fetchColumn(); + + $returnValue = getDomainPrice($db, $domainName, $tld_id, $date_add, 'create'); + $price = $returnValue['price']; if (!$price) { sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans); diff --git a/epp/src/epp-delete.php b/epp/src/epp-delete.php index 0d66329..ddd3da1 100644 --- a/epp/src/epp-delete.php +++ b/epp/src/epp-delete.php @@ -174,6 +174,13 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) { return; } + $invalid_domain = validate_label($domainName, $db); + + if ($invalid_domain) { + sendEppError($conn, $db, 2306, 'Invalid domain:name', $clTRID, $trans); + return; + } + $stmt = $db->prepare("SELECT id, tldid, registrant, crdate, exdate, clid, crid, upid, trdate, trstatus, reid, redate, acid, acdate, rgpstatus, addPeriod, autoRenewPeriod, renewPeriod, renewedDate, transferPeriod FROM domain WHERE name = :name LIMIT 1"); $stmt->execute([':name' => $domainName]); $result = $stmt->fetch(PDO::FETCH_ASSOC); @@ -246,9 +253,8 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) { $addPeriod_id = $stmt->fetchColumn(); if ($addPeriod_id) { - $stmt = $db->prepare("SELECT m$addPeriod FROM domain_price WHERE tldid = ? AND command = 'create' LIMIT 1"); - $stmt->execute([$tldid]); - $price = $stmt->fetchColumn(); + $returnValue = getDomainPrice($db, $domainName, $tldid, $addPeriod, 'create'); + $price = $returnValue['price']; if (!isset($price)) { sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans); @@ -305,9 +311,8 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) { $autoRenewPeriod_id = $stmt->fetchColumn(); if ($autoRenewPeriod_id) { - $stmt = $db->prepare("SELECT m$autoRenewPeriod FROM domain_price WHERE tldid = ? AND command = 'renew' LIMIT 1"); - $stmt->execute([$tldid]); - $price = $stmt->fetchColumn(); + $returnValue = getDomainPrice($db, $domainName, $tldid, $autoRenewPeriod, 'renew'); + $price = $returnValue['price']; if (!isset($price)) { sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans); @@ -329,9 +334,8 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) { $renewPeriod_id = $stmt->fetchColumn(); if ($renewPeriod_id) { - $stmt = $db->prepare("SELECT m$renewPeriod FROM domain_price WHERE tldid = ? AND command = 'renew' LIMIT 1"); - $stmt->execute([$tldid]); - $price = $stmt->fetchColumn(); + $returnValue = getDomainPrice($db, $domainName, $tldid, $renewPeriod, 'renew'); + $price = $returnValue['price']; if (!isset($price)) { sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans); @@ -355,9 +359,8 @@ function processDomainDelete($conn, $db, $xml, $clid, $database_type, $trans) { if ($transferPeriod_id) { // Return money if a transfer was also a renew if ($transferPeriod > 0) { - $stmt = $db->prepare("SELECT m$transferPeriod FROM domain_price WHERE tldid = ? AND command = 'renew' LIMIT 1"); - $stmt->execute([$tldid]); - $price = $stmt->fetchColumn(); + $returnValue = getDomainPrice($db, $domainName, $tldid, $transferPeriod, 'renew'); + $price = $returnValue['price']; if (!isset($price)) { sendEppError($conn, $db, 2400, 'The price, period and currency for such TLD are not declared', $clTRID, $trans); diff --git a/epp/src/epp-renew.php b/epp/src/epp-renew.php index 257f355..e8a36ac 100644 --- a/epp/src/epp-renew.php +++ b/epp/src/epp-renew.php @@ -43,7 +43,7 @@ function processDomainRenew($conn, $db, $xml, $clid, $database_type, $trans) { $stmt->execute(); $clid = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt = $db->prepare("SELECT id, tldid, exdate, clid FROM domain WHERE name = :domainName LIMIT 1"); + $stmt = $db->prepare("SELECT id, name, tldid, exdate, clid FROM domain WHERE name = :domainName LIMIT 1"); $stmt->bindParam(':domainName', $domainName, PDO::PARAM_STR); $stmt->execute(); $domainData = $stmt->fetch(PDO::FETCH_ASSOC); @@ -57,7 +57,7 @@ function processDomainRenew($conn, $db, $xml, $clid, $database_type, $trans) { sendEppError($conn, $db, 2201, 'It belongs to another registrar', $clTRID, $trans); return; } - + // The domain name must not be subject to clientRenewProhibited, serverRenewProhibited. $stmt = $db->prepare("SELECT status FROM domain_status WHERE domain_id = :domainId"); $stmt->bindParam(':domainId', $domainData['id'], PDO::PARAM_INT); @@ -112,18 +112,15 @@ function processDomainRenew($conn, $db, $xml, $clid, $database_type, $trans) { $row = $stmt->fetch(PDO::FETCH_ASSOC); $registrar_balance = $row['accountBalance']; $creditLimit = $row['creditLimit']; - - $columnName = "m$date_add"; - $stmt = $db->prepare("SELECT $columnName FROM domain_price WHERE tldid = :tldid AND command = 'renew' LIMIT 1"); - $stmt->bindParam(':tldid', $domainData['tldid'], PDO::PARAM_INT); - $stmt->execute(); - $price = $stmt->fetchColumn(); + + $returnValue = getDomainPrice($db, $domainData['name'], $domainData['tldid'], $date_add, 'renew'); + $price = $returnValue['price']; if (($registrar_balance + $creditLimit) < $price) { sendEppError($conn, $db, 2104, 'There is no money on the account to renew', $clTRID, $trans); return; } - + $stmt = $db->prepare("SELECT exdate FROM domain WHERE id = :domain_id LIMIT 1"); $stmt->bindParam(':domain_id', $domainData['id'], PDO::PARAM_INT); $stmt->execute(); @@ -151,8 +148,8 @@ function processDomainRenew($conn, $db, $xml, $clid, $database_type, $trans) { $stmt->execute(); // Insert into payment_history: - $description = "renew domain $domainName for period $date_add MONTH"; - $negative_price = -$price; + $description = "renew domain $domainName for period $date_add MONTH"; + $negative_price = -$price; $stmt = $db->prepare("INSERT INTO payment_history (registrar_id, date, description, amount) VALUES (:registrar_id, CURRENT_TIMESTAMP(3), :description, :amount)"); $stmt->bindParam(':registrar_id', $clid['id'], PDO::PARAM_INT); $stmt->bindParam(':description', $description, PDO::PARAM_STR); @@ -170,7 +167,7 @@ function processDomainRenew($conn, $db, $xml, $clid, $database_type, $trans) { $stmt->execute([$clid['id'], 'renew', $domainName, $date_add, $from, $to, $price]); } } - + // Fetch exdate for the given domain name $stmt = $db->prepare("SELECT exdate FROM domain WHERE name = :name LIMIT 1"); $stmt->bindParam(':name', $domainName, PDO::PARAM_STR); diff --git a/epp/src/epp-transfer.php b/epp/src/epp-transfer.php index 845a82c..5c51a14 100644 --- a/epp/src/epp-transfer.php +++ b/epp/src/epp-transfer.php @@ -466,16 +466,15 @@ function processDomainTransfer($conn, $db, $xml, $clid, $database_type, $trans) $stmt->execute([$domainName]); $date_add = $stmt->fetchColumn(); - $stmt = $db->prepare("SELECT m$date_add FROM domain_price WHERE tldid = ? AND command = 'transfer' LIMIT 1"); - $stmt->execute([$tldid]); - $price = $stmt->fetchColumn(); - + $returnValue = getDomainPrice($db, $domainName, $tldid, $date_add, 'transfer'); + $price = $returnValue['price']; + if (($registrar_balance + $creditLimit) < $price) { sendEppError($conn, $db, 2104, 'The registrar who took over this domain has no money to pay the renewal period that resulted from the transfer request', $clTRID, $trans); return; } } - + $stmt = $db->prepare("SELECT exdate FROM domain WHERE id = :domain_id LIMIT 1"); $stmt->execute(['domain_id' => $domain_id]); $from = $stmt->fetchColumn(); @@ -865,11 +864,9 @@ function processDomainTransfer($conn, $db, $xml, $clid, $database_type, $trans) $result = $stmt->fetch(PDO::FETCH_ASSOC); $registrar_balance = $result["accountBalance"]; $creditLimit = $result["creditLimit"]; - - $stmt = $db->prepare("SELECT m$date_add FROM domain_price WHERE tldid = :tldid AND command = 'transfer' LIMIT 1"); - $stmt->execute([':tldid' => $tldid]); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - $price = $result["m$date_add"]; + + $returnValue = getDomainPrice($db, $domainName, $tldid, $date_add, 'transfer'); + $price = $returnValue['price']; if (($registrar_balance + $creditLimit) < $price) { sendEppError($conn, $db, 2104, 'The registrar who wants to take over this domain has no money', $clTRID, $trans); diff --git a/epp/src/helpers.php b/epp/src/helpers.php index 0431d93..f63300f 100644 --- a/epp/src/helpers.php +++ b/epp/src/helpers.php @@ -490,4 +490,67 @@ function updatePermittedIPs($pool, $permittedIPsTable) { foreach ($permittedIPs as $ip) { $permittedIPsTable->set($ip, ['addr' => $ip]); } +} + +function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = 'create') { + // Check if the domain is a premium domain + $stmt = $pdo->prepare(" + 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 = ? + "); + $stmt->execute([$domain_name, $tld_id]); + if ($stmt->rowCount() > 0) { + return ['type' => 'premium', 'price' => $stmt->fetch()['category_price']]; + } + + // Check if there is a promotion for the domain + $currentDate = date('Y-m-d'); + $stmt = $pdo->prepare(" + SELECT discount_percentage, discount_amount + FROM promotion_pricing + WHERE tld_id = ? + AND promo_type = 'full' + AND status = 'active' + AND start_date <= ? + AND end_date >= ? + "); + $stmt->execute([$tld_id, $currentDate, $currentDate]); + if ($stmt->rowCount() > 0) { + $promo = $stmt->fetch(); + $discount = null; + + // Determine discount based on percentage or amount + if (!empty($promo['discount_percentage'])) { + $discount = $promo['discount_percentage']; // Percentage discount + } elseif (!empty($promo['discount_amount'])) { + $discount = $promo['discount_amount']; // Fixed amount discount + } + } else { + $discount = null; + } + + // Get regular price for the specified period + $priceColumn = "m" . $date_add; + $stmt = $pdo->prepare("SELECT $priceColumn FROM domain_price WHERE tldid = ? AND command = '$command' LIMIT 1"); + $stmt->execute([$tld_id]); + + if ($stmt->rowCount() > 0) { + $regularPrice = $stmt->fetch()[$priceColumn]; + + if ($discount !== null) { + if (isset($promo['discount_percentage'])) { + $discountAmount = $regularPrice * ($promo['discount_percentage'] / 100); + } else { + $discountAmount = $discount; + } + $price = $regularPrice - $discountAmount; + return ['type' => 'promotion', 'price' => $price]; + } + + return ['type' => 'regular', 'price' => $regularPrice]; + } + + return ['type' => 'not_found', 'price' => 0]; } \ No newline at end of file