osCommerce's Checkout Sequence
osCommerce probably has the most illogical checkout system I have seen when it comes to a modular level. Here goes an overlook for osCommerce 2.x:
In checkout_confirmation.php
1. Payment module is initiated
2. Order object initiated
3. Payment module update_status() is executed
4. Payment module pre_confirmation_check() is executed
5. Shipping module initiated
6. Order total modules initiated
7. Order total modules process() is executed
8. Browser output is starting
9. form_action_url is output by payment module
10. Order total modules output() is executed
11. Payment module confirmation() is executed.
12. Payment module process_button() is executed.
In checkout_process.php
13. Payment module is initiated
14. Shipping module initiated
15. Order object initiated
16. Payment module update_status() is executed
17. Order total modules initiated *
18. Payment modulebefore_process() is executed *
19. Order stored into database and an order_id is created
20. Payment moduleafter_process() is executed
* Earlier versions before osCommerce 2.2-RC2a the order total modules where not initiated (step 17) until after payment->before_process(). Making it impossible to validate a payment against the order total before creating the order.
The current model has a lot of disadvantages causing many module makers being forced to tweak the system.
A classic dilemma for payment windows: A form url can only be set in step 11 or 12 since the order total modules must run first (step 7). But the form url is expected in step 9. If an error occurs in step 11 or 12 there is no way to redirect to another page since HTML output started at step 8.
You can't sub methodly preload the order total modules in step 3 or 4 since the class file is not included until step 6. Including it twice leaves an error.
And so on...
My proposal would be to rearrange it into:
(The numbers represent the previous sort order)
2. Order object initiated
1. Payment module is initiated
5. Shipping module initiated
6. Order total modules initiated
3. Payment module update_status() is executed
4. Payment module pre_confirmation_check() is executed
7. Order total modules process() is executed
8. Browser output is starting
10. Order total modules output() is executed
9. form_action_url is output by payment module
11. Payment module confirmation() is executed.
12. Payment module process_button() is executed.
In checkout_process.php
15. Order object initiated
14. Shipping module initiated
13. Payment module is initiated
17. Order total modules initiated *
16. Payment module update_status() is executed
18. Payment module before_process() is executed *
19. Order stored into database and an order_id is created
20. Payment module after_process() is executed