2016-07-05 3 views
0

私は値、クレジットカード番号、カード所有者名、住所などの注文情報を取得する必要があるカスタムゲートウェイを開発しようとしています。これを取得した後、Centinel 3D Secureが提供するAPIを使用してリクエストを送信します。もし成功すれば、彼らは私が銀行のURLにPOSTするいくつかの他の情報と一緒にクレジットカード銀行のURLを返します。wordpressのカスタムゲートウェイでprocess_payment関数からリダイレクトを行うにはどうすればよいですか?

銀行は、コールバックURLにフォームを使用してデータを送信します。しかし、私はそれが動作するように見えることはできません。これは私のコードのサンプルです:

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>  



      } 

これはサーバーにリダイレクトしません。なぜこれがうまくいかないのか誰にも分かりますか?

+0

フォーム要素内のjqueryコードの目的は何ですか? –

+0

@amit rayをクリックすることなく自動的にフォームを送信する –

+0

私は答えを提出しました。これがあなたを助けることを願ってください。私が削除した構文エラーがいくつかありました。今すぐチェックすることができます。 –

答えて

0

を使用すると、この目標を達成できます。代わりにこのコード

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

を使用してのあなたは、あなたのフォームにIDを追加提供

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

このコードを使用することができます。 また、フォームに構文エラーがあり、フォーム要素の外でJavaScriptコードを取り出すことをお勧めします。あなたは最終的には、このコード

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> 
'; 
0

これは古い質問があるを持つことができますが、あなたは今、同じ問題に苦しんでのすべてのために、私は私の答えは役立つことを願っています。私はまったく同じ問題を抱えていましたが、これが私が解決した方法です。

このような動作の原因となっているprocess_payment($ order_id)関数のバックグラウンドで何が起こっているのか分かりませんが、関数からのリダイレクトはphp echoやjavascript経由ではできませんが、以下の例のように:だから

function process_payment($order_id) { 
    global $woocommerce; 
    $order = new WC_Order($order_id); 

    // Mark as on-hold (we're awaiting the cheque) 
    $order->update_status('on-hold', __('Awaiting cheque payment', 'woocommerce')); 

    // Reduce stock levels 
    $order->reduce_order_stock(); 

    // Remove cart 
    $woocommerce->cart->empty_cart(); 

    // Return thank you redirect 
    return array(
     'result' => 'success', 
     'redirect' => $this->get_return_url($order) 
    ); 
} 

Wocommerce Payment Gateway APIから貼り付け例)

、特定の問題のために私はsecure_form.php、別のファイルにフォームを置きます。 (パラメータを取得合格することを忘れないでください)

<!DOCTYPE html> 
<html> 
<head> 
    <title>3D Secure Verification</title> 
    <script language="Javascript"> 
     function OnLoadEvent() { document.form.submit(); } 
    </script> 
</head> 
<body OnLoad="OnLoadEvent();"> 
    Invoking 3-D secure form, please wait ... 
    <form name="form" action="<?php echo rawurldecode($_GET[ 'acs_url' ]); ?>" method="post"> 
    <input type="hidden" name="PaReq" value="<?php echo rawurldecode($_GET[ 'pareq' ]); ?>"> 
    <input type="hidden" name="TermUrl" value="<?php echo rawurldecode($_GET[ 'term_url' ]); ?>"> 
    <input type="hidden" name="MD" value="<?php echo rawurldecode($_GET[ 'authencity_token' ]); ?>"> 
    <noscript> 
     <p>Please click</p><input id="to-asc-button" type="submit"> 
    </noscript> 
    </form> 
    </body> 
</html> 

そして、あなたのprocess_payment($ order_id)機能であなたが変数を設定し、フォームを呼び出す:すべての必要なデータは、GETパラメータを経由してアクセスできるようになります

function process_payment($order_id) { 
    global $woocommerce; 
    //code to get data using API 
    if((strcasecmp('Y', $_SESSION['Centinel_Enrolled']) == 0){ 
     // Set variables and redirect to 3DS check form 
     $acs_url   = rawurlencode($_SESSION["ACSUrl"]); 
     $pareq   = rawurlencode($_SESSION["RandomValue"]); 
     $authencity_token = rawurlencode('Data'); 
     $term_url   = rawurlencode($myWPCallbackUrl); 
     $url    = path_to_secure_form.php . "?acs_url=$acs_url&pareq=$pareq&authencity_token=$authencity_token&term_url=$term_url"; 

     return [ 
      'result' => 'success', 
      'redirect' => $url 
     ];   
    } 
} 
関連する問題