Redsys
Плагин платёжного провайдера Redsys / Sermepa TPV Virtual для Medusa v2
medusa-payment-redsys
Redsys / Sermepa TPV Virtual payment provider plugin for MedusaJS v2.
This plugin enables payment processing through Redsys' hosted payment page (TPV Virtual) via redirect flow. Customers are redirected to the Redsys secure payment page to complete their transaction.
Production-proven: This plugin is derived from a live production Medusa store processing real Redsys payments.
Features
- Redsys hosted payment page / TPV Virtual redirect flow
- Sandbox and production environments
- One-step payment (immediate capture) and two-step payment (pre-authorization + capture)
- Full and partial refunds via Redsys API
- Payment cancellation
- Webhook handling with HMAC-SHA256 signature verification
- Spanish error messages for Redsys response codes
- Zero PCI scope — card data is handled by Redsys' secure page
Prerequisites
- MedusaJS v2.13.0 or later
- Node.js v20 or later
- A Redsys merchant account (or sandbox test credentials)
- v5.3.0+ (installed automatically as a dependency)
Installation
Configuration
Environment Variables
Add the following to your file:
For sandbox testing, use the following test credentials from Redsys:
Medusa Configuration
In your :
Enable in Region
Enable the Redsys provider in your Medusa admin panel under Settings > Regions and select Redsys as a payment provider.
The provider ID will be:
pp_redsys_redsysOptions
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
| string | Yes | — | Redsys HMAC-SHA256 secret key | |
| string | Yes | — | Redsys merchant code (FUC) | |
| string | No | Terminal number | ||
| string | No | or | ||
| string | No | — | Webhook URL for Redsys to POST transaction results | |
| string | No | — | URL to redirect after successful payment (URLOK) | |
| string | No | — | URL to redirect after failed payment (URLKO) | |
| string | No | = immediate capture, = pre-authorization |
Payment Flow
- Customer selects Redsys as payment method
- creates a signed redirect form with Redsys merchant parameters
- Customer clicks "Place Order" → storefront calls to create the order, then auto-submits the redirect form to Redsys TPV
- Customer completes payment on the Redsys hosted payment page
- Redsys sends a webhook notification to
- validates the HMAC-SHA256 signature and updates the payment status
- Redsys redirects the customer's browser to or
Important: authorizePayment Behavior
This plugin's returns for sessions with status and . This is intentional for the redirect flow: the real authorization happens on Redsys TPV and is confirmed via webhook. Without this, would fail with a 400 error because Medusa requires the payment session to be authorized before completing the cart.
Storefront Integration
Redsys is a redirect-based payment method (no card input in your storefront — the customer enters card data on Redsys' secure TPV). You must adapt your Medusa Next.js storefront with the changes below.
1. — Register the payment method
Add Redsys to the payment info map and add a helper function:
2. — Add order completion without redirect
Add a function. The standard does a (server-side), but Redsys needs to redirect the browser to the TPV instead. This function completes the cart, creates the order, but returns the result so the client can handle the TPV redirect:
3. — Redsys payment button
Add a component that:
- Reads the payment session data (formUrl, merchantParams, signature) from the cart
- Calls to create the order
- Dynamically builds and auto-submits a to Redsys' TPV
4. — Callback page (new file)
Create the page Redsys redirects to after payment. It reads the query param and redirects to the order confirmation page:
5. — Bypass region redirect
If your storefront uses middleware to enforce region/country code prefixes in URLs (as the default Medusa Next.js storefront does), add a bypass so is not redirected. Add this early in the function:
6. — CORS
Ensure your storefront domain is allowed in CORS:
Session Data Reference
The payment session field returned by :
These fields are used in step 3 to build the auto-submitting redirect form.
Webhook
Medusa automatically exposes a webhook endpoint for the Redsys provider at:
/hooks/payment/redsys_redsysFor local development with sandbox, you must expose your backend to the internet (e.g., via ngrok) so Redsys can reach the webhook. Set to the ngrok URL.
Important: Redsys sends the notification to but the signature verification and payment status update happens through the Medusa webhook handler — make sure points to the same endpoint or forward notifications accordingly.
Test Cards (Sandbox)
| Card Number | Brand | Behavior |
|---|---|---|
| 4548810000000003 | VISA | 3DS v2 approved |
| 5576441563045037 | Mastercard | 3DS v2 approved |
| 4548814479727229 | VISA | 3DS frictionless |
| 4548817212493017 | VISA | 3DS challenge |
| Any + CVV 999 | Any | Payment declined |
Transaction Types
| Code | Type | Description |
|---|---|---|
| Payment | Authorization + immediate capture (default) | |
| Pre-authorization | Reserve funds only | |
| Confirmation | Capture pre-authorized funds | |
| Refund | Full or partial refund | |
| Cancellation | Cancel/void a transaction |
Security
- Never log PAN, CVV, or the secret key. The provider strips sensitive fields from log output.
- Always validate signatures server-side. uses 's for HMAC-SHA256 verification.
- Use HTTPS for all communication with Redsys.
- Do not trust client-side payment data. The webhook with signature verification is the source of truth.
- The redirect flow keeps you out of PCI scope — card data is handled by Redsys' secure page.
Currency Support
The plugin includes built-in numeric currency codes for all major currencies. If your currency is not listed, it defaults to EUR (). See for the full list.
Development
Local Testing with a Medusa Project
License
MIT — see LICENSE file for details.
Support
For issues and questions, please open an issue on GitHub.

