Installation Add the package via Composer:
composer require djoo/symfony2hipaylib
Autoload Configuration
Modify app/autoload.php to include the Hipay library:
$loader->add('HIPAY', __DIR__.'/../vendor/djoo/symfony2hipaylib/lib/hipay');
require __DIR__.'/../vendor/djoo/symfony2hipaylib/lib/hipay/mapi_package.php';
First Use Case Use the library in a Symfony2 controller to initialize a payment:
use HIPAY;
$params = new \HIPAY_MAPI_PaymentParams();
$params->setSite('YOUR_SITE_ID');
$params->setPassword('YOUR_PASSWORD');
$params->setAccount('YOUR_ACCOUNT_ID');
Payment Initialization
Use HIPAY_MAPI_PaymentParams to configure payment details:
$params = new \HIPAY_MAPI_PaymentParams();
$params->setAmount(1000); // Amount in cents
$params->setCurrency('978'); // EUR
$params->setOrderId('ORDER_123');
$params->setReturn('https://your-site.com/return');
Sending Payment Requests
Use HIPAY_MAPI_SEND_XML to send XML requests to Hipay:
$xmlTx = $params->createXML();
$urlHipay = 'https://secure.hipay.com/payment/v4';
$output = \HIPAY_MAPI_SEND_XML::sendXML($xmlTx, $urlHipay);
Handling Responses
Parse Hipay’s response using HIPAY_MAPI_ResponseParser:
$responseParser = new \HIPAY_MAPI_ResponseParser();
$responseParser->setXml($output);
$response = $responseParser->getResponse();
Webhook Validation Validate Hipay webhook notifications:
$notification = new \HIPAY_MAPI_Notification();
$notification->setXml($rawPostData);
if ($notification->isValid()) {
$status = $notification->getStatus();
}
services.yml for dependency injection:
services:
hipay.payment:
class: HIPAY_MAPI_PaymentParams
arguments: ['%hipay.site_id%', '%hipay.password%', '%hipay.account_id%']
parameters.yml:
parameters:
hipay.site_id: YOUR_SITE_ID
hipay.password: YOUR_PASSWORD
hipay.account_id: YOUR_ACCOUNT_ID
try {
$output = \HIPAY_MAPI_SEND_XML::sendXML($xmlTx, $urlHipay);
} catch (\Exception $e) {
// Log error or notify admin
}
Namespace Conflicts
The package uses the HIPAY namespace directly. Ensure no naming collisions exist in your project. Prefix classes if necessary:
use HIPAY as HipayLib;
XML Parsing Issues Hipay’s XML responses may fail if malformed. Validate XML before parsing:
if (!\HIPAY_MAPI_Tools::isValidXml($output)) {
throw new \RuntimeException('Invalid XML response from Hipay');
}
Deprecated Methods The package mirrors Hipay’s original library, which may include deprecated methods. Check Hipay’s official documentation for updates.
Autoloading Quirks
Forgetting to add the HIPAY namespace to autoload.php will result in ClassNotFound errors. Always include:
$loader->add('HIPAY', __DIR__.'/../vendor/djoo/symfony2hipaylib/lib/hipay');
Enable Hipay Logging Configure Hipay’s logger to debug issues:
\HIPAY_MAPI_Tools::setLogLevel(\HIPAY_MAPI_Tools::LOG_DEBUG);
\HIPAY_MAPI_Tools::setLogFile(__DIR__.'/hipay_debug.log');
Test with Sandbox
Use Hipay’s sandbox environment (https://sandbox.hipay.com) for testing:
$urlHipay = 'https://sandbox.hipay.com/payment/v4';
Custom Response Handlers
Extend HIPAY_MAPI_ResponseParser to add custom logic:
class CustomResponseParser extends \HIPAY_MAPI_ResponseParser {
public function getCustomField() {
return $this->getField('CUSTOM_FIELD');
}
}
Event Dispatching Integrate with Symfony’s event system to trigger actions on Hipay events:
$dispatcher->dispatch('hipay.notification', new HipayNotificationEvent($notification));
Middleware for Webhooks Create a Symfony firewall or middleware to validate Hipay webhooks:
public function onKernelRequest(GetResponseEvent $event) {
if ($event->getRequest()->getPathInfo() === '/hipay/webhook') {
$notification = new \HIPAY_MAPI_Notification();
$notification->setXml($event->getRequest()->getContent());
if (!$notification->isValid()) {
throw new \RuntimeException('Invalid Hipay webhook');
}
}
}
How can I help you explore Laravel packages today?