mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-15 05:43:55 +02:00
Added domain price fetch and calculation
This commit is contained in:
parent
fc72a57bdd
commit
831cc77be3
3 changed files with 650 additions and 578 deletions
|
@ -665,9 +665,23 @@ class DomainsController extends Controller
|
||||||
$db = $this->container->get('db');
|
$db = $this->container->get('db');
|
||||||
$registrars = $db->select("SELECT id, clid, name FROM registrar");
|
$registrars = $db->select("SELECT id, clid, name FROM registrar");
|
||||||
|
|
||||||
|
$locale = (isset($_SESSION['_lang']) && !empty($_SESSION['_lang'])) ? $_SESSION['_lang'] : 'en_US';
|
||||||
|
$currency = $_SESSION['_currency'] ?? 'USD'; // Default to USD if not set
|
||||||
|
|
||||||
|
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
||||||
|
$formatter->setTextAttribute(\NumberFormatter::CURRENCY_CODE, $currency);
|
||||||
|
|
||||||
|
$symbol = $formatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
|
||||||
|
$pattern = $formatter->getPattern();
|
||||||
|
|
||||||
|
// Determine currency position (before or after)
|
||||||
|
$position = (strpos($pattern, '¤') < strpos($pattern, '#')) ? 'before' : 'after';
|
||||||
|
|
||||||
// Default view for GET requests or if POST data is not set
|
// Default view for GET requests or if POST data is not set
|
||||||
return view($response,'admin/domains/create.twig', [
|
return view($response,'admin/domains/create.twig', [
|
||||||
'registrars' => $registrars,
|
'registrars' => $registrars,
|
||||||
|
'currencySymbol' => $symbol,
|
||||||
|
'currencyPosition' => $position
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,22 @@ $container->set('view', function ($container) use ($translations, $uiLang, $lang
|
||||||
$view->getEnvironment()->addGlobal('screen_mode', 'light');
|
$view->getEnvironment()->addGlobal('screen_mode', 'light');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$db = $container->get('db');
|
||||||
|
$query = 'SELECT r.currency
|
||||||
|
FROM registrar_users ru
|
||||||
|
JOIN registrar r ON ru.registrar_id = r.id
|
||||||
|
WHERE ru.user_id = ?';
|
||||||
|
|
||||||
|
$result = $db->select($query, [$_SESSION['auth_user_id']]);
|
||||||
|
|
||||||
|
$_SESSION['_currency'] = 'USD'; // default value
|
||||||
|
|
||||||
|
if ($result !== null && isset($result[0]['currency'])) {
|
||||||
|
$_SESSION['_currency'] = $result[0]['currency'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$view->getEnvironment()->addGlobal('currency', $_SESSION['_currency']);
|
||||||
|
|
||||||
$translateFunction = new TwigFunction('__', function ($text) use ($translations) {
|
$translateFunction = new TwigFunction('__', function ($text) use ($translations) {
|
||||||
// Find the translation
|
// Find the translation
|
||||||
$translation = $translations->find(null, $text);
|
$translation = $translations->find(null, $text);
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
<form id="domainCreateForm" action="/domain/create" method="post">
|
<form id="domainCreateForm" action="/domain/create" method="post">
|
||||||
{{ csrf.field | raw }}
|
{{ csrf.field | raw }}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="domainName" class="form-label required">Your Domain Name</label>
|
<label for="domainName" class="form-label required">{{ __('Your Domain Name') }}</label>
|
||||||
<input type="text" class="form-control mb-2" placeholder="example.com" name="domainName" id="domainName" required="required">
|
<input type="text" class="form-control mb-2" placeholder="example.com" name="domainName" id="domainName" required="required">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -71,50 +71,50 @@
|
||||||
|
|
||||||
<!-- Slider for years -->
|
<!-- Slider for years -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="registrationYears" class="form-label">Registration Years</label>
|
<label for="registrationYears" class="form-label">{{ __('Registration Years') }}</label>
|
||||||
<input type="range" class="form-range" min="1" max="10" step="1" id="registrationYears" name="registrationYears" value="1">
|
<input type="range" class="form-range" min="1" max="10" step="1" id="registrationYears" name="registrationYears" value="1">
|
||||||
<span id="yearValue">1 Year</span>
|
<span id="yearValue">1 Year</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Placeholder for displaying domain price -->
|
<!-- Placeholder for displaying domain price -->
|
||||||
<div class="mb-3" id="domainPriceDisplay" style="display:none;">
|
<div class="mb-3" id="domainPriceDisplay" style="display:none;">
|
||||||
<strong>Estimated Price: </strong><span id="domainPrice">$0.00</span>
|
<strong>{{ __('Estimated Price') }}: </strong><span id="domainPrice">$0.00</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Fields for 4 contacts with roles -->
|
<!-- Fields for 4 contacts with roles -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="contactRegistrant" class="form-label required">Contacts</label>
|
<label for="contactRegistrant" class="form-label required">{{ __('Contacts') }}</label>
|
||||||
<input type="text" class="form-control mb-2" placeholder="Registrant Contact" name="contactRegistrant" id="contactRegistrant" required="required">
|
<input type="text" class="form-control mb-2" placeholder="{{ __('Registrant Contact') }}" name="contactRegistrant" id="contactRegistrant" required="required">
|
||||||
<input type="text" class="form-control mb-2" placeholder="Admin Contact" name="contactAdmin">
|
<input type="text" class="form-control mb-2" placeholder="{{ __('Admin Contact') }}" name="contactAdmin">
|
||||||
<input type="text" class="form-control mb-2" placeholder="Tech Contact" name="contactTech">
|
<input type="text" class="form-control mb-2" placeholder="{{ __('Tech Contact') }}" name="contactTech">
|
||||||
<input type="text" class="form-control mb-2" placeholder="Billing Contact" name="contactBilling">
|
<input type="text" class="form-control mb-2" placeholder="{{ __('Billing Contact') }}" name="contactBilling">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Fields for nameservers -->
|
<!-- Fields for nameservers -->
|
||||||
<div id="nameserverFields">
|
<div id="nameserverFields">
|
||||||
<label class="form-label">Nameservers</label>
|
<label class="form-label">{{ __('Nameservers') }}</label>
|
||||||
|
|
||||||
<div class="nameserver-group mb-1 row">
|
<div class="nameserver-group mb-1 row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<input type="text" class="form-control mb-1" placeholder="Nameserver 1" name="nameserver[]" required>
|
<input type="text" class="form-control mb-1" placeholder="{{ __('Nameserver') }} 1" name="nameserver[]" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<input type="text" class="form-control mb-1" placeholder="Nameserver 1 - IPv4" name="nameserver_ipv4[]">
|
<input type="text" class="form-control mb-1" placeholder="{{ __('Nameserver') }} 1 - IPv4" name="nameserver_ipv4[]">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<input type="text" class="form-control mb-1" placeholder="Nameserver 1 - IPv6" name="nameserver_ipv6[]">
|
<input type="text" class="form-control mb-1" placeholder="{{ __('Nameserver') }} 1 - IPv6" name="nameserver_ipv6[]">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nameserver-group mb-1 row">
|
<div class="nameserver-group mb-1 row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<input type="text" class="form-control mb-1" placeholder="Nameserver 2" name="nameserver[]" required>
|
<input type="text" class="form-control mb-1" placeholder="{{ __('Nameserver') }} 2" name="nameserver[]" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<input type="text" class="form-control mb-1" placeholder="Nameserver 2 - IPv4" name="nameserver_ipv4[]">
|
<input type="text" class="form-control mb-1" placeholder="{{ __('Nameserver') }} 2 - IPv4" name="nameserver_ipv4[]">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<input type="text" class="form-control mb-1" placeholder="Nameserver 2 - IPv6" name="nameserver_ipv6[]">
|
<input type="text" class="form-control mb-1" placeholder="{{ __('Nameserver') }} 2 - IPv6" name="nameserver_ipv6[]">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -124,52 +124,52 @@
|
||||||
<!-- DNSSEC Data with checkbox -->
|
<!-- DNSSEC Data with checkbox -->
|
||||||
<div class="mb-3 form-check">
|
<div class="mb-3 form-check">
|
||||||
<input type="checkbox" class="form-check-input" id="addDnssec" name="addDnssec">
|
<input type="checkbox" class="form-check-input" id="addDnssec" name="addDnssec">
|
||||||
<label class="form-check-label" for="addDnssec">Add DNSSEC Data</label>
|
<label class="form-check-label" for="addDnssec">{{ __('Add DNSSEC Data') }}</label>
|
||||||
</div>
|
</div>
|
||||||
<div id="dnssecData" style="display: none;">
|
<div id="dnssecData" style="display: none;">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="dsKeyTag" class="form-label">DS Record</label>
|
<label for="dsKeyTag" class="form-label">{{ __('DS Record') }}</label>
|
||||||
<input type="text" class="form-control mb-2" placeholder="Key Tag" name="dsKeyTag" id="dsKeyTag">
|
<input type="text" class="form-control mb-2" placeholder="{{ __('Key Tag') }}" name="dsKeyTag" id="dsKeyTag">
|
||||||
<select class="form-control mb-2" name="dsAlg">
|
<select class="form-control mb-2" name="dsAlg">
|
||||||
<option value="" disabled selected>Select Algorithm</option>
|
<option value="" disabled selected>{{ __('Select Algorithm') }}</option>
|
||||||
<option value="1">RSA/MD5 (deprecated)</option>
|
<option value="1">RSA/MD5 (deprecated)</option>
|
||||||
<option value="3">DSA/SHA1</option>
|
<option value="3">DSA/SHA1</option>
|
||||||
<option value="5">RSA/SHA-1</option>
|
<option value="5">RSA/SHA-1</option>
|
||||||
<!-- Add other algorithms as required -->
|
<!-- Add other algorithms as required -->
|
||||||
</select>
|
</select>
|
||||||
<select class="form-control mb-2" name="dsDigestType">
|
<select class="form-control mb-2" name="dsDigestType">
|
||||||
<option value="" disabled selected>Select Digest Type</option>
|
<option value="" disabled selected>{{ __('Select Digest Type') }}</option>
|
||||||
<option value="1">SHA-1</option>
|
<option value="1">SHA-1</option>
|
||||||
<option value="2">SHA-256</option>
|
<option value="2">SHA-256</option>
|
||||||
<!-- Add other digest types as required -->
|
<!-- Add other digest types as required -->
|
||||||
</select>
|
</select>
|
||||||
<input type="text" class="form-control mb-2" placeholder="Digest" name="dsDigest">
|
<input type="text" class="form-control mb-2" placeholder="{{ __('Digest') }}" name="dsDigest">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="dnskeyFlags" class="form-label">DNSKEY Record</label>
|
<label for="dnskeyFlags" class="form-label">{{ __('DNSKEY Record') }}</label>
|
||||||
<input type="number" class="form-control mb-2" placeholder="Flags" name="dnskeyFlags" id="dnskeyFlags">
|
<input type="number" class="form-control mb-2" placeholder="{{ __('Flags') }}" name="dnskeyFlags" id="dnskeyFlags">
|
||||||
<input type="number" class="form-control mb-2" placeholder="Protocol" name="dnskeyProtocol" value="3" readonly> <!-- Protocol is typically set to 3 -->
|
<input type="number" class="form-control mb-2" placeholder="{{ __('Protocol') }}" name="dnskeyProtocol" value="3" readonly> <!-- Protocol is typically set to 3 -->
|
||||||
<select class="form-control mb-2" name="dnskeyAlg">
|
<select class="form-control mb-2" name="dnskeyAlg">
|
||||||
<option value="" disabled selected>Select Algorithm</option>
|
<option value="" disabled selected>{{ __('Select Algorithm') }}</option>
|
||||||
<option value="1">RSA/MD5 (deprecated)</option>
|
<option value="1">RSA/MD5 (deprecated)</option>
|
||||||
<option value="3">DSA/SHA1</option>
|
<option value="3">DSA/SHA1</option>
|
||||||
<option value="5">RSA/SHA-1</option>
|
<option value="5">RSA/SHA-1</option>
|
||||||
<!-- Add other algorithms as required -->
|
<!-- Add other algorithms as required -->
|
||||||
</select>
|
</select>
|
||||||
<input type="text" class="form-control mb-2" placeholder="Public Key" name="dnskeyPubKey">
|
<input type="text" class="form-control mb-2" placeholder="{{ __('Public Key') }}" name="dnskeyPubKey">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- AuthInfo -->
|
<!-- AuthInfo -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="authInfo" class="form-label">Auth Info</label>
|
<label for="authInfo" class="form-label">{{ __('Auth Info') }}</label>
|
||||||
<input type="text" class="form-control" id="authInfo" name="authInfo" readonly>
|
<input type="text" class="form-control" id="authInfo" name="authInfo" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<div class="row align-items-center">
|
<div class="row align-items-center">
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<button type="submit" class="btn btn-primary">Create Domain</button>
|
<button type="submit" class="btn btn-primary">{{ __('Create Domain') }}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -194,6 +194,10 @@
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
|
||||||
|
window.currencySymbol = "{{ currencySymbol }}";
|
||||||
|
window.currencyPosition = "{{ currencyPosition }}";
|
||||||
|
|
||||||
const yearSlider = document.getElementById('registrationYears');
|
const yearSlider = document.getElementById('registrationYears');
|
||||||
const yearValueDisplay = document.getElementById('yearValue');
|
const yearValueDisplay = document.getElementById('yearValue');
|
||||||
const addNameserverBtn = document.getElementById('addNameserver');
|
const addNameserverBtn = document.getElementById('addNameserver');
|
||||||
|
@ -215,7 +219,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
const nameserverField = document.createElement('input');
|
const nameserverField = document.createElement('input');
|
||||||
nameserverField.type = 'text';
|
nameserverField.type = 'text';
|
||||||
nameserverField.className = 'form-control mb-1';
|
nameserverField.className = 'form-control mb-1';
|
||||||
nameserverField.placeholder = `Nameserver ${count}`;
|
nameserverField.placeholder = `{{ __('Nameserver') }} ${count}`;
|
||||||
nameserverField.name = `nameserver[]`;
|
nameserverField.name = `nameserver[]`;
|
||||||
nameserverCol.appendChild(nameserverField);
|
nameserverCol.appendChild(nameserverField);
|
||||||
|
|
||||||
|
@ -224,7 +228,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
const ipv4Field = document.createElement('input');
|
const ipv4Field = document.createElement('input');
|
||||||
ipv4Field.type = 'text';
|
ipv4Field.type = 'text';
|
||||||
ipv4Field.className = 'form-control mb-1';
|
ipv4Field.className = 'form-control mb-1';
|
||||||
ipv4Field.placeholder = `Nameserver ${count} - IPv4`;
|
ipv4Field.placeholder = `{{ __('Nameserver') }} ${count} - IPv4`;
|
||||||
ipv4Field.name = `nameserver_ipv4[]`;
|
ipv4Field.name = `nameserver_ipv4[]`;
|
||||||
ipv4Col.appendChild(ipv4Field);
|
ipv4Col.appendChild(ipv4Field);
|
||||||
|
|
||||||
|
@ -233,7 +237,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
const ipv6Field = document.createElement('input');
|
const ipv6Field = document.createElement('input');
|
||||||
ipv6Field.type = 'text';
|
ipv6Field.type = 'text';
|
||||||
ipv6Field.className = 'form-control mb-1';
|
ipv6Field.className = 'form-control mb-1';
|
||||||
ipv6Field.placeholder = `Nameserver ${count} - IPv6`;
|
ipv6Field.placeholder = `{{ __('Nameserver') }} ${count} - IPv6`;
|
||||||
ipv6Field.name = `nameserver_ipv6[]`;
|
ipv6Field.name = `nameserver_ipv6[]`;
|
||||||
ipv6Col.appendChild(ipv6Field);
|
ipv6Col.appendChild(ipv6Field);
|
||||||
|
|
||||||
|
@ -291,20 +295,58 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
const priceDisplay = document.getElementById('domainPriceDisplay');
|
const priceDisplay = document.getElementById('domainPriceDisplay');
|
||||||
const priceValue = document.getElementById('domainPrice');
|
const priceValue = document.getElementById('domainPrice');
|
||||||
|
|
||||||
// Simulate an API request
|
function extractTLD(domain) {
|
||||||
|
const match = domain.match(/\.[a-zA-Z0-9]+$/);
|
||||||
|
return match ? match[0].toLowerCase() : null;
|
||||||
|
}
|
||||||
|
|
||||||
function getDomainPrice(domain, years) {
|
function getDomainPrice(domain, years) {
|
||||||
// For now, we'll just return a dummy price. In a real scenario, you'd call your API here.
|
const tld = extractTLD(domain);
|
||||||
return new Promise(resolve => {
|
if (!tld) {
|
||||||
setTimeout(() => {
|
return Promise.reject("Invalid TLD");
|
||||||
resolve(10.00 * years); // Example: Price is $10/year
|
}
|
||||||
}, 500); // Simulating API delay
|
|
||||||
|
// Call your API to get the domain price based on its TLD.
|
||||||
|
return fetch(`/api/records/domain_price?join=domain_tld`)
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.json();
|
||||||
|
} else {
|
||||||
|
return Promise.reject("Failed to fetch domain prices");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
// Find the domain TLD and then get its price for the "create" command
|
||||||
|
const tldData = data.records.find(record =>
|
||||||
|
record.tldid && record.tldid.tld.toLowerCase() === tld.toLowerCase() &&
|
||||||
|
record.command === 'create'
|
||||||
|
);
|
||||||
|
if (tldData) {
|
||||||
|
const priceField = `m${years * 12}`;
|
||||||
|
const price = parseFloat(tldData[priceField]);
|
||||||
|
if (!isNaN(price)) {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject("TLD price not found");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatPrice(price) {
|
||||||
|
switch(window.currencyPosition) {
|
||||||
|
case 'before':
|
||||||
|
return `${window.currencySymbol}${price.toFixed(2)}`;
|
||||||
|
case 'after':
|
||||||
|
return `${price.toFixed(2)} ${window.currencySymbol}`;
|
||||||
|
default:
|
||||||
|
return price.toFixed(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updatePrice() {
|
function updatePrice() {
|
||||||
if (domainInput.value) {
|
if (domainInput.value) {
|
||||||
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
||||||
priceValue.innerText = `$${price.toFixed(2)}`;
|
priceValue.innerText = formatPrice(price);
|
||||||
priceDisplay.style.display = 'block';
|
priceDisplay.style.display = 'block';
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue