diff --git a/.gitignore b/.gitignore index 04ee6ae3..9e16607b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,21 @@ Homestead.json Homestead.yaml Thumbs.db !.cpanel.yml + + +# Laravel storage +/storage/*.key +/storage/app/* +!/storage/app/public + +/storage/app/public/* +!/storage/app/public/.gitignore + +/storage/framework/* +/storage/logs/* + +# Livewire temp +/storage/app/private/livewire-tmp + +# Archivos subidos +/storage/app/public/documentos diff --git a/app/Http/Controllers/PagoController.php b/app/Http/Controllers/PagoController.php index c6616b0e..912d8cd2 100644 --- a/app/Http/Controllers/PagoController.php +++ b/app/Http/Controllers/PagoController.php @@ -2,27 +2,104 @@ namespace App\Http\Controllers; -use App\Models\Pago; use App\Models\Concepto; +use App\Models\Pago; +use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Auth; +use Openpay\Data\Openpay; class PagoController extends Controller { // public function __construct() { // $this->middleware('can:user.index')->only('index'); // } - public function index() - { - $user = Auth::user(); +public function index() +{ + $user = Auth::user(); - $prospectoId = $user->alumnos()->value('alumnos.id'); + $prospectoId = $user->alumnos()->value('alumnos.id'); - $pagos = Pago::where('user_id', $prospectoId)->get(); + $pagos = Pago::where('user_id', $prospectoId)->get(); - $nombres = Concepto::where('tipo', '3')->get(); + $nombres = Concepto::where('tipo', '3')->get(); - return view('pago.index',compact('pagos','nombres')); + return view('pago.index',compact('pagos','nombres')); +} + +public function pagar(Request $request, $id) +{ + try { + + $pago = Pago::findOrFail($id); + + $openpay = Openpay::getInstance( + env('OPENPAY_ID'), + env('OPENPAY_PRIVATE_KEY'), + 'MX', + false + ); + + $orderId = 'pago_'.$pago->id.'_'.time(); + + if ($request->metodo === 'store') { + + $charge = $openpay->charges->create([ + 'method' => 'store', + 'amount' => (float)$pago->monto, + 'description' => 'Pago '.$pago->id, + 'order_id' => $orderId, + 'customer' => [ + 'name' => Auth::user()->name, + 'email' => Auth::user()->email, + ] + ]); + + $pago->update([ + 'openpay_id' => $charge->id, + 'referencia' => $charge->payment_method->reference ?? null, + 'metodo_pago' => 'store', + 'status' => 'pendiente' + ]); + + return response()->json([ + 'referencia' => $charge->payment_method->reference + ]); + } + + if ($request->metodo === 'spei') { + + $charge = $openpay->charges->create([ + 'method' => 'bank_account', + 'amount' => (float)$pago->monto, + 'description' => 'Pago '.$pago->id, + 'order_id' => $orderId, + 'customer' => [ + 'name' => Auth::user()->name, + 'email' => Auth::user()->email, + ] + ]); + + $pago->update([ + 'openpay_id' => $charge->id, + 'referencia' => $charge->payment_method->clabe ?? null, + 'metodo_pago' => 'spei', + 'status' => 'pendiente' + ]); + + return response()->json([ + 'clabe' => $charge->payment_method->clabe + ]); + } + + } catch (\Throwable $e) { + + return response()->json([ + 'error' => $e->getMessage(), + 'line' => $e->getLine(), + 'file' => $e->getFile() +], 500); } +} } diff --git a/composer.json b/composer.json index 8bf506f8..51a92533 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "laravel/sanctum": "^4.0", "laravel/tinker": "^2.10.1", "livewire/livewire": "^3.6.4", + "openpay/sdk": "^3.1", "spatie/laravel-permission": "^6.24", "stripe/stripe-php": "^19.2" }, diff --git a/composer.lock b/composer.lock index 195fa899..02975c53 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5d64888217fcdda5f613895b74c621a7", + "content-hash": "28550ccb2083e2f7896811098a56fc72", "packages": [ { "name": "bacon/bacon-qr-code", @@ -3390,6 +3390,57 @@ ], "time": "2025-11-20T02:34:59+00:00" }, + { + "name": "openpay/sdk", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/open-pay/openpay-php.git", + "reference": "5a922d4e95e6c68c37c6e558e33b6f7e4918f398" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/open-pay/openpay-php/zipball/5a922d4e95e6c68c37c6e558e33b6f7e4918f398", + "reference": "5a922d4e95e6c68c37c6e558e33b6f7e4918f398", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-hash": "*", + "php": ">=5.2.1" + }, + "require-dev": { + "phpunit/phpunit": "4.8.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Openpay\\": "Openpay/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Openpay", + "email": "soporte@openpay.mx", + "homepage": "https://www.openpay.mx/" + }, + { + "name": "Federico Balderas", + "email": "plugins@openpay.mx", + "homepage": "https://openpay.mx/" + } + ], + "description": "This is a client implementing the payment services for Openpay at openpay.mx", + "support": { + "issues": "https://github.com/open-pay/openpay-php/issues", + "source": "https://github.com/open-pay/openpay-php/tree/3.1.1" + }, + "time": "2024-10-28T22:15:37+00:00" + }, { "name": "paragonie/constant_time_encoding", "version": "v3.1.3", diff --git a/database/migrations/2026_01_20_194834_create_pagos_table.php b/database/migrations/2026_01_20_194834_create_pagos_table.php index e936658e..7c476a21 100644 --- a/database/migrations/2026_01_20_194834_create_pagos_table.php +++ b/database/migrations/2026_01_20_194834_create_pagos_table.php @@ -7,7 +7,11 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { /** - * Run the migrations. + + const STATUS_PENDIENTE = 'pendiente'; + const STATUS_PROCESO = 'proceso'; + const STATUS_PAGADO = 'pagado'; + const STATUS_FALLIDO = 'fallido'; */ public function up(): void { @@ -23,7 +27,16 @@ return new class extends Migration $table->dateTime('fecha_pagado')->nullable(); $table->unsignedBigInteger('user_id'); $table->unsignedBigInteger('asignacion'); - $table->integer('status'); + $table->enum('status', ['pendiente','proceso','pagado','fallido'])->default('pendiente'); + + $table->string('openpay_id')->nullable(); + $table->string('order_id')->nullable()->unique(); + $table->string('metodo_pago')->nullable(); + $table->string('referencia')->nullable(); + $table->timestamp('fecha_webhook')->nullable(); + + $table->json('openpay_response')->nullable(); + $table->timestamps(); }); } diff --git a/resources/views/pago/index.blade.php b/resources/views/pago/index.blade.php index 3590352f..0d07e1ce 100644 --- a/resources/views/pago/index.blade.php +++ b/resources/views/pago/index.blade.php @@ -41,12 +41,12 @@ {{$pago->monto}} -
- @csrf - -
+ @empty @@ -63,6 +63,31 @@ + + + @endsection @@ -78,4 +103,102 @@ }); @endif + + + + {{-- OpenPay --}} + + + + @endsection diff --git a/routes/web.php b/routes/web.php index b0292cd1..94cc96f5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -76,8 +76,10 @@ Route::middleware(['auth:sanctum',config('jetstream.auth_session'),'verified', Route::resource('/nivel',NivelController::class); Route::resource('/note',NoteController::class); Route::resource('/pago',PagoController::class); - Route::post('/pagar/{pago}', [StripeController::class, 'pagar'])->name('pagar'); - Route::get('/pagar/{status}', [StripeController::class, 'show'])->name('pagar.show'); + // Route::post('/pagar/{pago}', [StripeController::class, 'pagar'])->name('pagar'); + // Route::get('/pagar/{status}', [StripeController::class, 'show'])->name('pagar.show'); + + Route::post('/pagar/{id}', [PagoController::class, 'pagar'])->name('pagar'); Route::get('/perfil', [UserProfileController::class, 'show'])->name('perfil');}); Route::resource('/permission',PermissionController::class); Route::resource('/plan',PlanController::class);