SDK PHP
Cliente oficial de iPagos para PHP 8.1+. Compatible con frameworks modernos como Laravel, Symfony, Slim y CodeIgniter 4.
Instalación
composer require ipagos/ipagos-php
Inicialización
<?php
require 'vendor/autoload.php';
use IPagos\Client;
$ipagos = new Client(
secretKey: getenv('IPAGOS_SECRET_KEY'),
apiVersion: '2026-01-15',
maxRetries: 3,
);
Crear un pago
<?php
$payment = $ipagos->payments->create([
'amount' => 25000,
'currency' => 'MXN',
'source' => 'tok_visa_4242',
'description' => 'Pedido #1042',
'metadata' => ['order_id' => '1042'],
], [
'idempotency_key' => bin2hex(random_bytes(16)),
]);
echo $payment->id, ' ', $payment->status;
Integración con Laravel
<?php
// config/services.php
'ipagos' => [
'key' => env('IPAGOS_SECRET_KEY'),
'webhook'=> env('IPAGOS_WEBHOOK_SECRET'),
],
// app/Providers/AppServiceProvider.php
$this->app->singleton(IPagos\Client::class, fn () =>
new IPagos\Client(config('services.ipagos.key'))
);
// app/Http/Controllers/CheckoutController.php
public function pay(Request $request, IPagos\Client $ipagos)
{
$payment = $ipagos->payments->create([
'amount' => $request->integer('amount'),
'currency' => 'MXN',
'source' => $request->string('token'),
]);
return response()->json($payment);
}
Manejo de errores
<?php
use IPagos\Exceptions\CardException;
use IPagos\Exceptions\RateLimitException;
use IPagos\Exceptions\ApiException;
try {
$payment = $ipagos->payments->create([...]);
} catch (CardException $e) {
// El banco rechazó la tarjeta — mostrar al usuario.
return back()->withErrors(['card' => $e->getMessage()]);
} catch (RateLimitException $e) {
// Esperar y reintentar.
sleep($e->retryAfter);
} catch (ApiException $e) {
// Falla genérica — log + retry asíncrono.
Log::error('iPagos', ['id' => $e->requestId, 'msg' => $e->getMessage()]);
}