creagia/laravel-redsys
A Laravel package for integrating Spain's Redsys payment gateway. Easily generate signed payment requests, redirect customers to the virtual POS, and securely handle server notifications and callbacks with minimal configuration.
3.0.3 if your app is older.composer require creagia/laravel-redsys
php artisan vendor:publish --provider="Creagia\Redsys\RedsysServiceProvider"
php artisan migrate
.env:
REDSYS_ENVIRONMENT=test
REDSYS_MERCHANT_CODE=999008881
REDSYS_TERMINAL=1
REDSYS_SECRET_KEY=base64-encoded-terminal-secret
config/redsys.php for merchant code, terminal, secret key, environment, and route/notification settings.Redsys facade for form generation and response helpers.RedsysNotification model.use Creagia\Redsys\Facades\Redsys;
$order = Order::create([...]); // status: pending
$form = Redsys::generatePaymentForm(
order: $order->reference, // max 12 chars, unique
amount: $order->total_cents, // amount in cents
urlOk: route('checkout.ok'),
urlKo: route('checkout.ko'),
notificationUrl: route('redsys.notification'),
);
return view('checkout.redirect', compact('form')); // render with {!! $form !!}
urlOk/urlKo pages are user experience only; a customer can open the OK URL manually. Only fulfil an order after the package has validated the Redsys signature in the notification endpoint.pending status and a unique merchant order reference.Event::listen(RedsysNotificationReceived::class, function ($event) {
$notification = $event->redsysNotification;
$order = Order::where('reference', $notification->order)->firstOrFail();
if ($notification->isSuccessful()
&& $notification->amount === $order->total_cents) {
$order->markAsPaid($notification->authorisation_code);
}
});
Check the exact event class in your installed version; alternatively publish/override the notification controller and dispatch your own domain event.Ds_MerchantParameters/response payload accessible when investigating bank-side disputes.PaymentService around the facade keeps controllers thin and lets you swap the package or add reconciliation commands later.urlOk.validateCsrfTokens(except: [...]); otherwise notifications fail with 419 and orders remain pending.100 = 1.00 EUR). Confirm the currency in config/redsys.php; the default is usually EUR (978). A decimal amount will produce a wrong charge or signature mismatch.localhost or private hosts. Ensure notificationUrl is reachable and not behind auth, IP allow-listing, or maintenance mode.0000–0099 are generally approved; 0900 is an authorization; codes such as 0101, 0102, 0190, and 0191 are denials. Store and display the raw code and authorization code.Ds_Order and Ds_MerchantParameters. Log the order reference and response code, but never log the terminal secret or full derived key. A single character difference in the order string causes a valid-looking but rejected signature.php artisan config:clear (and redeploy if config is cached during release).{{ }} will display markup instead of submitting it.How can I help you explore Laravel packages today?