se carga sdk de openPay
This commit is contained in:
+18
@@ -22,3 +22,21 @@ Homestead.json
|
|||||||
Homestead.yaml
|
Homestead.yaml
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
!.cpanel.yml
|
!.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
|
||||||
|
|||||||
@@ -2,27 +2,104 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Pago;
|
|
||||||
use App\Models\Concepto;
|
use App\Models\Concepto;
|
||||||
|
use App\Models\Pago;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Openpay\Data\Openpay;
|
||||||
|
|
||||||
class PagoController extends Controller
|
class PagoController extends Controller
|
||||||
{
|
{
|
||||||
// public function __construct() {
|
// public function __construct() {
|
||||||
// $this->middleware('can:user.index')->only('index');
|
// $this->middleware('can:user.index')->only('index');
|
||||||
// }
|
// }
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$user = Auth::user();
|
$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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"laravel/sanctum": "^4.0",
|
"laravel/sanctum": "^4.0",
|
||||||
"laravel/tinker": "^2.10.1",
|
"laravel/tinker": "^2.10.1",
|
||||||
"livewire/livewire": "^3.6.4",
|
"livewire/livewire": "^3.6.4",
|
||||||
|
"openpay/sdk": "^3.1",
|
||||||
"spatie/laravel-permission": "^6.24",
|
"spatie/laravel-permission": "^6.24",
|
||||||
"stripe/stripe-php": "^19.2"
|
"stripe/stripe-php": "^19.2"
|
||||||
},
|
},
|
||||||
|
|||||||
Generated
+52
-1
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "5d64888217fcdda5f613895b74c621a7",
|
"content-hash": "28550ccb2083e2f7896811098a56fc72",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "bacon/bacon-qr-code",
|
"name": "bacon/bacon-qr-code",
|
||||||
@@ -3390,6 +3390,57 @@
|
|||||||
],
|
],
|
||||||
"time": "2025-11-20T02:34:59+00:00"
|
"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",
|
"name": "paragonie/constant_time_encoding",
|
||||||
"version": "v3.1.3",
|
"version": "v3.1.3",
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
return new class extends Migration
|
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
|
public function up(): void
|
||||||
{
|
{
|
||||||
@@ -23,7 +27,16 @@ return new class extends Migration
|
|||||||
$table->dateTime('fecha_pagado')->nullable();
|
$table->dateTime('fecha_pagado')->nullable();
|
||||||
$table->unsignedBigInteger('user_id');
|
$table->unsignedBigInteger('user_id');
|
||||||
$table->unsignedBigInteger('asignacion');
|
$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();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,12 @@
|
|||||||
<td>{{$pago->monto}}</td>
|
<td>{{$pago->monto}}</td>
|
||||||
<td class="row mx-auto">
|
<td class="row mx-auto">
|
||||||
|
|
||||||
<form action="{{ route('pagar', $pago->id) }}" method="POST">
|
<select class="form-control" onchange="pagarMetodo(this.value, {{ $pago->id }})">
|
||||||
@csrf
|
<option value="">Selecciona método</option>
|
||||||
<button class="btn btn-success">
|
<option value="card">Tarjeta</option>
|
||||||
Pagar
|
<option value="store">OXXO</option>
|
||||||
</button>
|
<option value="spei">Transferencia</option>
|
||||||
</form>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
@@ -63,6 +63,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="modal fade" id="modalPago">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content p-3">
|
||||||
|
|
||||||
|
<h5>Pagar con tarjeta</h5>
|
||||||
|
|
||||||
|
<form id="payment-form">
|
||||||
|
|
||||||
|
<input type="hidden" id="pago_id">
|
||||||
|
|
||||||
|
<input data-openpay-card="holder_name" class="form-control mb-2" placeholder="Nombre">
|
||||||
|
<input data-openpay-card="card_number" class="form-control mb-2" placeholder="Tarjeta">
|
||||||
|
<input data-openpay-card="expiration_month" class="form-control mb-2" placeholder="MM">
|
||||||
|
<input data-openpay-card="expiration_year" class="form-control mb-2" placeholder="AA">
|
||||||
|
<input data-openpay-card="cvv2" class="form-control mb-2" placeholder="CVV">
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Pagar</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|
||||||
@@ -78,4 +103,102 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function pagarMetodo(metodo, pagoId) {
|
||||||
|
|
||||||
|
if (!metodo) return;
|
||||||
|
|
||||||
|
if (metodo === 'card') {
|
||||||
|
document.getElementById('pago_id').value = pagoId;
|
||||||
|
$('#modalPago').modal('show');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch('/pagar/' + pagoId, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
metodo: metodo
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
|
||||||
|
console.log('STATUS:', res.status);
|
||||||
|
|
||||||
|
let text = await res.text(); // 👈 lee como texto SIEMPRE
|
||||||
|
console.log('RAW RESPONSE:', text);
|
||||||
|
|
||||||
|
try {
|
||||||
|
let data = JSON.parse(text);
|
||||||
|
console.log('JSON:', data);
|
||||||
|
|
||||||
|
if (data.referencia) {
|
||||||
|
alert('Referencia OXXO: ' + data.referencia);
|
||||||
|
} else if (data.clabe) {
|
||||||
|
alert('CLABE: ' + data.clabe);
|
||||||
|
} else {
|
||||||
|
alert('Respuesta recibida');
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('NO ES JSON:', e);
|
||||||
|
alert('Error: respuesta no válida');
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error('FETCH ERROR:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{{-- OpenPay --}}
|
||||||
|
<script src="https://openpay.s3.amazonaws.com/openpay.v1.min.js"></script>
|
||||||
|
<script src="https://openpay.s3.amazonaws.com/openpay-data.v1.min.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
OpenPay.setId("{{ env('OPENPAY_ID') }}");
|
||||||
|
OpenPay.setApiKey("{{ env('OPENPAY_PUBLIC_KEY') }}");
|
||||||
|
OpenPay.setSandboxMode(true);
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
|
||||||
|
let form = document.getElementById('payment-form');
|
||||||
|
|
||||||
|
if (form) {
|
||||||
|
form.addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
OpenPay.token.extractFormAndCreate('payment-form', function(response){
|
||||||
|
|
||||||
|
let token = response.data.id;
|
||||||
|
let pagoId = document.getElementById('pago_id').value;
|
||||||
|
|
||||||
|
fetch('/pagar/' + pagoId, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
metodo: 'card',
|
||||||
|
token: token
|
||||||
|
})
|
||||||
|
}).then(() => {
|
||||||
|
alert('Pago procesado');
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
}, function(){
|
||||||
|
alert('Error en tarjeta');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
+4
-2
@@ -76,8 +76,10 @@ Route::middleware(['auth:sanctum',config('jetstream.auth_session'),'verified',
|
|||||||
Route::resource('/nivel',NivelController::class);
|
Route::resource('/nivel',NivelController::class);
|
||||||
Route::resource('/note',NoteController::class);
|
Route::resource('/note',NoteController::class);
|
||||||
Route::resource('/pago',PagoController::class);
|
Route::resource('/pago',PagoController::class);
|
||||||
Route::post('/pagar/{pago}', [StripeController::class, 'pagar'])->name('pagar');
|
// Route::post('/pagar/{pago}', [StripeController::class, 'pagar'])->name('pagar');
|
||||||
Route::get('/pagar/{status}', [StripeController::class, 'show'])->name('pagar.show');
|
// 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::get('/perfil', [UserProfileController::class, 'show'])->name('perfil');});
|
||||||
Route::resource('/permission',PermissionController::class);
|
Route::resource('/permission',PermissionController::class);
|
||||||
Route::resource('/plan',PlanController::class);
|
Route::resource('/plan',PlanController::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user