Installation
composer require jh9/robokassa-bundle
Register the bundle in app/AppKernel.php:
new jh9\RobokassaBundle\jh9RobokassaBundle(),
Configuration
Add Robokassa credentials to app/config/config.yml:
jh9_robokassa:
login: %robokassa_login% # From .env or parameters.yml
password1: %robokassa_password1% # Merchant password 1
password2: %robokassa_password2% # Merchant password 2
test: %kernel.debug% # Enable test mode in dev
First Use Case
Generate a payment form in a Twig template (e.g., pay_order.html.twig):
{{ jh9_robokassa_form(order.id, order.amount) }}
This renders a pre-configured Robokassa payment button linking to the payment gateway.
Payment Initiation
jh9_robokassa_form() in Twig to generate a payment button.order.id, order.amount) and optional overrides (e.g., Desc, IncCurrLabel).{{ jh9_robokassa_form(123, 100.50, {
"Desc": "Premium Subscription",
"IncCurrLabel": "USD"
}) }}
Handling Callback Responses
ResultUrl endpoint (e.g., /robokassa/result) to process Robokassa callbacks:
/**
* @Route("/robokassa/result", name="robokassa_result")
* @Methods({"POST"})
*/
public function resultAction(Request $request)
{
$manager = $this->get('jh9.robokassa.manager');
$result = $manager->handleResult($request);
if ($result->isValid()) {
// Update order status, send confirmation, etc.
$this->updateOrderStatus($result->getInvId());
}
return new Response('OK');
}
Validation and Order Management
$result->getInvId() to fetch the order ID from the callback.if ($result->getAmount() == $expectedAmount) {
$this->markOrderAsPaid($result->getInvId());
}
jh9RobokassaBundle:Twig:payForm.html.twig) in your theme.$this->get('logger')->info('Robokassa callback', ['data' => $request->request->all()]);
test: true mode before going live. Use Robokassa’s sandbox for testing.POST-Only Support
ResultUrl endpoint is POST-only (as shown in the example).@Methods({"POST"}) to your route to block GET requests.Missing Order ID Handling
InvId (order ID) is not provided in the callback, $result->getInvId() returns null. Always validate this field:
if (null === $result->getInvId()) {
throw new \RuntimeException('Invalid Robokassa callback: missing order ID');
}
Test Mode Quirks
test: true) uses Robokassa’s sandbox. Ensure your test credentials match the sandbox environment.OutSum (amount) and InvId fields in test responses to verify they match your expectations.Encoding Issues
utf-8 encoding. If you encounter garbled text in descriptions or callbacks:
Encoding: "utf-8" in the form options.Callback Validation Failures
$result->isValid() returns false, inspect the raw request data:
$rawData = $request->request->all();
$this->get('logger')->error('Robokassa validation failed', ['data' => $rawData]);
password1/password2 in config.OutSum or InvId in the callback.Signature Verification
SignatureValue field. If you need to bypass this (e.g., for testing), use:
$result = $manager->handleResult($request, false); // Skip signature check
Custom Callback Logic
jh9\RobokassaBundle\Manager service to add custom validation:
$this->container->set('jh9.robokassa.manager', $this->container->share(function() {
return new CustomRobokassaManager(
$this->getParameter('jh9_robokassa.login'),
$this->getParameter('jh9_robokassa.password1'),
$this->getParameter('jh9_robokassa.password2'),
$this->getParameter('jh9_robokassa.test')
);
}));
Additional Fields
{{ jh9_robokassa_form(order.id, order.amount, {
"Email": user.email,
"Culture": "ru"
}) }}
Event Dispatching
robokassa.callback event (if the bundle supports it). If not, wrap the logic in a service and dispatch events manually:
$this->get('event_dispatcher')->dispatch(
'robokassa.callback.valid',
new RobokassaEvent($result)
);
How can I help you explore Laravel packages today?