mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-29 08:50:03 +02:00
Added deposit page
This commit is contained in:
parent
fa5600bddd
commit
0439463a30
3 changed files with 115 additions and 34 deletions
|
@ -25,6 +25,80 @@ class FinancialsController extends Controller
|
||||||
|
|
||||||
public function deposit(Request $request, Response $response)
|
public function deposit(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
|
if ($_SESSION["auth_roles"] != 0) {
|
||||||
|
return $response->withHeader('Location', '/dashboard')->withStatus(302);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->getMethod() === 'POST') {
|
||||||
|
// Retrieve POST data
|
||||||
|
$data = $request->getParsedBody();
|
||||||
|
$db = $this->container->get('db');
|
||||||
|
$registrar_id = $data['registrar'];
|
||||||
|
$registrars = $db->select("SELECT id, clid, name FROM registrar");
|
||||||
|
$amount = $data['amount'];
|
||||||
|
$description = empty($data['description']) ? "Funds Added to Account Balance" : $data['description'];
|
||||||
|
|
||||||
|
$isPositiveNumberWithTwoDecimals = filter_var($amount, FILTER_VALIDATE_FLOAT) !== false && preg_match('/^\d+(\.\d{1,2})?$/', $amount);
|
||||||
|
|
||||||
|
if ($isPositiveNumberWithTwoDecimals) {
|
||||||
|
$db->beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$currentDateTime = new \DateTime();
|
||||||
|
$date = $currentDateTime->format('Y-m-d H:i:s.v');
|
||||||
|
$db->insert(
|
||||||
|
'statement',
|
||||||
|
[
|
||||||
|
'registrar_id' => $registrar_id,
|
||||||
|
'date' => $date,
|
||||||
|
'command' => 'create',
|
||||||
|
'domain_name' => 'deposit',
|
||||||
|
'length_in_months' => 0,
|
||||||
|
'from' => $date,
|
||||||
|
'to' => $date,
|
||||||
|
'amount' => $amount
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$db->insert(
|
||||||
|
'payment_history',
|
||||||
|
[
|
||||||
|
'registrar_id' => $registrar_id,
|
||||||
|
'date' => $date,
|
||||||
|
'description' => $description,
|
||||||
|
'amount' => $amount
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$db->exec(
|
||||||
|
'UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?',
|
||||||
|
[
|
||||||
|
$amount,
|
||||||
|
$registrar_id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$db->rollBack();
|
||||||
|
return view($response, 'admin/financials/deposit.twig', [
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
'registrars' => $registrars
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view($response, 'admin/financials/deposit.twig', [
|
||||||
|
'deposit' => $amount,
|
||||||
|
'registrars' => $registrars
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return view($response, 'admin/financials/deposit.twig', [
|
||||||
|
'error' => 'Invalid entry: Deposit amount must be positive. Please enter a valid amount.',
|
||||||
|
'registrars' => $registrars
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$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");
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<!-- Page pre-title -->
|
<!-- Page pre-title -->
|
||||||
<div class="page-pretitle">
|
<div class="page-pretitle">
|
||||||
Overview
|
{{ __('Overview') }}
|
||||||
</div>
|
</div>
|
||||||
<h2 class="page-title">
|
<h2 class="page-title">
|
||||||
{{ __('Registrar Deposit') }}
|
{{ __('Registrar Deposit') }}
|
||||||
|
@ -24,9 +24,35 @@
|
||||||
<div class="page-body">
|
<div class="page-body">
|
||||||
<div class="container-xl">
|
<div class="container-xl">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
|
{% if deposit is defined %}
|
||||||
|
<div class="alert alert-important alert-success alert-dismissible" role="alert">
|
||||||
|
<div class="d-flex">
|
||||||
|
<div>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l5 5l10 -10" /></svg>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{{ __('Deposit successfully added. The registrar\'s account balance has been updated.') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
|
||||||
|
</div>
|
||||||
|
{% elseif error is defined %}
|
||||||
|
<div class="alert alert-important alert-danger alert-dismissible" role="alert">
|
||||||
|
<div class="d-flex">
|
||||||
|
<div>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" /><path d="M12 8v4" /><path d="M12 16h.01" /></svg>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{{ __('Unable to process the deposit due to a system error. Please retry or contact support for help') }}: <strong>{{ error }}</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form id="depositForm">
|
<form id="depositForm" action="/deposit" method="post">
|
||||||
|
{{ csrf.field | raw }}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="registrarSelect" class="form-label">Registrar</label>
|
<label for="registrarSelect" class="form-label">Registrar</label>
|
||||||
<select class="form-select" id="registrarSelect" name="registrar" required>
|
<select class="form-select" id="registrarSelect" name="registrar" required>
|
||||||
|
@ -38,18 +64,18 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="deposit-info">
|
<div class="deposit-info">
|
||||||
<h5>Current Funds for <span id="registrarName"></span></h5>
|
<h5>Current Balance for <span id="registrarName"></span></h5>
|
||||||
<p class="fs-4">$<span id="currentFunds">0.00</span></p>
|
<p class="fs-4">$<span id="currentFunds">0.00</span></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="amount" class="form-label">Amount</label>
|
<label for="amount" class="form-label">Amount</label>
|
||||||
<input type="number" step="0.01" class="form-control" id="amount" placeholder="Enter deposit amount" required>
|
<input type="number" step="0.01" class="form-control" id="amount" name="amount" placeholder="Enter deposit amount" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="description" class="form-label">Description</label>
|
<label for="description" class="form-label">Description</label>
|
||||||
<textarea class="form-control" id="description" rows="3" placeholder="Optional deposit description"></textarea>
|
<textarea class="form-control" id="description" name="description" rows="3" placeholder="Optional deposit description"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
|
@ -64,42 +90,23 @@
|
||||||
<script>
|
<script>
|
||||||
const registrarSelect = document.getElementById('registrarSelect');
|
const registrarSelect = document.getElementById('registrarSelect');
|
||||||
registrarSelect.addEventListener('change', function() {
|
registrarSelect.addEventListener('change', function() {
|
||||||
// Mock API call to get current funds for the selected registrar
|
const selectedRegistrarId = registrarSelect.value;
|
||||||
fetch(`https://api.example.com/registrarFunds/${registrarSelect.value}`)
|
|
||||||
|
// Real API call to get registrars
|
||||||
|
fetch(`/api/records/registrar`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const registrarName = registrarSelect.options[registrarSelect.selectedIndex].text;
|
const registrarData = data.records.find(registrar => registrar.id == selectedRegistrarId);
|
||||||
document.getElementById('registrarName').textContent = registrarName;
|
const accountBalance = registrarData ? registrarData.accountBalance : '0.00';
|
||||||
document.getElementById('currentFunds').textContent = data.funds.toFixed(2);
|
|
||||||
|
document.getElementById('registrarName').textContent = registrarData ? registrarData.name : 'N/A';
|
||||||
|
document.getElementById('currentFunds').textContent = parseFloat(accountBalance).toFixed(2);
|
||||||
document.querySelector('.deposit-info').style.display = 'block';
|
document.querySelector('.deposit-info').style.display = 'block';
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('There was an error with the request:', error);
|
console.error('There was an error with the request:', error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('depositForm').addEventListener('submit', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
const amount = document.getElementById('amount').value;
|
|
||||||
|
|
||||||
// Mock API call to add deposit
|
|
||||||
fetch("https://api.example.com/addDeposit", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ registrarId: registrarSelect.value, amount: amount })
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
// Update the displayed funds after deposit
|
|
||||||
document.getElementById('currentFunds').textContent = data.newFunds.toFixed(2);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('There was an error with the request:', error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -64,7 +64,7 @@ $app->group('', function ($route) {
|
||||||
$route->get('/reports', ReportsController::class .':view')->setName('reports');
|
$route->get('/reports', ReportsController::class .':view')->setName('reports');
|
||||||
|
|
||||||
$route->get('/pricing', FinancialsController::class .':pricing')->setName('pricing');
|
$route->get('/pricing', FinancialsController::class .':pricing')->setName('pricing');
|
||||||
$route->get('/deposit', FinancialsController::class .':deposit')->setName('deposit');
|
$route->map(['GET', 'POST'], '/deposit', FinancialsController::class .':deposit')->setName('deposit');
|
||||||
$route->get('/transactions', FinancialsController::class .':transactions')->setName('transactions');
|
$route->get('/transactions', FinancialsController::class .':transactions')->setName('transactions');
|
||||||
$route->get('/overview', FinancialsController::class .':overview')->setName('overview');
|
$route->get('/overview', FinancialsController::class .':overview')->setName('overview');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue