PHPackages                             creagia/laravel-redsys - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. creagia/laravel-redsys

ActiveLibrary[Payment Processing](/categories/payments)

creagia/laravel-redsys
======================

Laravel Redsys Payments Gateway

4.0.0(2mo ago)2013.6k↑73.3%2MITPHPPHP ^8.2CI passing

Since Jan 26Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/creagia/laravel-redsys)[ Packagist](https://packagist.org/packages/creagia/laravel-redsys)[ Docs](https://github.com/creagia/laravel-redsys)[ GitHub Sponsors](https://github.com/creagia)[ RSS](/packages/creagia-laravel-redsys/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (26)Versions (20)Used By (0)

[![Logo Laravel Redsys](/art/laravel-redsys-logosvg.svg)](/art/laravel-redsys-logosvg.svg)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ae5e67196e0a902a558d7718e799865b1ecbfab0163fd631eda231b30bd6ee75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f637265616769612f6c61726176656c2d7265647379732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/creagia/laravel-redsys)[![GitHub Tests Action Status](https://camo.githubusercontent.com/49106bb97c56804dd34935a5633cf3cdf4898865ea6ae5b4fa80db5767f92011/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f637265616769612f6c61726176656c2d7265647379732f72756e2d74657374732e796d6c3f6c6162656c3d7465737473)](https://github.com/creagia/laravel-redsys/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ef2b2d289533376d5af8bcf93c9c129cdf4cd3e98d2206436a597d7f8ab75c51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f637265616769612f6c61726176656c2d7265647379732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6c6162656c3d636f64652532307374796c65)](https://github.com/creagia/laravel-redsys/actions/workflows/fix-php-code-style-issues.yml)[![Total Downloads](https://camo.githubusercontent.com/8a55382ea66318ddd635f0195388bc259c6d650282696203c333f3623d88b022/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f637265616769612f6c61726176656c2d7265647379732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/creagia/laravel-redsys)

Introduction
------------

[](#introduction)

Integrate your Laravel application with Redsys, the lead payment gateway in Spain.

This package provides:

- Redsys integration with Redirection and REST methods
- Associate Redsys request with Eloquent models
- Associate Redsys card tokens with Eloquent models
- Management for Redsys notifications (payment confirmation)
- Advanced custom Redsys requests that cover all features
- Fake gateway for local testing

You'll be able to create a payment request, redirect the user to the payment gateway and process Redsys response with just a few lines of code:

```
public function createPaymentAndRedirect()
{
    $redsysRequest = $yourModel->createRedsysRequest(
        productDescription: 'Product description',
        payMethod: PayMethod::Bizum,
    );
    return $redsysRequest->redirect();
}
```

> If you are not using Laravel, check our other package **[creagia/redsys-php](https://github.com/creagia/redsys-php)** for just a Redsys PHP library.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require creagia/laravel-redsys
```

After that, you should publish and run the migrations:

```
php artisan vendor:publish --tag="redsys-migrations"
php artisan migrate
```

Next, you should publish the config file with:

```
php artisan vendor:publish --tag="redsys-config"
```

Finally, you should define, at least, the required options in your .env file:

```
REDSYS_ENVIRONMENT
REDSYS_MERCHANT_CODE
REDSYS_KEY

```

This is the content of the published config file:

```
return [
    /**
     * Used to define the service URL. Possible values 'test', 'production' or 'local'.
     *
     * It's recommended to use 'local' during your development to enable a local gateway to test your
     * application without need to expose it.
     */
    'environment' => env('REDSYS_ENVIRONMENT'),

    /**
     * Values sent to Redsys.
     */
    'tpv' => [
        'terminal' => env('REDSYS_TERMINAL', 1),
        'currency' => \Creagia\Redsys\Enums\Currency::EUR,
        'merchantCode' => env('REDSYS_MERCHANT_CODE'), // Default test code: 999008881
        'key' => env('REDSYS_KEY'), // Default test key: sq7HjrUOBfKmC576ILgskD5srU870gJ7
    ],

    /**
     * Prefix used by the package routes. 'redsys' by default.
     */
    'routes_prefix' => env('REDSYS_ROUTE_PREFIX', 'redsys'),

    /**
     * Route names for successful and unsuccessful confirm pages. Redsys redirects to these routes
     * after the payment is finished. By default, this package provides two neutral views.
     */
    'successful_payment_route_name' => env('REDSYS_SUCCESSFUL_ROUTE_NAME', null),
    'unsuccessful_payment_route_name' => env('REDSYS_UNSUCCESSFUL_ROUTE_NAME', null),

    /**
     * Use an automatic prefix for the order number with the current year and month.
     */
    'order_num_auto_prefix' => true,

    /**
     * Redsys order number should be unique. Here you can set an order number prefix if you need it.
     * This prefix must be an integer number.
     */
    'order_num_prefix' => env('REDSYS_ORDER_NUM_PREFIX', 0),
];
```

Usage
-----

[](#usage)

- [Introduction](#introduction)
- [Associate requests with Eloquent models](#associate-with-models)
- [Custom Redsys requests](#custom-redsys-requests)
- [Sending requests to Redsys](#redirecting-to-redsys)
- [Credential-On-File requests](#cof-requests)
- [Local Gateway](#local-gateway)
- [Unsuccessful or abandoned payments](#unsuccessful-or-abandoned-payments)
- [Events](#events)

### Introduction

[](#introduction-1)

This packages integrates [redsys-php](https://github.com/creagia/redsys-php) with your Laravel application. You can use it in two different ways:

- [Associating requests with Eloquent models](#associate-with-models)
- [Creating standalone Redsys requests](#standalone-redsys-requests)

### Associate requests with Eloquent models

[](#associate-requests-with-eloquent-models)

Add the `CanCreateRedsysRequests` trait and implement the `RedsysPayable` class to the model you would like make payable.

Typically, this model would be something like `Order` for a full ecommerce or cart system, but you can associate payments with multiple Eloquent models if you prefer it.

You should implement your `getTotalAmount` and `paidWithRedsys` methods. The first one will return the computed total amount for the payment **in cents**. The second will be executed when Redsys confirms the payment was successful.

```
use Creagia\LaravelRedsys\Concerns\CanCreateRedsysRequests;
use Creagia\LaravelRedsys\Contracts\RedsysPayable;

class YourModel extends Model implements RedsysPayable
{
    use CanCreateRedsysRequests;

    public function getTotalAmount(): int
    {
        return 199_99;
    }

    public function paidWithRedsys(): void
    {
        // Notify user, change status to paid, ...
    }
}
```

Create request:

```
use Creagia\Redsys\Enums\PayMethod;

$redsysRequest = $yourModel->createRedsysRequest(
    productDescription: 'Product description',
    payMethod: PayMethod::Card,
);
```

### Custom Redsys requests

[](#custom-redsys-requests)

If you prefer to not associate a Redsys request to an Eloquent model, or you need to create a more complex request, you can create a custom request easily.

This way you can totally customize the request and implement every Redsys feature available. The request input parameters are defined with a `RequestParameters` object that implements all the [available parameters](https://pagosonline.redsys.es/parametros-entrada-salida.html)

```
use Creagia\LaravelRedsys\RequestBuilder;

$redsysRequestBuilder = RequestBuilder::newRequest(
    new \Creagia\Redsys\Support\RequestParameters(
        transactionType: \Creagia\Redsys\Enums\TransactionType::Autorizacion,
        productDescription: 'Description',
        amountInCents: 123_12,
        currency: Currency::EUR,
        payMethods: \Creagia\Redsys\Enums\PayMethod::Card,
    )
);
```

The `RequestBuilder` has some middle methods to help you create your requests. You can associate your custom request with an eloquent model using the `associateWithModel()` method and interact with credit card tokens with `requestingCardToken()`or `usingCardToken()` methods. Check the [Credential-On-File requests](#cof-requests) section to know more about it.

After creating the request you should continue on the next section to send the request to Redsys.

### Sending requests to Redsys

[](#sending-requests-to-redsys)

From all the [integration methods](https://pagosonline.redsys.es/modelos-de-integracion.html) available on Redsys, you can implement 'Redirection' and 'REST' methods.

Once you created your Redsys request, you should send it either with redirection:

```
use Creagia\Redsys\Enums\PayMethod;

public function redirection()
{
    $redsysRequest = $yourModel->createRedsysRequest(
        productDescription: 'Product description',
        payMethod: PayMethod::Card,
    );
    return $redsysRequest->redirect();
}
```

or send it as a POST request:

```
use Creagia\Redsys\Enums\Currency;
use Creagia\Redsys\Enums\TransactionType;
use Creagia\LaravelRedsys\RequestBuilder;
use Illuminate\Database\Eloquent\Model;

public function cancellation(Model $yourModel)
{
    $redsysRequest = RequestBuilder::newRequest(new RequestParameters(
        amountInCents: $yourModel->getTotalAmount(),
        currency: Currency::EUR,
        order: '1446068581',
        transactionType: TransactionType::Anulacion,
    ))->associateWithModel($yourModel);

    return $redsysRequest->post();
}
```

> Keep in mind that the REST integration mode is not available for all features and is not always enabled by default. Always check the Redsys documentation and your account configuration if you are not sure if you can use it or something is not working.

#### Redsys response

[](#redsys-response)

Redsys notification with the request result will be automatically managed by the package. For successful payments, the package will run the `paidWithRedsys` method from your model.

#### Redirect users back

[](#redirect-users-back)

In the redirection method, when the client has finished, Redsys will redirect they to your website. By default, this package serves a successful or unsuccessful route with a pretty simple view. You can override redirect routes on the config file:

```
'successful_payment_route_name' => env('REDSYS_SUCCESSFUL_ROUTE_NAME', null),
'unsuccessful_payment_route_name' => env('REDSYS_UNSUCCESSFUL_ROUTE_NAME', null),
```

[![Successful default view](/art/default-redirect-view.png)](/art/default-redirect-view.png)

### Credential-On-File (token) requests

[](#credential-on-file-token-requests)

[Credential-On-File](https://pagosonline.redsys.es/funcionalidades-COF.html) requests uses authorized stored card data to create future requests after an initial one. This is useful for a few use cases like subscriptions with recurring payments or installments for individual payments.

While you can create [Credential-On-File](https://pagosonline.redsys.es/funcionalidades-COF.html) with a [custom Redsys request](#standalone-redsys-requests) as defined on Redsys documentation, this packages provides some helpers to make it easier.

Credential-On-File transactions require an initial request where you ask for a card token. After that, you can create new requests with the card token stored on your application.

#### Prepare your Eloquent model

[](#prepare-your-eloquent-model)

Use the `InteractsWithRedsysCards` concern on the model you want to associate with Redsys card tokens. Typically this model will be `User`, `Team` or `Subscription`, for example.

```
use Creagia\LaravelRedsys\Concerns\InteractsWithRedsysCards;

class Team extends Model
{
    use InteractsWithRedsysCards;

    ...
}
```

#### Initial request

[](#initial-request)

```
use Creagia\Redsys\Enums\CofType;
use Creagia\Redsys\Enums\PayMethod;

/**
 * Use this example to associate the request and card easily to Eloquent models
 */
public function initialRequest()
{
    $redsysRequest = $yourProductModel->createRedsysRequest(
        productDescription: 'Product description',
        payMethod: PayMethod::Card,
    )->requestingCardToken(
        CofType::Recurring
    )->storeCardOnModel(
        $yourPayingModel // User, Team, ...
    );

    return $redsysRequest->redirect();
}

/**
 * Use this example for a custom request, optionally associating the request to Eloquent models
 */
public function initialCustomRequest()
{
    $redsysRequest = RequestBuilder::newRequest(new RequestParameters(
        amountInCents: 19_99,
        currency: Currency::EUR,
        transactionType: TransactionType::Autorizacion,
    ))->associateWithModel(
        $yourProductModel
    )->requestingCardToken(
        CofType::Recurring
    )->storeCardOnModel(
        $yourPayingModel // User, Team, ...
    );
    return $redsysRequest->redirect();
}
```

#### Future requests

[](#future-requests)

```
use Creagia\Redsys\Enums\Currency;
use Creagia\Redsys\Enums\TransactionType;
use Creagia\LaravelRedsys\RequestBuilder;
use Illuminate\Database\Eloquent\Model;
use Creagia\Redsys\Enums\CofType;

public function renewSubscription(Model $yourProductModel, Model $yourPayingModel)
{
    $redsysCard = $yourPayingModel->redsysCards->last();  // User, Team, ...

    $redsysRequest = RequestBuilder::newRequest(new RequestParameters(
        amountInCents: $yourProductModel->getTotalAmount(),
        currency: Currency::EUR,
        transactionType: TransactionType::Autorizacion,
    ))
        ->associateWithModel(
            $yourProductModel
        )->usingCard(
            CofType::Recurring,
            $redsysCard,
        );

    return $redsysRequest->post();
}
```

### Local Gateway

[](#local-gateway)

LaravelRedsys provides a practical local gateway to test your app locally without need to expose it. When your environment config is defined to `local`, your Redsys payments will redirect to your local app instead of the test or production Redsys url.

You'll be able to test authorised and denied payments selected the response code between the available options.

For your security, **this feature is only available if your app is set to local environment too**, apart from the package config.

[![Local gateway screenshot](/art/local-gateway.png)](/art/local-gateway.png)

### Unsuccessful or abandoned payments

[](#unsuccessful-or-abandoned-payments)

Unsuccessful payments won't execute any method, unlike the successful ones.

Users can abandon the payment on the Redsys side, and we wouldn't get notified on that. Because of that, you should take care of pending/cancelled/abandoned payments on your application.

### Events

[](#events)

The package will fire some events you can listen to:

#### RedsysNotificationEvent

[](#redsysnotificationevent)

This event is fired when Redsys tries to notify you with a result from a payment. This event doesn't contain the `RedsysPayment` model because it's fired before processing the request.

The event has one property with the request inputs from Redsys: `$fields`.

#### RedsysSuccessfulEvent

[](#redsyssuccessfulevent)

This event is fired when a successful notification from Redsys is processed.

The event has two properties:

- `$redsysPayment`: the processed `RedsysPayment` model.
- `$notificationData`: array with the successful notification data.

#### RedsysUnsuccessfulEvent

[](#redsysunsuccessfulevent)

This event is fired when an unsuccessful notification from Redsys is processed.

The event has two properties:

- `$redsysPayment`: the processed `RedsysPayment` model.
- `$errorMessage`: string with the error message from Redsys.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [David Torras](https://github.com/dtorras)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance89

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~125 days

Recently: every ~162 days

Total

13

Last Release

64d ago

Major Versions

v1.x-dev → 2.0.02023-05-16

2.x-dev → 3.0.02024-06-02

3.0.3 → 4.0.02026-03-15

PHP version history (2 changes)1.0.0PHP ^8.1

4.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb8d6e5cd2001939a7ab04426d1c21068da6cb9925a6a26aa5aca5b9a1338afa?d=identicon)[creagia](/maintainers/creagia)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (46 commits)")[![dtorras](https://avatars.githubusercontent.com/u/240932?v=4)](https://github.com/dtorras "dtorras (37 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (36 commits)")[![gonbooster](https://avatars.githubusercontent.com/u/22731016?v=4)](https://github.com/gonbooster "gonbooster (1 commits)")

---

Tags

laravelpayment-gatewayredsyssermepaphplaravelredsyspayment gatewaycreagia

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/creagia-laravel-redsys/health.svg)

```
[![Health](https://phpackages.com/badges/creagia-laravel-redsys/health.svg)](https://phpackages.com/packages/creagia-laravel-redsys)
```

###  Alternatives

[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)[creagia/redsys-php

Online payments with Redsys

1837.4k2](/packages/creagia-redsys-php)[danestves/laravel-polar

A package to easily integrate your Laravel application with Polar.sh

7812.3k](/packages/danestves-laravel-polar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
