I've set up my shop so that I am able to create an entire order programmatically. Line items register fine. However, I can't get fees to stick through the ordering process. I'm using the following code:
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$fee = 'machine_name_of_fee';
commerce_fees_apply($order_wrapper, $fee, 500, 'USD');
commerce_order_save($order);
I then push the order through to checkout so that I can manage it on the backend:
commerce_order_status_update($order, 'checkout_checkout');
I get no errors, but when I check the order in the admin backend, there are no fees that show up. I've double checked that the machine name is correct, and have even confirmed that the commerce fees module returns as 'empty' if the machine name doesn't exist. This leads me to believe that the fees are indeed being added, but that they are being removed at some point after a checkout stage. Is there a specific stage where fees have to be added in order to stick to and affect the order total? Am I implementing commerce_fees_apply() incorrectly?