Se cargan las modificaciones para pasarela stripe

This commit is contained in:
2026-03-12 17:17:03 -06:00
parent 46a0f8b1c3
commit 58e27fc5fc
10 changed files with 99 additions and 8 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ class PagoController extends Controller
{ {
$user = Auth::user(); $user = Auth::user();
$prospectoId = $user->prospectos()->value('prospectos.id'); $prospectoId = $user->alumnos()->value('alumnos.id');
$pagos = Pago::where('user_id', $prospectoId)->get(); $pagos = Pago::where('user_id', $prospectoId)->get();
+6 -2
View File
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Models\Plane; use App\Models\Plane;
use App\Models\Plantel; use App\Models\Plantel;
use App\Models\Concepto; use App\Models\Concepto;
use App\Models\Nivel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
@@ -53,9 +54,10 @@ class PlaneController extends Controller
public function edit(Plane $plane) public function edit(Plane $plane)
{ $planConceptos = $plane->conceptos; { $planConceptos = $plane->conceptos;
$plantels = Plantel::where('status','=','1')->get(); $plantels = Plantel::where('status','=','1')->get();
$nivels = Nivel::where('status','=','1')->get();
$conceptos = Concepto::where('tipo','=','3')->get(); $conceptos = Concepto::where('tipo','=','3')->get();
return view('plane.edit',compact('plane','plantels','conceptos','planConceptos')); return view('plane.edit',compact('plane','plantels','conceptos','planConceptos','nivels'));
} }
public function update(Request $request,Plane $plane) public function update(Request $request,Plane $plane)
@@ -64,9 +66,10 @@ class PlaneController extends Controller
'name'=>'required' 'name'=>'required'
]); ]);
$plane->update($request->except(['plantels'])); $plane->update($request->except(['plantels','nivels']));
$plane->planPlantel()->sync($request->plantels); $plane->planPlantel()->sync($request->plantels);
$plane->nivelPlane()->sync($request->nivels);
return redirect()->route('plane.edit',$plane)->with('info','El plan se actualizo correctamente'); return redirect()->route('plane.edit',$plane)->with('info','El plan se actualizo correctamente');
} }
@@ -75,6 +78,7 @@ class PlaneController extends Controller
public function destroy(Plane $plane) public function destroy(Plane $plane)
{ {
$plane->planPlantel()->detach(); $plane->planPlantel()->detach();
$plane->nivelPlane()->detach();
$plane->delete(); $plane->delete();
session()->flash('swal',[ session()->flash('swal',[
'icon'=>'success', 'icon'=>'success',
+9 -1
View File
@@ -4,8 +4,9 @@ namespace App\Http\Controllers;
use App\Models\Concepto; use App\Models\Concepto;
use App\Models\Pago; use App\Models\Pago;
use Stripe\Stripe; use Illuminate\Support\Facades\Auth;
use Stripe\Checkout\Session; use Stripe\Checkout\Session;
use Stripe\Stripe;
class StripeController extends Controller class StripeController extends Controller
{ {
@@ -13,10 +14,14 @@ class StripeController extends Controller
{ {
$concepto = Concepto::where('id', $pago->concepto)->first(); $concepto = Concepto::where('id', $pago->concepto)->first();
$user = Auth::user();
Stripe::setApiKey(config('services.stripe.secret')); Stripe::setApiKey(config('services.stripe.secret'));
$session = Session::create([ $session = Session::create([
'mode' => 'payment', 'mode' => 'payment',
'customer_email' => $user->email,
'line_items' => [[ 'line_items' => [[
'price_data' => [ 'price_data' => [
'currency' => 'mxn', 'currency' => 'mxn',
@@ -27,10 +32,13 @@ class StripeController extends Controller
], ],
'quantity' => 1, 'quantity' => 1,
]], ]],
'success_url' => route('pagar.show',1), 'success_url' => route('pagar.show',1),
'cancel_url' => route('pagar.show',0), 'cancel_url' => route('pagar.show',0),
'metadata' => [ 'metadata' => [
'pago_id' => $pago->id, 'pago_id' => $pago->id,
'user_id' => $user->id,
], ],
]); ]);
@@ -31,14 +31,23 @@ class StripeWebhookController extends Controller
$session = $event->data->object; $session = $event->data->object;
Pago::where('id',$session->id)->update(['estado'=>'pagado']); $pagoId = $session->metadata->pago_id ?? null;
if ($pagoId) {
$pago = Pago::find($pagoId);
if ($pago) {
$pago->estado = 'pagado';
$pago->save();
}
}
break; break;
case 'payment_intent.payment_failed': case 'payment_intent.payment_failed':
// manejar fallo de pago // manejar fallo de pago
break; break;
} }
+4 -1
View File
@@ -255,7 +255,10 @@ class DataProspecto extends Component
$q->where('plantels.id', $this->pplantels) $q->where('plantels.id', $this->pplantels)
)->get(); )->get();
$this->planesPago = Plane::where('nivel', $this->selectedNivel) $this->planesPago = Plane::query()
->whereHas('nivelPlane', function ($q) {
$q->where('nivels.id', $this->selectedNivel);
})
->whereHas('planPlantel', function ($q) { ->whereHas('planPlantel', function ($q) {
$q->where('plantels.id', $this->pplantels); $q->where('plantels.id', $this->pplantels);
}) })
+5
View File
@@ -17,6 +17,11 @@ class Nivel extends Model
return $this->belongsToMany(Plantel::class)->withPivot('plantel_id'); return $this->belongsToMany(Plantel::class)->withPivot('plantel_id');
} }
public function nivelPlane() : BelongsToMany
{
return $this->belongsToMany(Plane::class);
}
public function existe($plantelId = null) public function existe($plantelId = null)
{ {
if (!$plantelId) { if (!$plantelId) {
+16
View File
@@ -16,6 +16,11 @@ class Plane extends Model
return $this->belongsToMany(Plantel::class)->withPivot('plantel_id'); return $this->belongsToMany(Plantel::class)->withPivot('plantel_id');
} }
public function nivelPlane() : BelongsToMany
{
return $this->belongsToMany(Nivel::class);
}
public function existe($plantelId = null) public function existe($plantelId = null)
{ {
if (!$plantelId) { if (!$plantelId) {
@@ -27,6 +32,17 @@ class Plane extends Model
->exists(); ->exists();
} }
public function nivel($nivelId = null)
{
if (!$nivelId) {
return false;
}
return $this->nivelPlane()
->wherePivot('nivel_id', $nivelId)
->exists();
}
public function conceptos(): BelongsToMany public function conceptos(): BelongsToMany
{ {
return $this->belongsToMany(Concepto::class) return $this->belongsToMany(Concepto::class)
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('nivel_plane', function (Blueprint $table) {
$table->unsignedBigInteger('nivel_id');
$table->foreign('nivel_id')->references('id')->on('nivels');
$table->unsignedBigInteger('plane_id');
$table->foreign('plane_id')->references('id')->on('planes');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('nivel_plane');
}
};
+1 -1
View File
@@ -16,7 +16,7 @@ class RoleSeeder extends Seeder
$role1 = Role::create(['name'=>'Admin']); $role1 = Role::create(['name'=>'Admin']);
$role2 = Role::create(['name'=>'Blogger']); $role2 = Role::create(['name'=>'Blogger']);
$role3 = Role::create(['name'=>'Promotor']); $role3 = Role::create(['name'=>'Promotor']);
$role4 = Role::create(['name'=>'alumno']); $role4 = Role::create(['name'=>'Alumno']);
Permission::create(['name'=>'note.index','description'=>'Ver notas'])->syncRoles([$role2]); Permission::create(['name'=>'note.index','description'=>'Ver notas'])->syncRoles([$role2]);
Permission::create(['name'=>'note.create','description'=>'Crear notas'])->syncRoles([$role2]); Permission::create(['name'=>'note.create','description'=>'Crear notas'])->syncRoles([$role2]);
+17
View File
@@ -49,6 +49,23 @@
@endforeach @endforeach
</div> </div>
<div class="mb-3">
<label>Niveles a impartir</label>
@foreach ($nivels as $nivel)
<div class="form-check">
<input type="checkbox" class="form-check-input cb"
id="n-{{ $nivel->id }}"
name="nivels[]" value="{{ $nivel->id }}"
{{ $plane->nivel($nivel->id) ? 'checked' : '' }}
>
<label class="form-check-label" for="n-{{ $nivel->id }}">
{{ $nivel->name }}
</label>
</div>
@endforeach
</div>
<div class="mb-3"> <div class="mb-3">
<label for="status">Seleccionar status</label> <label for="status">Seleccionar status</label>
<select class="form-control" name="status" id="status" value="{{ $plantel->status }}"> <select class="form-control" name="status" id="status" value="{{ $plantel->status }}">