mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-13 16:16:59 +02:00
Create, renew, transfer - calculate correct prices in CP
This commit is contained in:
parent
e2a7e9b054
commit
a2d8f53c23
4 changed files with 60 additions and 23 deletions
|
@ -892,11 +892,11 @@ class SystemController extends Controller
|
||||||
[ $args ]);
|
[ $args ]);
|
||||||
|
|
||||||
if ($tld) {
|
if ($tld) {
|
||||||
$createPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id = ? AND command = ?', [$tld['id'], NULL, 'create']);
|
$createPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id IS NULL AND command = ?', [$tld['id'], 'create']);
|
||||||
$renewPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id = ? AND command = ?', [$tld['id'], NULL, 'renew']);
|
$renewPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id IS NULL AND command = ?', [$tld['id'], 'renew']);
|
||||||
$transferPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id = ? AND command = ?', [$tld['id'], NULL, 'transfer']);
|
$transferPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id IS NULL AND command = ?', [$tld['id'], 'transfer']);
|
||||||
$tld_restore = $db->selectRow('SELECT * FROM domain_restore_price WHERE tldid = ? AND registrar_id = ? ',
|
$tld_restore = $db->selectRow('SELECT * FROM domain_restore_price WHERE tldid = ? AND registrar_id IS NULL ',
|
||||||
[ $tld['id'], NULL ]);
|
[ $tld['id'] ]);
|
||||||
$premium_pricing = $db->selectRow('SELECT * FROM premium_domain_pricing WHERE tld_id = ?',
|
$premium_pricing = $db->selectRow('SELECT * FROM premium_domain_pricing WHERE tld_id = ?',
|
||||||
[ $tld['id'] ]);
|
[ $tld['id'] ]);
|
||||||
$premium_categories = $db->select('SELECT * FROM premium_domain_categories');
|
$premium_categories = $db->select('SELECT * FROM premium_domain_categories');
|
||||||
|
|
|
@ -207,7 +207,7 @@
|
||||||
<option value="custom">Custom</option>
|
<option value="custom">Custom</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="phaseName" class="form-label">{{ __('Phase Name') }}</label>
|
<label for="phaseName" class="form-label">{{ __('Phase Name') }}</label>
|
||||||
<input type="text" class="form-control" id="phaseName" name="phaseName" placeholder="Enter phase name">
|
<input type="text" class="form-control" id="phaseName" name="phaseName" placeholder="Enter phase name">
|
||||||
|
@ -267,6 +267,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
const removeNameserverBtn = document.getElementById('removeNameserver');
|
const removeNameserverBtn = document.getElementById('removeNameserver');
|
||||||
const nameserverFields = document.getElementById('nameserverFields');
|
const nameserverFields = document.getElementById('nameserverFields');
|
||||||
const authInfoField = document.getElementById('authInfo');
|
const authInfoField = document.getElementById('authInfo');
|
||||||
|
const registrarDropdown = document.getElementById('registrarDropdown');
|
||||||
|
|
||||||
// Display year value from slider
|
// Display year value from slider
|
||||||
yearSlider.addEventListener('input', function() {
|
yearSlider.addEventListener('input', function() {
|
||||||
|
@ -371,7 +372,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDomainPrice(domain, years) {
|
function getDomainPrice(domain, years, registrarId) {
|
||||||
const tld = extractTLD(domain);
|
const tld = extractTLD(domain);
|
||||||
if (!tld) {
|
if (!tld) {
|
||||||
return Promise.reject("Invalid TLD");
|
return Promise.reject("Invalid TLD");
|
||||||
|
@ -396,12 +397,22 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
(!record.years_of_promotion || record.years_of_promotion >= years)
|
(!record.years_of_promotion || record.years_of_promotion >= years)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Find the regular price for the TLD
|
// Find the regular price for the TLD with registrar ID
|
||||||
const tldData = pricingData.records.find(record =>
|
let tldData = pricingData.records.find(record =>
|
||||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||||
record.command === 'create'
|
record.command === 'create' &&
|
||||||
|
record.registrar_id == registrarId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// If no registrar-specific price found, find the generic price
|
||||||
|
if (!tldData) {
|
||||||
|
tldData = pricingData.records.find(record =>
|
||||||
|
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||||
|
record.command === 'create' &&
|
||||||
|
record.registrar_id == null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (tldData) {
|
if (tldData) {
|
||||||
const priceField = `m${years * 12}`;
|
const priceField = `m${years * 12}`;
|
||||||
let price = parseFloat(tldData[priceField]);
|
let price = parseFloat(tldData[priceField]);
|
||||||
|
@ -434,7 +445,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
function updatePrice() {
|
function updatePrice() {
|
||||||
if (domainInput.value) {
|
if (domainInput.value) {
|
||||||
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
const registrarId = registrarDropdown.value;
|
||||||
|
getDomainPrice(domainInput.value, yearInput.value, registrarId).then(price => {
|
||||||
priceValue.innerText = formatPrice(price);
|
priceValue.innerText = formatPrice(price);
|
||||||
priceDisplay.style.display = 'block';
|
priceDisplay.style.display = 'block';
|
||||||
});
|
});
|
||||||
|
@ -445,6 +457,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
domainInput.addEventListener('input', updatePrice);
|
domainInput.addEventListener('input', updatePrice);
|
||||||
yearInput.addEventListener('input', updatePrice);
|
yearInput.addEventListener('input', updatePrice);
|
||||||
|
registrarDropdown.addEventListener('change', updatePrice);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -83,7 +83,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
yearSlider.addEventListener('input', function() {
|
yearSlider.addEventListener('input', function() {
|
||||||
yearValueDisplay.textContent = `${yearSlider.value} Year${yearSlider.value > 1 ? 's' : ''}`;
|
yearValueDisplay.textContent = `${yearSlider.value} Year${yearSlider.value > 1 ? 's' : ''}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const registrarId = "{{ registrars.id }}"; // Embedded securely in JavaScript
|
||||||
const domainInput = document.getElementById('domainName');
|
const domainInput = document.getElementById('domainName');
|
||||||
const yearInput = document.getElementById('renewalYears');
|
const yearInput = document.getElementById('renewalYears');
|
||||||
const priceDisplay = document.getElementById('domainPriceDisplay');
|
const priceDisplay = document.getElementById('domainPriceDisplay');
|
||||||
|
@ -102,7 +103,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDomainPrice(domain, years) {
|
function getDomainPrice(domain, years, registrarId) {
|
||||||
const tld = extractTLD(domain);
|
const tld = extractTLD(domain);
|
||||||
if (!tld) {
|
if (!tld) {
|
||||||
return Promise.reject("Invalid TLD");
|
return Promise.reject("Invalid TLD");
|
||||||
|
@ -127,12 +128,22 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
(!record.years_of_promotion || record.years_of_promotion >= years)
|
(!record.years_of_promotion || record.years_of_promotion >= years)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Find the regular price for the TLD
|
// Find the regular price for the TLD with registrar ID
|
||||||
const tldData = pricingData.records.find(record =>
|
let tldData = pricingData.records.find(record =>
|
||||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||||
record.command === 'renew'
|
record.command === 'renew' &&
|
||||||
|
record.registrar_id == registrarId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// If no registrar-specific price found, find the generic price
|
||||||
|
if (!tldData) {
|
||||||
|
tldData = pricingData.records.find(record =>
|
||||||
|
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||||
|
record.command === 'renew' &&
|
||||||
|
record.registrar_id == null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (tldData) {
|
if (tldData) {
|
||||||
const priceField = `m${years * 12}`;
|
const priceField = `m${years * 12}`;
|
||||||
let price = parseFloat(tldData[priceField]);
|
let price = parseFloat(tldData[priceField]);
|
||||||
|
@ -164,8 +175,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePrice() {
|
function updatePrice() {
|
||||||
if (domainInput.value) {
|
if (domainInput.textContent) {
|
||||||
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
getDomainPrice(domainInput.textContent, yearInput.value, registrarId).then(price => {
|
||||||
priceValue.innerText = formatPrice(price);
|
priceValue.innerText = formatPrice(price);
|
||||||
priceDisplay.style.display = 'block';
|
priceDisplay.style.display = 'block';
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
|
|
@ -101,6 +101,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
const yearInput = document.getElementById('transferYears');
|
const yearInput = document.getElementById('transferYears');
|
||||||
const priceDisplay = document.getElementById('domainPriceDisplay');
|
const priceDisplay = document.getElementById('domainPriceDisplay');
|
||||||
const priceValue = document.getElementById('domainPrice');
|
const priceValue = document.getElementById('domainPrice');
|
||||||
|
const registrarDropdown = document.getElementById('registrarDropdown');
|
||||||
|
|
||||||
function extractTLD(domain) {
|
function extractTLD(domain) {
|
||||||
const parts = domain.split('.');
|
const parts = domain.split('.');
|
||||||
|
@ -115,7 +116,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDomainPrice(domain, years) {
|
function getDomainPrice(domain, years, registrarId) {
|
||||||
const tld = extractTLD(domain);
|
const tld = extractTLD(domain);
|
||||||
if (!tld) {
|
if (!tld) {
|
||||||
return Promise.reject("Invalid TLD");
|
return Promise.reject("Invalid TLD");
|
||||||
|
@ -140,12 +141,22 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
(!record.years_of_promotion || record.years_of_promotion >= years)
|
(!record.years_of_promotion || record.years_of_promotion >= years)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Find the regular price for the TLD
|
// Find the regular price for the TLD with registrar ID
|
||||||
const tldData = pricingData.records.find(record =>
|
let tldData = pricingData.records.find(record =>
|
||||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||||
record.command === 'transfer'
|
record.command === 'transfer' &&
|
||||||
|
record.registrar_id == registrarId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// If no registrar-specific price found, find the generic price
|
||||||
|
if (!tldData) {
|
||||||
|
tldData = pricingData.records.find(record =>
|
||||||
|
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||||
|
record.command === 'transfer' &&
|
||||||
|
record.registrar_id == null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (tldData) {
|
if (tldData) {
|
||||||
const priceField = `m${years * 12}`;
|
const priceField = `m${years * 12}`;
|
||||||
let price = parseFloat(tldData[priceField]);
|
let price = parseFloat(tldData[priceField]);
|
||||||
|
@ -178,7 +189,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
function updatePrice() {
|
function updatePrice() {
|
||||||
if (domainInput.value) {
|
if (domainInput.value) {
|
||||||
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
const registrarId = registrarDropdown.value;
|
||||||
|
getDomainPrice(domainInput.value, yearInput.value, registrarId).then(price => {
|
||||||
priceValue.innerText = formatPrice(price);
|
priceValue.innerText = formatPrice(price);
|
||||||
priceDisplay.style.display = 'block';
|
priceDisplay.style.display = 'block';
|
||||||
});
|
});
|
||||||
|
@ -189,6 +201,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
domainInput.addEventListener('input', updatePrice);
|
domainInput.addEventListener('input', updatePrice);
|
||||||
yearInput.addEventListener('input', updatePrice);
|
yearInput.addEventListener('input', updatePrice);
|
||||||
|
registrarDropdown.addEventListener('change', updatePrice);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue