feat: ✨ Added Server Cancelation route method and charging
This commit is contained in:
parent
32384044ea
commit
78a6787607
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,24 @@ class ServerController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* @param Server $server
|
||||||
* @return RedirectResponse
|
* @return RedirectResponse
|
||||||
|
|
|
@ -210,7 +210,21 @@ class ServerController extends Controller
|
||||||
$server->delete();
|
$server->delete();
|
||||||
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() . '"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,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() }}'
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,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);
|
||||||
Route::resource('profile', ProfileController::class);
|
Route::resource('profile', ProfileController::class);
|
||||||
Route::resource('store', StoreController::class);
|
Route::resource('store', StoreController::class);
|
||||||
|
@ -112,6 +113,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::resource('servers', AdminServerController::class);
|
Route::resource('servers', AdminServerController::class);
|
||||||
|
|
||||||
#products
|
#products
|
||||||
|
|
Loading…
Reference in a new issue