How to Prevent Orders Based on Shipping Address in Magento

checkoutshippingshipping-address

We're experiencing a high volume of fraud orders with the same city as the shipping address.

If we could block the city, or a list of zip codes we will avoid all this issues.

Is there a way to prevent orders being placed, based on the value of the shipping address?

Best Answer

You can use sales_order_place_before event to stop these zip codes.

In your config (this is part of config.xml)

<config>
    <frontend>
        <events>
            <sales_order_place_before> 
                <observers>
                    <stop_placing_order>
                        <class>your_module/observer</class>
                        <method>stopOrder</method>
                    </stop_placing_order>
                </observers>
            </sales_order_place_before>
        </events>
    </frontend>
</config>

In your observer you can have this function:

public function stopOrder($observer)
{
    $order = $observer->getEvent()->getOrder();
    $address = $order->getShippingAddress();
    $postCode = $address->getPostcode();

    $listOfCodes = array('2144', '456', '555');

    //now your condition
    if(in_array($postCode, $listOfCodes)){
       Mage::getSingleton('checkout/session')->addError('This Postcode is blocked');

       Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
       Mage::app()->getResponse()->sendResponse();
       exit;
    }
}

I haven't tested but this should do the trick for you.