I am creating a module that needs to do a check right before payment is made. If the check fails, it needs to forward the user to the cart with an error.
I have an observer and have verified that it is loading and executing. Right now, I have it hooked into sales_order_payment_place_start.
In the observer function, I have the following code (and only this code for testing):
$url = Mage::getUrl('checkout/cart');//eg to redirect to cart page
$response = Mage::app()->getFrontController()->getResponse();
$response->setRedirect($url);
$response->sendResponse();
exit;
When I get to the final page on check and click the "Place Order" button to submit the order, the button disappears and the "submitting order" message appears and then the button re-appears. If I click it a second time, it forwards to the cart page as expected.
It seems as though the call is ajax'ed, my forward sets a flag, then forwards the ajax request. Upon re-submission the page finds the flag and actually forwards.
That's a guess, but is there any way to accomplish what I am trying to do?
What would be the preferred method of doing this check? Overwriting some controller/model?