50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class PaymentController extends Controller
|
|
{
|
|
public function store(Request $request)
|
|
{
|
|
|
|
|
|
$validated = $request->validate([
|
|
'token' => 'required|string',
|
|
'amount' => 'required|numeric|min:0.01',
|
|
'description' => 'nullable|string|max:255',
|
|
'email' => 'required|email',
|
|
'phone' => 'required|string',
|
|
]);
|
|
|
|
$payload = [
|
|
'amount' => (float) $validated['amount'],
|
|
'currency' => 'MXN',
|
|
'description' => $validated['description'] ?? 'Pago con SDK Clip',
|
|
'payment_method' => [
|
|
'token' => $validated['token']
|
|
],
|
|
'customer' => [
|
|
'email' => $validated['email'],
|
|
'phone' => $validated['phone']
|
|
]
|
|
];
|
|
|
|
$response = Http::withHeaders([
|
|
'Authorization' => 'Bearer ' . config('clip.api_key'),
|
|
'Content-Type' => 'application/json',
|
|
])->post(config('clip.payments_url'), $payload);
|
|
|
|
if ($response->successful()) {
|
|
return response()->json($response->json(), 201);
|
|
}
|
|
|
|
return response()->json([
|
|
'error' => $response->json('detail') ?? 'Error al procesar el pago',
|
|
'code' => $response->json('error_code')
|
|
], $response->status());
|
|
}
|
|
}
|