2013-07-19 127 views
1

與最新的woocommerce版本支付網關集成有問題。 我最近開始使用woocommerce的一個朋友,他有woocommerce版本1.6.5.2。但現在他更新了他的woocommerce到最新版本(2.0.12)。 他有一些定製的支付網關,工作在1.6版本,但現在沒有。 這是自定義的支付網關代碼:Woocommerce支付網關集成

/* 
Plugin Name ...... 
.../* 
$post_perma = trim(esc_url ($_SERVER['REQUEST_URI']), '/'); 
add_action('plugins_loaded', 'woocommerce_rba_etomitreba_init', 0); 
if($post_perma == 'uspjeh'||$post_perma == 'greska') { 
    add_filter('the_content', 'after_processing'); 
} 
function after_processing() { 
    global $post, $post_perma, $woocommerce; 
    if($post_perma == 'uspjeh') { 
     if(isset($_POST['OrderID'])&&isset($_POST['ApprovalCode'])) { 
      echo '<div class="notify notify-success">Not Important;)</div>'; 
      $order = new WC_Order($_POST['OrderID']); 
      $order->payment_complete(); 
      $order->status = 'completed'; 
      $woocommerce->cart->empty_cart(); 
      unset($_SESSION['order_awaiting_payment']); 
     } 
     else { 
      echo '<div class="notify notify-error">Not Important</div>'; 
     } 
    } 
    if($post_perma == 'greska') { 
     echo '<div class="notify notify-error">DNot Important</div>'; 
    } 
} 
function woocommerce_rba_etomitreba_init() { 
    if (!class_exists('WC_Payment_Gateway')) return; 
    class WC_Raiffeisen_Bank_eToMiTreba extends WC_Payment_Gateway { 
     public function __construct() { 
      $this->id = 'rba_etomitreba'; 
      $this->method_title = __('Raiffeisen Bank', 'woocommerce'); 
      $this->icon = apply_filters('woocommerce_cheque_icon', ''); 
      $this->has_fields = false; 

      // Load the form fields. 
      $this->form_fields = array(
       'enabled' => array(
        'title' => __('Not Important', 'woothemes'), 
        'type' => 'checkbox', 
        'label' => __('Not Important', 'woothemes'), 
        'default' => 'yes' 
       ), 
       'merchant-id' => array(
        'title' => __('Not Important', 'woothemes'), 
        'type' => 'text', 
        'description' => __('Not Important', 'woothemes'), 
        'default' => __('', 'woothemes') 
       ), 
       'terminal-id' => array(
        'title' => __('Not Important', 'woothemes'), 
        'type' => 'text', 
        'description' => __('Not Important', 'woothemes'), 
        'default' => __('', 'woothemes') 
       ), 
       'rsa-private-key' => array(
        'title' => __('Not Important', 'woothemes'), 
        'type' => 'textarea', 
        'description' => __('Not Important', 'woothemes'), 
        'default' => __('', 'woothemes') 
       ), 
       'title' => array(
        'title' => __('Not Important', 'woothemes'), 
        'type' => 'text', 
        'description' => __('', 'woothemes'), 
        'default' => __('Not Important', 'woothemes') 
       ), 
       'description' => array(
        'title' => __('Not Important', 'woothemes'), 
        'type' => 'textarea', 
        'description' => __('', 'woothemes'), 
        'default' => 'Not Important.' 
       ) 
      ); 
      // Load the settings. 
      $this->init_settings(); 
      $this->title = $this->settings['title']; 
      $this->description = $this->settings['description']; 

      // Actions 
      add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options')); 
     } 

     public function process_payment($order_id) { 
       $order = new WC_Order($order_id); 
       $order->shipping_first_name; 
       $order->shipping_last_name; 
       $order->get_shipping_address(); 
       $url_gateway = 'Not Important'; 

       $merchant_id = 'xxxxx'; 
       $terminal_id = 'xxxxx'; 
       $total = $order->get_total()*100; // kn to lp conversion 
       $currency_id = 191; 
       $time = new DateTime('', new DateTimeZone('Europe/Zagreb')); 
       $purchase_time = $time->format('ymdHis'); 
       $locale = 'hr'; 
       $ordered_items = $order->get_items(); 
       foreach($ordered_items as $item) { 
        $ordered_items_array[] = $item['name']; 
       } 
       $ordered_items = implode(', ',$ordered_items_array); 
       $purchase_desc = $time->format('d.m.Y. H:i:s').' - '.$order->shipping_first_name.' '.$order->shipping_last_name.' : '.$ordered_items; 
       $session_id = session_id(); 
       $data = "$merchant_id;$terminal_id;$purchase_time;$order_id;$currency_id;$total;$session_id;"; 
       $priv_key = $this->settings['rsa-private-key']; 
       $pkeyid = openssl_get_privatekey($priv_key); 
       openssl_sign($data, $signature, $pkeyid); 
       openssl_free_key($pkeyid); 
       $b64sign = base64_encode($signature); 
       $signature = $b64sign; 

       //$order->update_status('on-hold', __('Not Important', 'woothemes')); 
       echo ' 
      <form name="ordersend" action="'.$url_gateway.'" method="post"> 
       <input name="Version" type="hidden" value="1" > 
       <input name="MerchantID" type="hidden" value="'.$merchant_id.'" > 
       <input name="TerminalID" type="hidden" value="'.$terminal_id.'" > 
       <input name="TotalAmount" type="hidden" value="'.$total.'"> 
       <input name="SD" type="hidden" value="'.$session_id.'"> 
       <input name="Currency" type="hidden" value="'.$currency_id.'" > 
       <input name="Locale" type="hidden" value="'.$locale.'"> 
       <input name="OrderID" type="hidden" value="'.$order_id.'" > 
       <input name="PurchaseTime" type="hidden" value="'.$purchase_time.'"> 
       <input name="PurchaseDesc" type="hidden" value="'.$purchase_desc.'" > 
       <input name="Signature" type="hidden" value="'.$signature.'" > 
      </form> 
      <script language="javascript"> 
      <!-- 
      document.forms["ordersend"].submit(); 
      --></script> 
      '; 

      /* 
      return array (
       'result' => 'success' 
      );*/ 
     } 

     public function admin_options() { 
      ?> 
      <img src="<?php echo 'Not Important ?>" width="664" height="114" /> 
      <h3><?php _e('Not Important', 'woothemes'); ?></h3> 
      <p><?php _e('Not Important'); ?></p> 
      <table class="form-table"> 
      <?php 
       // Generate the HTML For the settings form. 
       $this->generate_settings_html(); 
      ?> 
      </table> 
      <?php 
     } // End admin_options() 
    } 

    function woocommerce_raiffeisen_bank_etomitreba_gateway($methods) { 
     $methods[] = 'WC_Raiffeisen_Bank_eToMiTreba'; 
     return $methods; 
    } 
    add_filter('woocommerce_payment_gateways', 'woocommerce_raiffeisen_bank_etomitreba_gateway'); 
} 

它只是一個兼容性問題,但正如我所說的,我是新來woocommerce與PHP不這麼有經驗。任何幫助將不勝感激。

回答

0

變化

add_action('woocommerce_update_options_payment_gateways', array(&$this, process_admin_options')); 

if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) { 
       add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options')); 
      } else { 
       add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options')); 
      } 
+0

感謝您抽出時間來幫助,但遺憾的是它仍然無法正常工作。我一直在試圖看看你的插件,看看我錯過了什麼,但我似乎無法找到它 – dinca