mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-16 17:46:59 +02:00
Added new pricing calculation method; testing needed
This commit is contained in:
parent
a07c407543
commit
a8a4c44590
10 changed files with 250 additions and 92 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue