Paritosh
Paritosh

Reputation: 2137

Payment gateway integration - Javascript not working

I am integrating CCAvenue Payment gateway to my code.

echo '<form method="post" name="redirect" action="'.$url.'">';
echo '<input type="hidden" name="encRequest" value="'.$encrypted_data.'">';
echo '<input type="hidden" name="access_code" value="'.$this->access_code.'">';
echo '</form>';
echo '<script language="javascript">document.redirect.submit();</script>';

My page is not redirecting to $url.

I added <INPUT TYPE="submit" value="submit"> to <form>. Now Submit button is visible on the page. Click of submit button redirects me to payment page.

This script auto redirects only on IE 11. It does not work on Chrome, Firefox dev edition.

I tried

  1. Delay (Alert not executing)

    echo '<script language="javascript" type="text/javascript">';
    echo 'function redirectToCC() {document.redirect.submit();alert("hi");};function delay() {setTimeout(redirectToCC, 1000)};delay();';
    echo '</script>';

  2. Change file permissions

I changed this file's permission to 755

  1. jQuery

I added id "btnSubmit" to <INPUT TYPE="submit" value="submit"> in <form>

echo '<script language="javascript">$(document).ready(function(){$("#btnSubmit").click();});</script>';  
echo '<script   src="https://code.jquery.com/jquery-3.1.0.slim.min.js"></script>';
  1. JS click()

    var link = document.getElementById('btnSubmit');link.click();

It seems that javascript is not executing on this page. Any hint / reference?

Upvotes: 1

Views: 872

Answers (1)

Forbs
Forbs

Reputation: 1276

calling via Script language directly is a little iffy due to timing issues. And your JQuery example doesn't have any JQuery, just javascript.

Here's how I would do this (Note that the 'name' is now an 'id')

<html><body onload=document.getElementById('redirect').submit()>
<form id='redirect' action='$url' method='post'>
// Info
</form></body></html>

Then the form will auto submit upon creation. The onload call is only triggered after the complete website loads so you don't have timing issues.

Upvotes: 1

Related Questions