Installation Add the bundle via Composer:
composer require develit-ab/payex-bundle
Enable it in config/bundles.php:
return [
// ...
DevelitAB\PayexBundle\PayexBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console config:dump-reference DevelitAB\PayexBundle\Resources/config/services.yml
Update config/packages/develit_ab_payex.yaml with your PayEx credentials:
develit_ab_payex:
merchant_id: "your_merchant_id"
secret_key: "your_secret_key"
test_mode: true # Set to false for live
First Use Case: Redirect Payment
Use the PayexGateway service to create a payment:
use DevelitAB\PayexBundle\Service\PayexGateway;
public function createPayment(PayexGateway $payex, Request $request)
{
$payment = $payex->createPayment(
$request->request->get('amount'),
$request->request->get('currency'),
$request->request->get('description'),
$request->request->get('callback_url')
);
return new RedirectResponse($payment->getPaymentUrl());
}
Payment Creation & Redirect
PayexGateway::createPayment() for one-click payments.$payment->getPaymentUrl()) in your frontend.paymentId in your DB for later reference.Server-Side Callback Handling
callback_url with payment status.PayexGateway::validateCallback()).public function handleCallback(PayexGateway $payex, Request $request)
{
if ($payex->validateCallback($request)) {
$payment = $payex->getPaymentFromCallback($request);
// Process payment (e.g., update order status)
}
return new Response('OK');
}
Recurring Payments
PayexGateway::createRecurringPayment() for subscriptions.recurringPaymentId and handle renewal callbacks.Refunds
PayexGateway::createRefund() for partial/full refunds:
$refund = $payex->createRefund(
$paymentId,
$amount,
$currency,
$description
);
paymentId, status, and amount in your orders table.paymentId and callback responses for debugging.test_mode: true with PayEx’s sandbox environment.paymentUrl to redirect users; never expose the paymentId directly.Callback Validation
validateCallback()). Skipping this exposes you to fraud.PayexGateway::getPaymentFromCallback() to parse the response safely.Test Mode Quirks
4111111111111111).Currency & Amount
100.00 → 10000 for SEK).Idempotency
paymentId for retries.paymentId in your DB to avoid duplicate payments.Deprecated Methods
DevelitAB\PayexBundle for callback debugging.PayexGateway::getLastResponse() to debug failed callbacks.Custom Callback Logic
DevelitAB\PayexBundle\Service\PayexGateway to add custom payment status handlers.$payex->onPaymentSuccess(function ($payment) {
// Custom logic (e.g., send email)
});
Webhook Handling
Multi-Currency Support
PayexGateway to handle dynamic currency conversion if needed.How can I help you explore Laravel packages today?