Some love to payments
Fixed a bug with the new payment changes Improved the payments table and changes
This commit is contained in:
parent
2a42ac71b5
commit
b445cf7003
|
@ -6,11 +6,14 @@ use App\Http\Controllers\Controller;
|
||||||
use App\Models\Configuration;
|
use App\Models\Configuration;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaypalProduct;
|
use App\Models\PaypalProduct;
|
||||||
|
use App\Models\Product;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\ConfirmPaymentNotification;
|
use App\Notifications\ConfirmPaymentNotification;
|
||||||
|
use Exception;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
@ -154,7 +157,7 @@ class PaymentController extends Controller
|
||||||
'type' => 'Credits',
|
'type' => 'Credits',
|
||||||
'status' => $response->result->status,
|
'status' => $response->result->status,
|
||||||
'amount' => $paypalProduct->quantity,
|
'amount' => $paypalProduct->quantity,
|
||||||
'price' => $paypalProduct->formatCurrency(),
|
'price' => $paypalProduct->price,
|
||||||
'payer' => json_encode($response->result->payer),
|
'payer' => json_encode($response->result->payer),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -192,4 +195,26 @@ class PaymentController extends Controller
|
||||||
{
|
{
|
||||||
return redirect()->route('store.index')->with('success', 'Payment Canceled');
|
return redirect()->route('store.index')->with('success', 'Payment Canceled');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return JsonResponse|mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function dataTable()
|
||||||
|
{
|
||||||
|
$query = Payment::with('user');
|
||||||
|
|
||||||
|
return datatables($query)
|
||||||
|
->editColumn('user', function (Payment $payment) {
|
||||||
|
return $payment->user->name;
|
||||||
|
})
|
||||||
|
->editColumn('price', function (Payment $payment) {
|
||||||
|
return $payment->formatCurrency();
|
||||||
|
})
|
||||||
|
->editColumn('created_at', function (Payment $payment) {
|
||||||
|
return $payment->created_at ? $payment->created_at->diffForHumans() : '';
|
||||||
|
})
|
||||||
|
->make();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Hidehalo\Nanoid\Client;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use NumberFormatter;
|
||||||
use Spatie\Activitylog\Traits\LogsActivity;
|
use Spatie\Activitylog\Traits\LogsActivity;
|
||||||
|
|
||||||
class Payment extends Model
|
class Payment extends Model
|
||||||
|
@ -30,10 +31,11 @@ class Payment extends Model
|
||||||
'price',
|
'price',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function boot() {
|
public static function boot()
|
||||||
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
static::creating(function(Payment $payment) {
|
static::creating(function (Payment $payment) {
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
|
|
||||||
$payment->{$payment->getKeyName()} = $client->generateId($size = 8);
|
$payment->{$payment->getKeyName()} = $client->generateId($size = 8);
|
||||||
|
@ -43,12 +45,14 @@ class Payment extends Model
|
||||||
/**
|
/**
|
||||||
* @return BelongsTo
|
* @return BelongsTo
|
||||||
*/
|
*/
|
||||||
public function User(){
|
public function user()
|
||||||
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Price()
|
public function formatCurrency($locale = 'en_US')
|
||||||
{
|
{
|
||||||
return number_format($this->price, 2, '.', '');
|
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
||||||
|
return $formatter->formatCurrency($this->price, $this->currency_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,10 @@ class PaypalProduct extends Model
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $locale
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function formatCurrency($locale = 'en_US')
|
public function formatCurrency($locale = 'en_US')
|
||||||
{
|
{
|
||||||
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
||||||
|
|
|
@ -30,7 +30,8 @@ class PaymentFactory extends Factory
|
||||||
'type' => "Credits",
|
'type' => "Credits",
|
||||||
'status' => "Completed",
|
'status' => "Completed",
|
||||||
'amount' => $this->faker->numberBetween(10, 10000),
|
'amount' => $this->faker->numberBetween(10, 10000),
|
||||||
'price' => '€' . $this->faker->numerify('##.##'),
|
'price' => $this->faker->numerify('##.##'),
|
||||||
|
'currency_code' => ['EUR', 'USD'][rand(0,1)],
|
||||||
'payer' => '{}',
|
'payer' => '{}',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class UpdatePriceToPaymentsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('payments', function (Blueprint $table) {
|
||||||
|
$table->decimal('price')->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('payments', function (Blueprint $table) {
|
||||||
|
$table->string('price')->change()->nullable();;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddCurrencyCodeToPaymentsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('payments', function (Blueprint $table) {
|
||||||
|
$table->string('currency_code' , 3)->default('USD')->after('price');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('payments', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('currency_code');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,9 +28,9 @@
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="card-title"><i class="fas fa-money-bill-wave mr-2"></i>Payments</h5>
|
<h5 class="card-title"><i class="fas fa-money-bill-wave mr-2"></i>Payments</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body table-responsive">
|
|
||||||
|
|
||||||
<table class="table table-striped">
|
<div class="card-body table-responsive">
|
||||||
|
<table id="datatable" class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
|
@ -44,32 +44,39 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach($payments as $payment)
|
|
||||||
<tr>
|
|
||||||
<td>{{$payment->id}}</td>
|
|
||||||
<td>{{$payment->User->name}}</td>
|
|
||||||
<td>{{$payment->type}}</td>
|
|
||||||
<td><i class="fa fa-coins mr-2"></i>{{$payment->amount}}</td>
|
|
||||||
<td>€{{$payment->Price()}}</td>
|
|
||||||
<td>{{$payment->payment_id}}</td>
|
|
||||||
<td>{{$payment->payer_id}}</td>
|
|
||||||
<td>{{$payment->created_at->diffForHumans()}}</td>
|
|
||||||
</tr>
|
|
||||||
@endforeach
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="float-right">
|
|
||||||
{!! $payments->links() !!}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
<!-- END CUSTOM CONTENT -->
|
<!-- END CUSTOM CONTENT -->
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<!-- END CONTENT -->
|
<!-- END CONTENT -->
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
$('#datatable').DataTable({
|
||||||
|
processing: true,
|
||||||
|
serverSide: true,
|
||||||
|
stateSave: true,
|
||||||
|
ajax: "{{route('admin.payments.datatable')}}",
|
||||||
|
columns: [
|
||||||
|
{data: 'id' , name : 'payments.id'},
|
||||||
|
{data: 'user', sortable: false},
|
||||||
|
{data: 'type'},
|
||||||
|
{data: 'amount'},
|
||||||
|
{data: 'price'},
|
||||||
|
{data: 'payment_id'},
|
||||||
|
{data: 'payer_id'},
|
||||||
|
{data: 'created_at'},
|
||||||
|
],
|
||||||
|
fnDrawCallback: function( oSettings ) {
|
||||||
|
$('[data-toggle="popover"]').popover();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -6,7 +6,7 @@ Your payment has been confirmed; Your credit balance has been updated.
|
||||||
___
|
___
|
||||||
### Payment ID: **{{$payment->id}}**
|
### Payment ID: **{{$payment->id}}**
|
||||||
### Status: **{{$payment->status}}**
|
### Status: **{{$payment->status}}**
|
||||||
### Price: **{{$payment->price}}**
|
### Price: **{{$payment->formatCurrency()}}**
|
||||||
### Type: **{{$payment->type}}**
|
### Type: **{{$payment->type}}**
|
||||||
### Amount: **{{$payment->amount}}**
|
### Amount: **{{$payment->amount}}**
|
||||||
### Balance: **{{$payment->user->credits}}**
|
### Balance: **{{$payment->user->credits}}**
|
||||||
|
|
|
@ -88,6 +88,7 @@ Route::middleware('auth')->group(function () {
|
||||||
'store' => 'paypalProduct',
|
'store' => 'paypalProduct',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Route::get('payments/datatable', [PaymentController::class, 'datatable'])->name('payments.datatable');
|
||||||
Route::get('payments', [PaymentController::class, 'index'])->name('payments.index');
|
Route::get('payments', [PaymentController::class, 'index'])->name('payments.index');
|
||||||
|
|
||||||
Route::get('nodes/datatable', [NodeController::class, 'datatable'])->name('nodes.datatable');
|
Route::get('nodes/datatable', [NodeController::class, 'datatable'])->name('nodes.datatable');
|
||||||
|
@ -101,6 +102,7 @@ Route::middleware('auth')->group(function () {
|
||||||
Route::get('configurations/datatable', [ConfigurationController::class, 'datatable'])->name('configurations.datatable');
|
Route::get('configurations/datatable', [ConfigurationController::class, 'datatable'])->name('configurations.datatable');
|
||||||
Route::patch('configurations/updatevalue', [ConfigurationController::class, 'updatevalue'])->name('configurations.updatevalue');
|
Route::patch('configurations/updatevalue', [ConfigurationController::class, 'updatevalue'])->name('configurations.updatevalue');
|
||||||
Route::resource('configurations', ConfigurationController::class);
|
Route::resource('configurations', ConfigurationController::class);
|
||||||
|
Route::resource('configurations', ConfigurationController::class);
|
||||||
|
|
||||||
Route::patch('settings/update/icons', [SettingsController::class , 'updateIcons'])->name('settings.update.icons');
|
Route::patch('settings/update/icons', [SettingsController::class , 'updateIcons'])->name('settings.update.icons');
|
||||||
Route::resource('settings', SettingsController::class)->only('index');
|
Route::resource('settings', SettingsController::class)->only('index');
|
||||||
|
|
Loading…
Reference in a new issue