Открыта бета 1С:ПредприятияОставить заявку
Redsys logo

Redsys

Плагин платёжного провайдера Redsys / Sermepa TPV Virtual для Medusa v2

npm install medusa-payment-redsys
Категория
Создано
Регионы
Сервис
Версия
1.0.2
Последнее обновление
6 месяцев назад
Ежемесячные загрузки
Загрузка данных

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_redsys

Options

OptionTypeRequiredDefaultDescription
stringYes—Redsys HMAC-SHA256 secret key
stringYes—Redsys merchant code (FUC)
stringNoTerminal number
stringNo or
stringNo—Webhook URL for Redsys to POST transaction results
stringNo—URL to redirect after successful payment (URLOK)
stringNo—URL to redirect after failed payment (URLKO)
stringNo = immediate capture, = pre-authorization

Payment Flow

  1. Customer selects Redsys as payment method
  2. creates a signed redirect form with Redsys merchant parameters
  3. Customer clicks "Place Order" → storefront calls to create the order, then auto-submits the redirect form to Redsys TPV
  4. Customer completes payment on the Redsys hosted payment page
  5. Redsys sends a webhook notification to
  6. validates the HMAC-SHA256 signature and updates the payment status
  7. 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:

  1. Reads the payment session data (formUrl, merchantParams, signature) from the cart
  2. Calls to create the order
  3. 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_redsys

For 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 NumberBrandBehavior
4548810000000003VISA3DS v2 approved
5576441563045037Mastercard3DS v2 approved
4548814479727229VISA3DS frictionless
4548817212493017VISA3DS challenge
Any + CVV 999AnyPayment declined

Transaction Types

CodeTypeDescription
PaymentAuthorization + immediate capture (default)
Pre-authorizationReserve funds only
ConfirmationCapture pre-authorized funds
RefundFull or partial refund
CancellationCancel/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.