Add the ability to sell server slots

This commit is contained in:
1Day 2022-05-30 09:23:35 +02:00
parent 0e426dca62
commit a7b199c01a
4 changed files with 56 additions and 34 deletions

View file

@ -164,9 +164,6 @@ class PaymentController extends Controller
$response = $this->getPayPalClient()->execute($request);
if ($response->statusCode == 201 || $response->statusCode == 200) {
//update credits
$user->increment('credits', $creditProduct->quantity);
//update server limit
if (config('SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE') !== 0) {
if ($user->server_limit < config('SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE')) {
@ -174,6 +171,14 @@ class PaymentController extends Controller
}
}
//update User with bought item
if ($creditProduct->type=="Credits") {
$user->increment('credits', $creditProduct->quantity);
}elseif ($creditProduct->type=="Server slots"){
$user->increment('server_limit', $creditProduct->quantity);
}
//update role
if ($user->role == 'member') {
$user->update(['role' => 'client']);
@ -184,7 +189,7 @@ class PaymentController extends Controller
'user_id' => $user->id,
'payment_id' => $response->result->id,
'payment_method' => 'paypal',
'type' => 'Credits',
'type' => $creditProduct->type,
'status' => 'paid',
'amount' => $creditProduct->quantity,
'price' => $creditProduct->price,
@ -305,8 +310,7 @@ class PaymentController extends Controller
// check if payment is 100% completed and payment does not exist in db already
if ($paymentSession->status == "complete" && $paymentIntent->status == "succeeded" && $paymentDbEntry == 0) {
//update credits
$user->increment('credits', $creditProduct->quantity);
//update server limit
if (config('SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE') !== 0) {
@ -315,6 +319,13 @@ class PaymentController extends Controller
}
}
//update User with bought item
if ($creditProduct->type=="Credits") {
$user->increment('credits', $creditProduct->quantity);
}elseif ($creditProduct->type=="Server slots"){
$user->increment('server_limit', $creditProduct->quantity);
}
//update role
if ($user->role == 'member') {
$user->update(['role' => 'client']);
@ -325,7 +336,7 @@ class PaymentController extends Controller
'user_id' => $user->id,
'payment_id' => $paymentSession->payment_intent,
'payment_method' => 'stripe',
'type' => 'Credits',
'type' => $creditProduct->type,
'status' => 'paid',
'amount' => $creditProduct->quantity,
'price' => $creditProduct->price,
@ -356,7 +367,7 @@ class PaymentController extends Controller
'user_id' => $user->id,
'payment_id' => $paymentSession->payment_intent,
'payment_method' => 'stripe',
'type' => 'Credits',
'type' => $creditProduct->type,
'status' => 'processing',
'amount' => $creditProduct->quantity,
'price' => $creditProduct->price,
@ -405,8 +416,7 @@ class PaymentController extends Controller
$user = User::where('id', $payment->user_id)->first();
if ($paymentIntent->status == 'succeeded' && $payment->status == 'processing') {
// Increment User Credits
$user->increment('credits', $payment->amount);
//update server limit
if (config('SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE') !== 0) {
@ -414,6 +424,12 @@ class PaymentController extends Controller
$user->update(['server_limit' => config('SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE')]);
}
}
//update User with bought item
if ($creditProduct->type=="Credits") {
$user->increment('credits', $creditProduct->quantity);
}elseif ($creditProduct->type=="Server slots"){
$user->increment('server_limit', $creditProduct->quantity);
}
//update role
if ($user->role == 'member') {

View file

@ -30,7 +30,7 @@ class StoreController extends Controller
}
return view('store.index')->with([
'products' => CreditProduct::where('disabled', '=', false)->orderBy('price', 'asc')->get(),
'products' => CreditProduct::where('disabled', '=', false)->orderBy('type', 'asc')->orderBy('price', 'asc')->get(),
'isPaymentSetup' => $isPaymentSetup,
]);
}

View file

@ -50,6 +50,7 @@
<select required name="type" id="type"
class="custom-select @error('name') is-invalid @enderror">
<option selected value="Credits">{{CREDITS_DISPLAY_NAME}}</option>
<option value="Server slots">{{__("Server Slots")}}</option>
</select>
@error('name')
<div class="text-danger">

View file

@ -12,9 +12,9 @@
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a class=""
href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a class="text-muted"
href="{{ route('store.index') }}">{{ __('Store') }}</a></li>
href="{{ route('store.index') }}">{{ __('Store') }}</a></li>
</ol>
</div>
</div>
@ -41,27 +41,34 @@
<div class="card-body">
<table class="table table-striped table-responsive-sm">
<thead>
<tr>
<th>{{ __('Price') }}</th>
<th>{{ __('Type') }}</th>
<th>{{ __('Description') }}</th>
<th></th>
</tr>
<tr>
<th>{{ __('Price') }}</th>
<th>{{ __('Type') }}</th>
<th>{{ __('Description') }}</th>
<th></th>
</tr>
</thead>
<tbody>
<?php /** @var $product CreditProduct */
?>
@foreach ($products as $product)
<tr>
<td>{{ $product->formatToCurrency($product->price) }}</td>
<td>{{ strtolower($product->type) == 'credits' ? CREDITS_DISPLAY_NAME : $product->type }}
</td>
<td><i class="fa fa-coins mr-2"></i>{{ $product->display }}</td>
<td><a href="{{ route('checkout', $product->id) }}"
class="btn btn-info">{{ __('Purchase') }}</a>
</td>
</tr>
@endforeach
<?php /** @var $product CreditProduct */
?>
@foreach ($products as $product)
<tr>
<td>{{ $product->formatToCurrency($product->price) }}</td>
<td>{{ strtolower($product->type) == 'credits' ? CREDITS_DISPLAY_NAME : $product->type }}
</td>
<td>
@if(strtolower($product->type) == 'credits')
<i class="fa fa-coins mr-2"></i>
@elseif (strtolower($product->type) == 'server slots')
<i class="fa fa-server mr-2"></i>
@endif
{{ $product->display }}</td>
<td><a href="{{ route('checkout', $product->id) }}"
class="btn btn-info">{{ __('Purchase') }}</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@ -87,7 +94,6 @@
const urlParams = new URLSearchParams(queryString);
return urlParams.get(param);
}
const voucherCode = getUrlParameter('voucher');
//if voucherCode not empty, open the modal and fill the input
if (voucherCode) {
@ -95,7 +101,6 @@
$('#redeemVoucherModal').modal('show');
$('#redeemVoucherCode').val(voucherCode);
});
}
</script>