Added ability to have custom currency per registrar

This commit is contained in:
Pinga 2025-02-06 12:08:40 +02:00
parent 843451406e
commit 98dd2950e0
3 changed files with 72 additions and 20 deletions

View file

@ -62,6 +62,7 @@ class RegistrarsController extends Controller
$validators = [
'name' => v::stringType()->notEmpty()->length(1, 255),
'currency' => v::stringType()->notEmpty()->length(1, 5),
'ianaId' => v::optional(v::positive()->length(1, 5)),
'email' => v::email(),
'owner' => v::optional(v::keySet(...$contactValidator)),
@ -124,7 +125,6 @@ class RegistrarsController extends Controller
for ($i = 0; $i < 2; $i++) {
$randomPrefix .= $characters[rand(0, strlen($characters) - 1)];
}
$currency = $_SESSION['_currency'] ?? 'USD';
$eppPassword = password_hash($data['eppPassword'], PASSWORD_ARGON2ID, ['memory_cost' => 1024 * 128, 'time_cost' => 6, 'threads' => 4]);
if (empty($data['ianaId']) || !is_numeric($data['ianaId'])) {
@ -156,7 +156,7 @@ class RegistrarsController extends Controller
'thresholdType' => $data['thresholdType'],
'companyNumber' => $data['companyNumber'],
'vatNumber' => $data['vatNumber'],
'currency' => $currency,
'currency' => $data['currency'],
'crdate' => $crdate,
'lastupdate' => $crdate
]
@ -298,9 +298,20 @@ class RegistrarsController extends Controller
$iso3166 = new ISO3166();
$countries = $iso3166->all();
$uniqueCurrencies = [];
foreach ($countries as $country) {
// Assuming each country has a 'currency' field with an array of currencies
foreach ($country['currency'] as $currencyCode) {
if (!array_key_exists($currencyCode, $uniqueCurrencies)) {
$uniqueCurrencies[$currencyCode] = $currencyCode; // Or any other currency detail you have
}
}
}
// Default view for GET requests or if POST data is not set
return view($response,'admin/registrars/create.twig', [
'countries' => $countries,
'uniqueCurrencies' => $uniqueCurrencies,
]);
}
@ -513,6 +524,16 @@ class RegistrarsController extends Controller
$_SESSION['registrars_to_update'] = [$registrar['clid']];
$_SESSION['registrars_user_email'] = [$user['email']];
$uniqueCurrencies = [];
foreach ($countries as $country) {
// Assuming each country has a 'currency' field with an array of currencies
foreach ($country['currency'] as $currencyCode) {
if (!array_key_exists($currencyCode, $uniqueCurrencies)) {
$uniqueCurrencies[$currencyCode] = $currencyCode; // Or any other currency detail you have
}
}
}
return view($response,'admin/registrars/updateRegistrar.twig', [
'registrar' => $registrar,
@ -522,7 +543,8 @@ class RegistrarsController extends Controller
'user' => $user,
'whitelist' => $whitelist,
'currentUri' => $uri,
'countries' => $countries
'countries' => $countries,
'uniqueCurrencies' => $uniqueCurrencies,
]);
} else {
// Registrar does not exist, redirect to the registrars view
@ -584,6 +606,7 @@ class RegistrarsController extends Controller
$validators = [
'name' => v::stringType()->notEmpty()->length(1, 255),
'currency' => v::stringType()->notEmpty()->length(1, 5),
'ianaId' => v::optional(v::positive()->length(1, 5)),
'email' => v::email(),
'owner' => v::optional(v::keySet(...$contactValidator)),
@ -640,7 +663,6 @@ class RegistrarsController extends Controller
try {
$currentDateTime = new \DateTime();
$update = $currentDateTime->format('Y-m-d H:i:s.v');
$currency = $_SESSION['_currency'] ?? 'USD';
if (empty($data['ianaId']) || !is_numeric($data['ianaId'])) {
$data['ianaId'] = null;
@ -659,7 +681,7 @@ class RegistrarsController extends Controller
'abuse_phone' => $data['abusePhone'],
'creditLimit' => $data['creditLimit'],
'creditThreshold' => $data['creditThreshold'],
'currency' => $currency,
'currency' => $data['currency'],
'lastupdate' => $update
];

View file

@ -95,19 +95,34 @@
<input type="number" step="0.01" class="form-control" id="accountBalance" name="accountBalance" value="0" required>
<small class="text-muted">{{ __('Current balance in the registrar\'s account.') }}</small>
</div>
<div class="mb-3">
<label for="creditLimit" class="form-label required">{{ __('Credit Limit') }}</label>
<input type="number" step="0.01" class="form-control" id="creditLimit" name="creditLimit" value="0" required>
<small class="text-muted">{{ __('Maximum credit limit for the registrar.') }}</small>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="creditLimit" class="form-label required">{{ __('Credit Limit') }}</label>
<input type="number" step="0.01" class="form-control" id="creditLimit" name="creditLimit" value="0" required>
<small class="text-muted">{{ __('Maximum credit limit for the registrar.') }}</small>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="creditThreshold" class="form-label required">{{ __('Credit Threshold') }}</label>
<input type="number" step="0.01" class="form-control" id="creditThreshold" name="creditThreshold" required>
<small class="text-muted">{{ __('Credit threshold triggering alerts or actions.') }}</small>
</div>
</div>
</div>
</div>
<!-- Second Column -->
<div class="col-md-4">
<div class="mb-3">
<label for="creditThreshold" class="form-label required">{{ __('Credit Threshold') }}</label>
<input type="number" step="0.01" class="form-control" id="creditThreshold" name="creditThreshold" required>
<small class="text-muted">{{ __('Credit threshold triggering alerts or actions.') }}</small>
<label for="registryCurrency" class="form-label required">{{ __('Currency') }}</label>
<select class="form-select" id="registryCurrency" name="currency" required="required">
{% for currencyCode, currencyName in uniqueCurrencies %}
<option value="{{ currencyCode }}" {% if currency == currencyCode %}selected{% endif %}>{{ currencyName }}</option>
{% endfor %}
</select>
<small class="text-muted">{{ __('Choose the currency for all registrar transactions.') }}</small>
</div>
<div class="mb-3">
<label for="thresholdType" class="form-label required">{{ __('Threshold Type') }}</label>

View file

@ -95,19 +95,34 @@
<div class="form-control-plaintext">{{ currency }} {{ registrar.accountBalance }}</div>
<small class="text-muted">{{ __('Current balance in the registrar\'s account.') }}</small>
</div>
<div class="mb-3">
<label for="creditLimit" class="form-label required">{{ __('Credit Limit') }}</label>
<input type="number" step="0.01" class="form-control" id="creditLimit" name="creditLimit" required value="{{ registrar.creditLimit }}">
<small class="text-muted">{{ __('Maximum credit limit for the registrar.') }}</small>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="creditLimit" class="form-label required">{{ __('Credit Limit') }}</label>
<input type="number" step="0.01" class="form-control" id="creditLimit" name="creditLimit" required value="{{ registrar.creditLimit }}">
<small class="text-muted">{{ __('Maximum credit limit for the registrar.') }}</small>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="creditThreshold" class="form-label required">{{ __('Credit Threshold') }}</label>
<input type="number" step="0.01" class="form-control" id="creditThreshold" name="creditThreshold" required value="{{ registrar.creditThreshold }}">
<small class="text-muted">{{ __('Credit threshold triggering alerts or actions.') }}</small>
</div>
</div>
</div>
</div>
<!-- Second Column -->
<div class="col-md-4">
<div class="mb-3">
<label for="creditThreshold" class="form-label required">{{ __('Credit Threshold') }}</label>
<input type="number" step="0.01" class="form-control" id="creditThreshold" name="creditThreshold" required value="{{ registrar.creditThreshold }}">
<small class="text-muted">{{ __('Credit threshold triggering alerts or actions.') }}</small>
<label for="registryCurrency" class="form-label required">{{ __('Currency') }}</label>
<select class="form-select" id="registryCurrency" name="currency" required="required">
{% for currencyCode, currencyName in uniqueCurrencies %}
<option value="{{ currencyCode }}" {% if registrar.currency == currencyCode %}selected{% endif %}>{{ currencyName }}</option>
{% endfor %}
</select>
<small class="text-muted">{{ __('Choose the currency for all registrar transactions.') }}</small>
</div>
<div class="mb-3">
<label for="thresholdType" class="form-label">{{ __('Threshold Type') }}</label>
@ -120,7 +135,7 @@
<div class="col-md-4">
<div class="mb-3">
<label for="companyNumber" class="form-label">{{ __('Company Number') }}</label>
<div class="form-control-plaintext">{{ registrar.companyNumber }}</div>
<div class="form-control-plaintext">{{ registrar.companyNumber|default('N/A') }}</div>
<small class="text-muted">{{ __('Official registration number provided by the relevant authority.') }}</small>
</div>
<div class="mb-3">