We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44922
    • 131 Posts
    We're trying to integrate with a payment gateway which requires hidden form input fields sent over POST. It's been suggested that the best way to do this is to output the needed variables as an array along with the <form> markup, redirect to a new page using javascript to create and post the hidden form with the Post data.

    We're doing this in Minishop2, taking a look at the existing Paypal payment files in core/components/minishop2/custom/payment and assets/components/minishop2/payment/. The Paypal integration seems to use Curl to do a lot of the initial verification with Paypal - we're just wanting to pass the parameters to another page to then send data by a form using POST. In the Paypal example we can see the
    	public function send(msOrder $order)
    which generates the order details in a $params variable. $params has the data we need for the form. Any attempt we try to pass those variables to another page to create the javascript form redirect fails. WE can't seem to successfully call these variables. (probably due to out lack of understanding on how these controllers are built, fired and called from the msOrder snippet).

    Any suggestion gratefully received.

    This question has been answered by lancipoos. See the first response.

    • discuss.answer
      • 44922
      • 131 Posts
      So we ended up creating a new handler 'Ourhandler' in manager -> Extras -> Minishop2 settings. We duplicated the Paypal php file and called it the same as our handler 'core/components/minishop2/custom/payment/ourhandler.php'

      Most of the functions copied from the Paypal file we didn't need - we weren't using Curl as the payment provider wanted a browser redirect with hidden form POST fields. So after outputting the needed $params to the array in public function send(msOrder $order), we set session variables:
       $_SESSION['params'] = $params; 
      then returned a redirect to an interim page.

      Here we outputted to a resource firing a snippet to populate the form with hidden form fields and use javascript to auto submit the form with no user input.
      <?php
      $newarray="
      <form id='ourhandler' name='ourhandler' method='post' action='https://sandbox.yourprovider.com/pay'>";
      if(!empty($_SESSION['params'])) {
          
           foreach($_SESSION['params'] as $key=>$value){
             $newarray .= "<input type='hidden' name='". $key. "' value='" . $value . "'>";
          }
      }
          
      $newarray .= '<SCRIPT LANGUAGE="JavaScript"><!--
      setTimeout("document.ourhandler.submit()",300);
      //--></SCRIPT>
      
      </form>';
      
      return  $newarray;