how to update the order total in checkout page? I'm calculating discount amount base on total order amount. how can I show the discount amount like something what coupon module has done? (see the picture) 



what is the correct way to update the total order amount? I mean how should I subtract the discount amount from the order total so if any products has been removed or added it always works correctly??
You need to use hook_form_alter().

First, for integrity purposes, write a validator that will ensure all amounts are correct, and if not - update them &amp; show form to user again.

Second - use AJAX. Drupal allows only for one callback, so your new one will have to take care of calling the original one in the first place, and you may have some problems if you will need to replace more than one form element, but it can be done.