Embedded webform with Redsys payment processor

Created on 15 December 2022, about 2 years ago
Updated 14 February 2023, almost 2 years ago

Problem/Motivation

Redsys payment not working with embedded Webform in a page, either as a paragraph ( https://www.drupal.org/project/paragraphs ) or a block

Steps to reproduce

We are using webform, webform-civicrm modules and Redsys Payment Processor extension (https://civicrm.org/extensions/redsys-payment-processor)
Payment through Redsys works fine when done directly from the webform:


But fails when the webform is embedded in a page:

After submitting the form, the browser shows a white page with no information in the browser inspector and no network activity

Test credentials for Redsys can be found here: https://pagosonline.redsys.es/entornosPruebas.html

🐛 Bug report
Status

Postponed: needs info

Version

6.2

Component

CiviCRM Data Handling

Created by

🇪🇸Spain xavi-xaloc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇪🇸Spain rubofvil

    In the file
    vendor/twig/twig/src/Template.php

    The function `ob_start` is avoding the redirect of the Redsys. The Twig is called to load the node (if the the webform is embeded into a node) after `exit` is called.

    This patch fix the issue, but isn't a good solution. It's to understand the issue

    diff --git a/vendor/twig/twig/src/Template.php b/vendor/twig/twig/src/Template.php
    index 76d55cbcb..daf98c079 100644
    --- a/vendor/twig/twig/src/Template.php
    +++ b/vendor/twig/twig/src/Template.php
    @@ -384,7 +384,12 @@ abstract class Template
             if ($this->env->isDebug()) {
                 ob_start();
             } else {
    -            ob_start(function () { return ''; });
    +            if (!empty($_POST["hidden_processor"]) && $_POST["hidden_processor"] == "1") {
    +                // Avoid executing ob_start allow the processor to continue
    +            } else {
    +                ob_start(function () { return ''; });
    +            }
    +
             }
             try {
                 $this->display($context);
    

    A porpouse is make a development that in some cases the Twig not render a node or panel,....

  • 🇪🇸Spain francescbassas Barcelona

    Thanks @rubofvil.

    This helps us to understand that the reason of get redsys redirection working in local environment is due to having twig debug enabled on services.yml.

    twig.config:
      debug: true
    

    I don't know if this makes sense to you.

  • 🇪🇸Spain francescbassas Barcelona

    @rubofvil I think the solution may be to rewrite current redirect to Redsys https://lab.civicrm.org/extensions/redsys/-/blob/2.4.3/CRM/Core/Payment/... like something as Paypal does https://lab.civicrm.org/dev/core/-/blob/5.57.2/CRM/Core/Payment/PayPalIm....

    This makes sense to you?

  • 🇪🇸Spain rubofvil

    Thx Francesc, but in this case Paypal is redirecting and sending the params with _GET and can use `CRM_Utils_System::redirect`

    But we need to use a post in a form (with method _POST) like in doc "Formulario de envío de petición" (https://pagosonline.redsys.es/conexion-redireccion.html)

    Pd. I tried to manage sending vars via _POST with Curl and a redirect with headers but i din't find a solution with this

  • 🇪🇸Spain xavi-xaloc

    @rubofvil I've tried the proposed patch but it doesn't work for us. We just found the opposite, that redirection works only when ob_start function is executed without callback function, as it is applied when debugging is enabled.
    Anyway, when sending the form, the proposed condition is not matched:

    +            if (!empty($_POST["hidden_processor"]) && $_POST["hidden_processor"] == "1") {
    +                // Avoid executing ob_start allow the processor to continue
    +            } 
    

    So ob_start function with callback function is executed:

    else {
    +                ob_start(function () { return ''; });
    +            }
    
Production build 0.71.5 2024