1. Go to this page and download the library: Download taypi/taypi-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
taypi / taypi-php example snippets
pi = new Taypi\Taypi(
'taypi_pk_test_...', // Public key
'taypi_sk_test_...', // Secret key
);
// Crear sesión de checkout
$session = $taypi->createCheckoutSession([
'amount' => '25.00',
'reference' => 'ORD-12345',
'description' => 'Zapatillas Nike Air',
], 'ORD-12345'); // Idempotency-Key
echo $session['checkout_token'];
// 1. Backend: crea la sesión y entrega solo el token al frontend
$session = $taypi->createCheckoutSession([
'amount' => '50.00',
'reference' => 'ORD-123',
], 'ORD-123');
$token = $session['checkout_token'];
// 2. Frontend (checkout.js) o backend: lee los datos completos de la sesión
$details = $taypi->getCheckoutSession($token);
echo $details['qr_image']; // SVG base64
echo $details['merchant_name'];
// Verificar firma de webhook recibido
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_TAYPI_SIGNATURE'];
$secret = 'tu_webhook_secret';
if ($taypi->verifyWebhook($payload, $signature, $secret)) {
// Webhook válido, procesar
$event = json_decode($payload, true);
} else {
// Firma inválida, rechazar
http_response_code(403);
}
// Producción (default)
$taypi = new Taypi\Taypi('pk', 'sk');
// Desarrollo
$taypi = new Taypi\Taypi('pk', 'sk', ['base_url' => 'https://sandbox.taypi.pe']);
// Sandbox
$taypi = new Taypi\Taypi('pk', 'sk', ['base_url' => 'https://sandbox.taypi.pe']);
// Usar la referencia de orden como idempotency key
$taypi->createCheckoutSession($params, 'ORD-12345');
// Si el mismo key se envía dentro de los 15 minutos, retorna la respuesta cacheada
// sin crear un pago nuevo.
try {
$session = $taypi->createCheckoutSession($params, $reference);
} catch (Taypi\TaypiException $e) {
echo $e->getMessage(); // "El monto mínimo es S/ 1.00"
echo $e->errorCode; // "AMOUNT_TOO_LOW"
echo $e->httpCode; // 422
echo $e->response; // Respuesta completa del API (array)
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.