2015-05-09 58 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