2016-06-21 15 views
0

私はカスタムwoocommerce支払いゲートウェイを作成しました。すべてがスムーズに動作しています。小数点以下2桁に設定しましたが、価格が0で終わるたびにorder_totalは送信時ゲートウェイに。Woocommerceはorder_totalから最後の0を切り捨てています

例:金額が122.98の場合、order_totalは122.98としてゲートウェイに送信されますが、金額が122.80の場合、order_totalは122.8としてゲートウェイに送られ、それは10進数の後に2桁の数字を受け取る必要があるゲートウェイの問題です二重ゼロの場合。しかし、ウェブサイト上で価格がうまく表示されているのは、ゲートウェイに送信されたときに2桁の数字がサイトの表示にうまくいき、0が消えるからです。以下

ゲートウェイコード: /** * **/ 関数get_netcommerce_args($順){ グローバルの$ woocommerceをnetcommerceに渡すためnetcommerceのArgsを取得します。

 $order_id  = $order->id; 
     $currencyUSD ='840'; 
     $order_total = $order->get_total(); 
     $merchantID  = $this->txtMerchNum; 
     $notify_url  = add_query_arg('wc-api', 'wc_tbz_netcommerce_gateway', home_url('/checkout')); 

     $signature_elts =$order_total.$currencyUSD.$order_id.$this->txtMerchNum.$notify_url.$this->sha_key; 
     $signature  =hash('sha256',(string)$signature_elts); 

     // netcommerce Args 
     $netcommerce_args = array(
      'txtIndex'    => $order_id, 
      'txthttp'    => $notify_url, 
      'txtAmount'    => $order_total, 
      'txtCurrency'   => $currencyUSD, 
      'txtMerchNum'   => $this->txtMerchNum, 
      'payment_mode'   => $this->payment_mode, 
      'first_name'   => $order->billing_first_name, 
      'last_name'    => $order->billing_last_name, 
      'email'     => $order->billing_email, 
      'mobile'    => $order->billing_phone, 
      'address_line1'   => $order->billing_address_1, 
      'address_line2'   => $order->billing_address_2, 
      'postal_code'   => $order->billing_postcode, 
      'city'     => $order->billing_city, 
      'state'     => $order->billing_state, 
      'country'    => $order->billing_country, 
      'signature'    => $signature 

     ); 

     $netcommerce_args = apply_filters('woocommerce_netcommerce_args', $netcommerce_args); 
     return $netcommerce_args; 
    } 


    /** 
    * Generate the netcommerce Payment button link 
    **/ 
    function generate_netcommerce_form($order_id) { 
     global $woocommerce; 

     $order = new WC_Order($order_id); 

     $netcommerce_adr = $this->gateway_link; 

     $netcommerce_args = $this->get_netcommerce_args($order); 

     $netcommerce_args_array = array(); 

     foreach ($netcommerce_args as $key => $value) { 
      $netcommerce_args_array[] = '<input type="hidden" name="'.esc_attr($key).'" value="'.esc_attr($value).'" />'; 
     } 

     return '<form action="'.esc_url($netcommerce_adr).'" method="post" id="netcommerce_payment_form" target="_top"> 
       ' . implode('', $netcommerce_args_array) . ' 
       <input type="submit" class="button-alt" id="submit_netcommerce_payment_form" value="'.__('Make Payment', 'woocommerce').'" /> <a class="button cancel" href="'.esc_url($order->get_cancel_order_url()).'">'.__('Cancel order &amp; restore cart', 'woocommerce').'</a> 
      </form>'; 

    } 


    /** 
    * Process the payment and return the result 
    **/ 
    function process_payment($order_id) { 

     $order = new WC_Order($order_id); 
     return array(
      'result' => 'success', 
      'redirect' => $order->get_checkout_payment_url(true) 
     ); 
    } 


    /** 
    * Output for the order received page. 
    **/ 
    function receipt_page($order) { 
     echo '<p>'.__('Thank you for your order, please click the button below to make payment.', 'woocommerce').'</p>'; 
     echo $this->generate_netcommerce_form($order); 
    } 


    /** 
    * Verify a successful Payment! 
    **/ 
    function check_netcommerce_response(){ 
     global $woocommerce; 
     if(isset($_POST['txtIndex'])) 
     { 


      $transaction_id = $_POST['txtIndex']; 
      $order_id  = $_POST['txtIndex']; 


      $order   = new WC_Order($order_id); 
      $order_total = $order->get_total(); 

      $amount_paid = $_POST['txtAmount']; 
      $RespVal  = $_POST['RespVal']; 
      $RespMsg  = $_POST['RespMsg']; 
      $txtMerchNum = $_POST['txtMerchNum']; 
      $txtNumAut  = $_POST['txtNumAut']; 
      $Signature  = $_POST['signature']; 

      $txtCurrency = $_POST['txtCurrency']; 
      $sha=$this->sha_key ; 
      $SignatureElts=$txtMerchNum.$order_id.$amount_paid.$txtCurrency.$txtNumAut.$RespVal.$RespMsg.$sha; 
      $ReturnSignature= hash('sha256',$SignatureElts); 

      if($ReturnSignature != $Signature){ 
      $message1="Signature error" ; 
      if (function_exists('wc_add_notice')) { 
         wc_add_notice($message1, 'error'); 

        } else { // WC < 2.1 
         $woocommerce->add_error($message1); 
         $woocommerce->set_messages(); 
        } 
      } 

ではなく、フロートの小数点以下2桁にパッドを入れられた文字列を取得するために$order_total = number_format($order->get_total(), 2, ".", "")$order_total = $order->get_total();を交換し、あなたに

+0

['number_format'](http://php.net/manual/en/function.number-format.php)には、桁区切り文字として空の文字列を使用します。 –

+0

私はあなたをよく理解していませんでした...ウーコ商業は現場で価格をよく示していて、クライアントや管理者に送られた電子メールでさえ、ゼロで​​あっても小数点以下2桁の価格が含まれています。ゼロが残っている唯一の場所は、最後に0がある場合、その金額がゲートウェイに送信されるときです。 – user3615115

+0

[作業していないコード]を含める必要があります(http:// stackoverflow .com/help/mcve)を使用して問題の解決方法を確認してください。 –

答えて

0

ありがとうございお知らせください。

関連する問題