'Woo commerce Partials Payments programmatically order save issue

I am working on partials payments by creating order programmatically. I am stuck with the issue when I am doing partials payments of a product in order. I created the order total successfully but woo commerce add remaining amount as a coupons, whereas I did not any coupons.

Here is my Function: public function createNewOrder($order_array){

    $address = array(
        'first_name' => $order_array['first_name'],
        'last_name'  => $order_array['last_name'],
        'company'    => $order_array['company'],
        'email'      => $order_array['email'],
        'phone'      => $order_array['phone'],
        'address_1'  => $order_array['address_1'],
        'address_2'  => $order_array['address_2'],
        'city'       => $order_array['city'],
        'state'      => $order_array['state'],
        'postcode'   => $order_array['postcode'],
        'country'    => $order_array['country']
    );
    
    $args = array(
        'customer_id'   => $order_array['customer_id'],
        'status'        => $order_array['order_status'],
    );
    
    $order = wc_create_order($args);
    $productArray =  json_decode(stripslashes($order_array["productArray"]), true);
    // This is an existing SIMPLE product
    foreach ($productArray as $key => $value) {
        
        $itemData=$value['id'];

        $wc_deposit_enabled = get_post_meta( $itemData, '_wc_deposit_enabled', true );
        $wc_deposit_amount = get_post_meta( $itemData, '_wc_deposit_amount', true );
        $wc_amount = get_post_meta( $itemData,'_price',true );

        if ($wc_deposit_enabled!="") {
            $order->add_product( get_product($itemData), $value['quantity'], array(
                'totals' => array(
                'subtotal'     => $wc_amount, 
                'total'        => $wc_deposit_amount, 
                'subtotal_tax' => 0, 
                'tax'          => 0, 
                )));
           [enter image description here][1]
        }else{
            $order->add_product( get_product($itemData), $value['quantity']);
        }
 
    } 
  
    
     if(!empty($order_array['order_status']))
     {
         $order->update_status($order_array['order_status']);  

     }
     $order->set_address( $address, 'billing' );
    
     
    
     $order->calculate_totals();
     $order->save();

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source