2017-11-18 201 views
0

我對支付網關集成很陌生。我瞭解到,可以通過編程創建訂單,而無需在woocommerce中添加產品並完成此操作。如何以編程方式在woocommerce中創建訂單並將其重定向到支付網關

現在的問題是,我不知道如何在點擊提交訂單按鈕後自動執行付款流程。

當前訂單表單被提交時,我創建訂單以編程方式進入woocommerce,並期望用戶重定向到選定的(目前默認爲billPlz)付款網關頁面進行付款。

我已經安裝了woocomerce和billPlz支付網關。而WC()->payment_gateways->get_available_payment_gateways()確實會給我返回billPlz。

但是,支付表格並未顯示在支付網關上,以供用戶將付款提交到billPlz。

我看到「成功」的消息,並重定向到mydomain/order-received/72?key=wc_order_5a0f8f3ead251

我想這是感謝頁面?

如何在創建訂單時重定向到支付網關?

訂單形式(我自己的,而不是從woocomerce)

<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="POST"> 
    <input type="text" name="action" value="createOrder"> 
    <input type="text" name="booking_id" value="123"> 
    <input type="text" name="customer_id" value="1006"> 
    <input type="text" name="order_amount" value="180.00"> 
    <input type="text" name="order_status" value="1"> 

    <input type="submit" value="PROCEED TO MAKE PAYMENT"> 
</form> 

創造秩序的功能

public function createOrder() 
    { 

     $product_id = 222; 
     $quantity = 1; 

     $args = array( 
     'variation' => array('attribute_color' => 'red'), 
     'status' => 'complete', 
     'customer_id'=> 23 
     ); 

     $order = wc_create_order(); 
     $order_id = trim(str_replace('#', '', $order->get_order_number())); 


     $order->add_product(get_product($product_id), $quantity, $args); 

     $order->set_status($args['status']); 
     $order->set_customer_id(is_numeric($args['customer_id']) ? absint($args['customer_id']) : 0); 
     $order->set_total(($discount['amount']/100) , 'order_discount'); // not pennies (use dollar amount) 

     update_post_meta($order_id, '_payment_method', 'billplz'); 
     update_post_meta($order_id, '_payment_method_title', 'Billplz Payment Gateway'); 

     $order->calculate_totals(); 


     // Process Payment 
     $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); 

     $result = $available_gateways[ 'billplz' ]->process_payment($order_id); 

     // Redirect to success/confirmation/payment page 
     if ($result['result'] == 'success') { 

      $result = apply_filters('woocommerce_payment_successful_result', $result, $order_id); 
      $return_url = $available_gateways[ 'billplz' ]->get_return_url($order); 

      wp_redirect($return_url); 
      exit; 
     } 
    } 

回答

1

您可以生成未付訂單付款URL像它出現在我的帳戶頁面下通過使用以下命令功能來訂購TAB。

$order->get_checkout_payment_url() 
相關問題