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

View file

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