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 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?