oda79 / robokassa-php
Lightweight PHP library for Robokassa payment integration
v1.0.0
2026-03-17 13:37 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.6
README
Lightweight PHP library for Robokassa payment integration (framework-agnostic).
This package provides a small, framework-agnostic integration layer for:
- building Robokassa payment fields
- creating fiscal receipt items
- calculating payment signatures
- verifying ResultURL and SuccessURL signatures
- parsing callback payloads
- rendering an auto-submit HTML payment form
It does not include any business logic, database layer, or framework-specific routing.
Features
- Plain PHP integration
- Supports payment receipt (
Receipt) - Supports test mode credentials
- Supports
SuccessUrl2,FailUrl2,ResultUrl2 - Supports
shp_*custom parameters - Verifies callback signatures
- Optional file logging
Design principles
- No framework dependencies
- No business logic inside the library
- Explicit configuration
- Minimal surface area
Requirements
- PHP 7.4+
Installation
Composer
composer require oda79/robokassa-php
Manual
Copy src/Robokassa folder to your project and include it manually.
Basic Usage
require_once __DIR__ . '/src/Robokassa.php'; $config = require __DIR__ . '/examples/config.example.php'; $robokassa = new \SwimLeague\Robokassa\Robokassa($config); $fields = $robokassa->buildPaymentData([ 'invoice_id' => '100001', 'amount' => '790', 'email' => 'customer@example.com', 'description' => 'Online commission payment', 'receipt_items' => [ $robokassa->makeReceiptItem('Online commission', '790'), ], 'shp' => [ 'shp_id' => '1', ], ]); echo $robokassa->renderRedirectForm($fields);
Callback verification
$request = $_POST; $parsed = $robokassa->parseCallbackRequest($request); if (!$robokassa->verifyResultSignature($request)) { http_response_code(400); echo 'bad sign'; exit; } echo 'OK' . $parsed['InvId'];
Tests
composer install
composer test
Notes
- Payment status should be updated only from ResultURL callback, not from success/fail return pages.
- Fiscal receipt generation is asynchronous and is not returned in the standard payment callback.
- Application-specific input forms should be handled outside of the library.
Examples
See examples/ folder for:
- Basic payment form generation
examples/basic-payment.php - Callback handler example
examples/callback-handler.php - Form POST adapter example
examples/form-post-adapter.php - Return URL handlers
examples/return-ok.phpandexamples/return-fail.php
WordPress integration
See docs/WORDPRESS_INTEGRATION.md.
License
MIT License. See LICENSE file for details.