acatus-dev/paybox-bundle
Symfony bundle to integrate Paybox payments: handles HMAC signing, server availability checks, IPN signature verification via OpenSSL, and dispatches events on responses. Configure your account parameters and submit transaction data.
Installation:
composer require acatus-dev/paybox-bundle
Ensure pecl hash and openssl are enabled in your PHP environment.
Bundle Registration:
Add to config/bundles.php (Symfony 5+):
return [
// ...
Acatus\PayboxBundle\AcatusPayboxBundle::class => ['all' => true],
];
Configuration: Publish the default config:
php bin/console config:dump-reference AcatusPayboxBundle
Update config/packages/acatus_paybox.yaml with your Paybox credentials:
acatus_paybox:
site: 'YOUR_SITE_ID'
rank: 'YOUR_RANK'
key: 'YOUR_SECRET_KEY'
test: '%env(bool:PAYBOX_TEST_MODE)%' # Set to true for sandbox
First Use Case: Trigger a payment in a controller:
use Acatus\PayboxBundle\Service\PayboxService;
class PaymentController extends AbstractController
{
public function pay(PayboxService $paybox, Request $request): Response
{
$params = [
'amount' => 1000, // 10.00€
'currency' => '978', // Euro
'order_id' => 'ORDER_123',
'return_url' => $this->generateUrl('payment_success'),
'cancel_url' => $this->generateUrl('payment_cancel'),
'customer_email' => 'user@example.com',
];
return $paybox->pay($params);
}
}
Payment Initiation:
PayboxService to generate and redirect to Paybox:
$paybox->pay($transactionParams);
$params (e.g., customer_ip, customer_language).IPN Handling:
# config/routes.yaml
acatus_paybox_ipn:
path: /paybox/ipn
methods: [POST]
controller: Acatus\PayboxBundle\Controller\PayboxController::ipn
paybox.ipn event to process responses:
use Acatus\PayboxBundle\Event\PayboxIpnEvent;
$eventDispatcher->addListener(PayboxIpnEvent::NAME, function (PayboxIpnEvent $event) {
if ($event->isValid()) {
// Process successful payment (e.g., update order status)
}
});
Server Testing:
acatus_paybox:
test_server: true # Validates Paybox server before redirect
Response Customization:
templates/AcatusPayboxBundle/Response/
(e.g., success.html.twig, cancel.html.twig).Order Management:
Link Paybox order_id to your database (e.g., via Order entity) for tracking:
$params['order_id'] = $order->getId();
Webhooks:
For async processing, use the PayboxIpnEvent to trigger jobs or notifications:
$eventDispatcher->addListener(PayboxIpnEvent::NAME, function (PayboxIpnEvent $event) {
if ($event->isValid()) {
PaymentJob::dispatch($event->getOrderId());
}
});
Testing:
Use the sandbox mode (test: true) and mock the PayboxService in tests:
$paybox = $this->createMock(PayboxService::class);
$paybox->method('pay')->willReturn(new Response('Mocked Paybox form'));
HMAC Mismatches:
key in config matches Paybox’s secret key.$event->getRawData(); // Log the raw IPN payload
Test Mode Quirks:
test: true) requires Paybox’s test URLs. Ensure your return_url/cancel_url are accessible in the test environment.Event Dispatching:
paybox.ipn event is not dispatched for invalid signatures. Always check $event->isValid() before processing.PECL Dependencies:
hmac or openssl fails, install extensions:
pecl install hash
sudo apt-get install php-openssl # Debian/Ubuntu
Log IPN Payloads: Add a subscriber to log events:
use Acatus\PayboxBundle\Event\PayboxIpnEvent;
class PayboxLoggerSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [PayboxIpnEvent::NAME => 'onIpn'];
}
public function onIpn(PayboxIpnEvent $event): void
{
\Log::debug('Paybox IPN', ['data' => $event->getRawData()]);
}
}
Signature Verification: Manually verify signatures for testing:
use Acatus\PayboxBundle\Validator\PayboxSignatureValidator;
$validator = new PayboxSignatureValidator($config['key']);
$isValid = $validator->isValidSignature($rawData);
Custom Validators:
Extend PayboxSignatureValidator to add business logic (e.g., IP whitelisting):
class CustomPayboxValidator extends PayboxSignatureValidator
{
public function isValidSignature(array $data): bool
{
if (!in_array($data['customer_ip'], ['192.168.1.0/24'])) {
return false;
}
return parent::isValidSignature($data);
}
}
Register it in services.yaml:
services:
Acatus\PayboxBundle\Validator\PayboxSignatureValidator:
class: App\Validator\CustomPayboxValidator
Dynamic Config: Override config per environment (e.g., dev/staging/prod):
# config/packages/dev/acatus_paybox.yaml
acatus_paybox:
test: true
test_server: true
Async Processing: Use Symfony Messenger to handle IPN events asynchronously:
$eventDispatcher->addListener(PayboxIpnEvent::NAME, function (PayboxIpnEvent $event) {
if ($event->isValid()) {
$message = new ProcessPaymentMessage($event->getOrderId());
$this->messageBus->dispatch($message);
}
});
How can I help you explore Laravel packages today?