feat: ✨ Added Server Cancelation route method and charging
This commit is contained in:
parent
f8c33d43be
commit
7fa9bf2062
|
@ -81,14 +81,14 @@ class ChargeServers extends Command
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if user has enough credits to charge the server
|
// check if the server is canceled or if user has enough credits to charge the server or
|
||||||
if ($user->credits < $product->price) {
|
if ( $server->cancelled || $user->credits < $product->price) {
|
||||||
try {
|
try {
|
||||||
#suspend server
|
// suspend server
|
||||||
$this->line("<fg=yellow>{$server->name}</> from user: <fg=blue>{$user->name}</> has been <fg=red>suspended!</>");
|
$this->line("<fg=yellow>{$server->name}</> from user: <fg=blue>{$user->name}</> has been <fg=red>suspended!</>");
|
||||||
$server->suspend();
|
$server->suspend();
|
||||||
|
|
||||||
#add user to notify list
|
// add user to notify list
|
||||||
if (!in_array($user, $this->usersToNotify)) {
|
if (!in_array($user, $this->usersToNotify)) {
|
||||||
array_push($this->usersToNotify, $user);
|
array_push($this->usersToNotify, $user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,25 @@ class ServerController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* Cancel the Server billing cycle.
|
||||||
|
*
|
||||||
|
* @param Server $server
|
||||||
|
* @return RedirectResponse|Response
|
||||||
|
*/
|
||||||
|
public function cancel (Server $server)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
error_log($server->update([
|
||||||
|
'cancelled' => now(),
|
||||||
|
]));
|
||||||
|
return redirect()->route('servers.index')->with('success', __('Server cancelled'));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to cancel the server"') . $e->getMessage() . '"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Server $server
|
||||||
* @return RedirectResponse
|
* @return RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function toggleSuspended(Server $server)
|
public function toggleSuspended(Server $server)
|
||||||
|
|
|
@ -246,7 +246,21 @@ class ServerController extends Controller
|
||||||
|
|
||||||
return redirect()->route('servers.index')->with('success', __('Server removed'));
|
return redirect()->route('servers.index')->with('success', __('Server removed'));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to remove a resource "').$e->getMessage().'"');
|
return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to delete the server"') . $e->getMessage() . '"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Cancel Server */
|
||||||
|
public function cancel (Server $server)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
error_log($server->update([
|
||||||
|
'cancelled' => now(),
|
||||||
|
]));
|
||||||
|
|
||||||
|
return redirect()->route('servers.index')->with('success', __('Server cancelled'));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return redirect()->route('servers.index')->with('error', __('An exception has occurred while trying to cancel the server"') . $e->getMessage() . '"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,8 @@ class Server extends Model
|
||||||
"identifier",
|
"identifier",
|
||||||
"product_id",
|
"product_id",
|
||||||
"pterodactyl_id",
|
"pterodactyl_id",
|
||||||
"last_billed"
|
"last_billed",
|
||||||
|
"cancelled"
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -219,8 +219,8 @@
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
if (result.value) {
|
if (result.value) {
|
||||||
// Delete server
|
// Delete server
|
||||||
fetch("{{ route('servers.destroy', '') }}" + '/' + serverId, {
|
fetch("{{ route('servers.cancel', '') }}" + '/' + serverId, {
|
||||||
method: 'DELETE',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
|
||||||
//normal routes
|
//normal routes
|
||||||
Route::get('notifications/readAll', [NotificationController::class, 'readAll'])->name('notifications.readAll');
|
Route::get('notifications/readAll', [NotificationController::class, 'readAll'])->name('notifications.readAll');
|
||||||
Route::resource('notifications', NotificationController::class);
|
Route::resource('notifications', NotificationController::class);
|
||||||
|
Route::patch('/servers/cancel/{server}', [ServerController::class, 'cancel'])->name('servers.cancel');
|
||||||
Route::resource('servers', ServerController::class);
|
Route::resource('servers', ServerController::class);
|
||||||
if (config('SETTINGS::SYSTEM:ENABLE_UPGRADE')) {
|
if (config('SETTINGS::SYSTEM:ENABLE_UPGRADE')) {
|
||||||
Route::post('servers/{server}/upgrade', [ServerController::class, 'upgrade'])->name('servers.upgrade');
|
Route::post('servers/{server}/upgrade', [ServerController::class, 'upgrade'])->name('servers.upgrade');
|
||||||
|
@ -140,6 +141,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
|
||||||
//servers
|
//servers
|
||||||
Route::get('servers/datatable', [AdminServerController::class, 'datatable'])->name('servers.datatable');
|
Route::get('servers/datatable', [AdminServerController::class, 'datatable'])->name('servers.datatable');
|
||||||
Route::post('servers/togglesuspend/{server}', [AdminServerController::class, 'toggleSuspended'])->name('servers.togglesuspend');
|
Route::post('servers/togglesuspend/{server}', [AdminServerController::class, 'toggleSuspended'])->name('servers.togglesuspend');
|
||||||
|
Route::patch('/servers/cancel/{server}', [AdminServerController::class, 'cancel'])->name('servers.cancel');
|
||||||
Route::get('servers/sync', [AdminServerController::class, 'syncServers'])->name('servers.sync');
|
Route::get('servers/sync', [AdminServerController::class, 'syncServers'])->name('servers.sync');
|
||||||
Route::resource('servers', AdminServerController::class);
|
Route::resource('servers', AdminServerController::class);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue