dongling2545 2016-07-05 00:00
浏览 125
已采纳

如何从wordpress中的自定义网关中的process_payment函数进行重定向?

I am trying to develop a custom gateway where I need to get order information such as value, credit card number, card owners name, address etc. After getting this, I will send a request using the API provided by Centinel 3D Secure. If successful they will return a url for the credit card bank along with some other information which I am to POST to the bank URL.

The bank will then post data using a form to my callback URL. I can't seem to get it to work however. This is a sample of my code:

function process_payment( $order_id ) {
            global $woocommerce;
            //code to get data using API
            if( (strcasecmp('Y', $_SESSION['Centinel_Enrolled']) == 0){

                 echo '<form action="'.$_SESSION["ACSUrl"].'"" method="post">
                  <input type=hidden name="PaReq" value="'.$_SESSION["RandomValue"].'"/>
                  <input type=hidden name="TermUrl" value="'$myWPCallbackUrl.'?>"/>
                  <input type=hidden name="MD" value="Data"/>
                  <input type="submit" value="Submit" id="submit_centinel_payment_form"/> 
                  <script type="text/javascript">
                  jQuery(function(){ 
                     jQuery("#submit_centinel_payment_form").click();});
                  </script>                 
                  </form>     



            }

This doesn't do a redirect to the server. Does anyone have any idea why this doesn't work?

  • 写回答

2条回答 默认 最新

  • dongnan1899 2016-07-05 04:13
    关注

    using pur javascript you can achieve this goal. Instead of using this code

    <script type="text/javascript">
        jQuery(function(){ 
        jQuery("#submit_centinel_payment_form").click();});
    </script> 
    

    You can use this code

    <script type="text/javascript">
        document.getElementById('paymentForm').submit(); // SUBMIT FORM
    </script>
    

    provided you add an id to your form. You also have syntax error in your form and I would suggest to take out the javascript code outside of form element. You can finally have this code

    echo '<form action="'.$_SESSION["ACSUrl"].'" method="post" id="paymentForm">
                      <input type=hidden name="PaReq" value="'.$_SESSION["RandomValue"].'"/>
                      <input type=hidden name="TermUrl" value="'.$myWPCallbackUrl.'"/>
                      <input type=hidden name="MD" value="Data"/>
                      <input type="submit" value="Submit" id="submit_centinel_payment_form"/> 
    
                      </form>
    <script type="text/javascript">
            document.getElementById("paymentForm").submit(); // SUBMIT FORM
        </script>
    ';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?