2015-05-09 95 views
1

我試圖爲WooCommerce插件開發自定義支付網關,但我在結帳頁面遇到問題。我想要的是在5秒鐘後自動提交的結帳最後一步頁面上插入一個表單。自定義WooCommerce網關

我的代碼是:

 ... 
    add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page')); 
    add_action('woocommerce_api_wc_' . $this->id, array($this, 'handle_callback')); 
} 

function handle_callback() { 
    wp_die('handle_callback'); 
} 

function receipt_page($order) 
{ 
    echo "receipt page"; 
    $this->generate_submit_form_elements($order); 
} 

的問題是, 「receipt_page」 動作不會被觸發。 謝謝!

+0

確定receipt_page是一個實際的掛鉤。這聽起來不太熟悉。我以爲最後一頁是'woocommerce_thankyou' – helgatheviking

回答

1

哦,它因爲你忘了將has_fields標誌設置爲true。

//after setting the id and method_title, set the has_fields to true 
      $this -> id = 'kiwipay'; 
      $this -> method_title = 'KiwiPay'; 

      $this->has_fields = true; // if you want credit card payment fields to show on the users checkout page 

然後在process_payment功能把這個:

// Payload would look something like this. 
$payload = array(
"amount" => $order.get_total(), 
"reference" => $order->get_order_number(), 
"orderid" => $order->id, 
"return_url" => $this->get_return_url($order) //return to thank you page. 
); 

response = wp_remote_post($environment_url, array(
       'method' => 'POST', 
       'body'  => http_build_query($payload), 
       'timeout' => 90, 
       'sslverify' => false, 
      )); 

// Retrieve the body's response if no errors found 
$response_body = wp_remote_retrieve_body($response); 
$response_headers = wp_remote_retrieve_headers($response); 

//use this if you need to redirect the user to the payment page of the bank. 
$querystring = http_build_query($payload); 

return array(
      'result' => 'success', 
      'redirect' => $environment_url . '?' . $querystring, 
     ); 
+0

確實has_fields國旗是問題。謝謝! – Larry