PHPackages                             creagia/redsys-php - 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/redsys-php

ActiveLibrary[Payment Processing](/categories/payments)

creagia/redsys-php
==================

Online payments with Redsys

3.0.3(1y ago)1847.2k—3%7[1 PRs](https://github.com/creagia/redsys-php/pulls)1MITPHPPHP ^8.1CI passing

Since Jan 25Pushed 1mo ago2 watchersCompare

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

READMEChangelog (8)Dependencies (3)Versions (13)Used By (1)

Online payments with Redsys
===========================

[](#online-payments-with-redsys)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ecb7a0b5be97cbeae4da8525cbd164f695d6295928196f717cdea0d4ef25d3a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f637265616769612f7265647379732d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/creagia/redsys-php)[![Tests](https://github.com/creagia/redsys-php/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/creagia/redsys-php/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/06c012235a2071c381984a20a1a5801b4e2c4adefa24a308ce898f4727942756/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f637265616769612f7265647379732d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/creagia/redsys-php)

Integrate your PHP code with Redsys, the lead payments gateway in Spain.

> If you are using Laravel, check our other package **[creagia/laravel-redsys](https://github.com/creagia/laravel-redsys)** for a ready-to-use integration.

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

[](#installation)

You can install the package via composer:

```
composer require creagia/redsys-php
```

Usage
-----

[](#usage)

This package supports redirection and REST integration methods. You can learn more about the available integration methods on the [official website](https://pagosonline.redsys.es/modelos-de-integracion.html).

- [Creating a request](#create-request)
- [Receive notifications from Redsys](#receive-notifications)
- [Environments](#environments)

### Creating a request

[](#creating-a-request)

```
use Creagia\Redsys\Enums\Currency;
use Creagia\Redsys\Enums\TransactionType;
use Creagia\Redsys\RedsysClient;
use Creagia\Redsys\RedsysRequest;
use Creagia\Redsys\Support\RequestParameters;

$redsysClient = new RedsysClient(
    merchantCode: env('redsys.merchantCode'),
    secretKey: env('redsys.key'),
    terminal: env('redsys.terminal'),
    environment: \Creagia\Redsys\Enums\Environment::Test,
);

$redsysRequest = RedsysRequest::create(
    $redsysClient,
    new RequestParameters(
        amountInCents: 123_45,
        order: '22013100005',
        currency: Currency::EUR,
        transactionType: TransactionType::Autorizacion,
        merchantUrl: 'https://example.com/redsysNotification',
        urlOk: 'https://example.com/paymentOk',
        urlKo: 'https://example.com/paymentKo',
    )
);

echo $redsysRequest->getRedirectFormHtml()
```

First, you need to create a `RedsysClient` with your environment configuration. After that, you should create a `RedsysRequest` using your client and your `RequestParameters`.

Apart from the mandatory fields, you may define any extra optional field (like `merchantUrl` as the notification URL or `urlOk`and `urlKo` to redirect the users after paying) as your `RequestParameters` arguments.

Finally, you can return the redirection form with the `getRedirectFormHtml()`method or send the post request using the `sendPostRequest()`. Read more about those integration methods on the Redsys documentation:

- [Redirection](https://pagosonline.redsys.es/conexion-redireccion.html)
- [REST](https://pagosonline.redsys.es/conexion-rest.html)

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

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

While you can create [Credential-On-File](https://pagosonline.redsys.es/funcionalidades-COF.html) configuring your `RequestParameters` as defined on Redsys documentation, this packages provides some helpers to make it easier.

```
use Creagia\Redsys\RedsysRequest;
use Creagia\Redsys\Support\RequestParameters;
use Creagia\Redsys\Enums\CofType;

$redsysRequest = RedsysRequest::create(
    redsysClient: $redsysClient,
    requestParameters: new RequestParameters(...)
)->requestingCardToken(
    cofType: CofType::Recurring
);

echo $redsysRequest->getRedirectFormHtml()
```

You can also send your request using the REST API as a post request:

```
use Creagia\Redsys\RedsysRequest;
use Creagia\Redsys\Support\RequestParameters;

$redsysRequest = RedsysRequest::create(
    redsysClient: $redsysClient,
    requestParameters: new RequestParameters(...)
)->usingCardToken(
    cofType: CofType::Recurring,
    cofTransactionId: $cofTransactionId,
    merchantIdentifier: $merchantIdentifier,
);

$response = $redsysRequest->sendPostRequest();
```

### Receive notifications from Redsys

[](#receive-notifications-from-redsys)

If you defined the `merchantUrl` parameter during the payment request creation, Redsys will post that URL with the result, so you can execute any actions on an authorised or denied request.

Keep in mind that Redsys won't notify you on abandoned payments so this `merchantUrl` won't be notified for every payment request created. Only when the payment finishes. You should take care of abandoned/pending requests.

```
use Creagia\Redsys\Exceptions\DeniedRedsysPaymentResponseException;
use Creagia\Redsys\RedsysClient;
use Creagia\Redsys\RedsysResponse;

$redsysClient = new RedsysClient(
    merchantCode: env('redsys.merchantCode'),
    secretKey: env('redsys.key'),
    terminal: env('redsys.terminal'),
    environment: \Creagia\Redsys\Enums\Environment::Test,
);

$redsysNotification = new RedsysResponse($redsysClient);
$redsysNotification->setParametersFromResponse($_POST);

// If you need it, prior to checking response, you can use the decoded data from
// Redsys accessing the `NotificationParameters` object on `$redsysNotification->parameters`.

try {
    $notificationData = $redsysNotification->checkResponse();
    // Authorised payment
} catch (DeniedRedsysPaymentResponseException $e) {
    $errorMessage = $e->getMessage();
    // Denied payment with $errorMessage
}
```

### Custom environments

[](#custom-environments)

When creating a `RedsysClient` you may define the right environment for your requests. That environment will be used to send requests to the production or testing Redsys environment.

#### Custom environments

[](#custom-environments-1)

You can define the environment property to `Environment::Custom`. In that case, you will also need to define the `customBaseUrl` propierty.

This feature enables you to use any mock or fake Redsys gateway to test you application locally, for example.

You can find an example on that on our Laravel package [creagia/laravel-redsys](https://github.com/creagia/laravel-redsys), which features a local gateway to test your integration locally.

```
$redsysClient = new RedsysClient(
    merchantCode: env('redsys.merchantCode'),
    secretKey: env('redsys.key'),
    terminal: env('redsys.terminal'),
    environment: \Creagia\Redsys\Enums\Environment::Custom,
    customBaseUrl: 'https://localGateway.test',
);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

Alternatives
------------

[](#alternatives)

- [eusonlito/redsys-TPV](https://github.com/eusonlito/redsys-TPV) PHP &gt;=5.3
- [Official Redsys](https://pagosonline.redsys.es/conexion-redireccion.html)

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

53

—

FairBetter than 96% of packages

Maintenance71

Regular maintenance activity

Popularity41

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity65

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 ~132 days

Recently: every ~103 days

Total

10

Last Release

405d ago

Major Versions

1.x-dev → 2.0.02023-05-16

2.x-dev → 3.0.02024-06-02

### Community

Maintainers

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

---

Top Contributors

[![dtorras](https://avatars.githubusercontent.com/u/240932?v=4)](https://github.com/dtorras "dtorras (41 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (25 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (18 commits)")[![ordago](https://avatars.githubusercontent.com/u/6376814?v=4)](https://github.com/ordago "ordago (3 commits)")[![elpeix](https://avatars.githubusercontent.com/u/5362762?v=4)](https://github.com/elpeix "elpeix (1 commits)")[![glijcom](https://avatars.githubusercontent.com/u/67062223?v=4)](https://github.com/glijcom "glijcom (1 commits)")

---

Tags

payment-gatewayphpredsyssermepaphpredsyspayment gatewaycreagia

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[shetabit/multipay

PHP Payment Gateway Integration Package

293355.3k4](/packages/shetabit-multipay)[creagia/laravel-redsys

Laravel Redsys Payments Gateway

2017.5k](/packages/creagia-laravel-redsys)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

232.5k](/packages/eslazarev-wildberries-sdk)[karson/mpesa-php-sdk

172.4k](/packages/karson-mpesa-php-sdk)

PHPackages © 2026

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