public function validateAddress(array $street, $state, $suburb, $postcode, $country)
    {
        $address = array(
            'address_line_1' => strtoupper($street[0]),
            'state' => strtoupper($state),
            'suburb' => strtoupper($suburb),
            'postcode' => strtoupper($postcode),
            'country' => strtoupper($country),
        );

        if (count($street) > 1) {
            $address['address_line_2'] = strtoupper($street[1]);
        }

        /** @var $helper Fontis_Australia_Helper_Data */
        $helper = Mage::helper('australia');
        $result = array();
        try {
            $result = $this->client->validateAddress($address);

            $result = $result['ValidateAustralianAddressResponse'];
            $result['success'] = true;

            $result['original'] = $this->_getAddressString(
                trim($address['address_line_1'] . (isset($address['address_line_2']) ? ' ' . $address['address_line_2'] : '')),
                $address['suburb'],
                $address['state'],
                $address['postcode']
            );

            // If the address isn't valid
            if (!$result['ValidAustralianAddress']) {
                return $result;
            }
            // Unset the delivery point identifier as it isn't relevant in this context.
            unset($result['Address']['DeliveryPointIdentifier']);

            $resultAddress = $result['Address'];
            $result['suggestion'] = $this->_getAddressString(
                $resultAddress['AddressLine'],
                $resultAddress['SuburbOrPlaceOrLocality'],
                $resultAddress['StateOrTerritory'],
                $resultAddress['PostCode']
            );

            /** @var $regionModel Mage_Directory_Model_Region */
            $regionModel = Mage::getModel('directory/region')->loadByCode($resultAddress['StateOrTerritory'], $resultAddress['Country']['CountryCode']);
            $regionId = $regionModel->getId();

            $result['suggestedAddress'] = array(
                'street1' => $resultAddress['AddressLine'],
                'city' => $resultAddress['SuburbOrPlaceOrLocality'],
                'regionId' => $regionId,
                'postcode' => $resultAddress['PostCode'],
            );

            // If we have a valid address append it to the response so the JavaScript can act accordingly.
            $result['validAddress'] = $this->_checkAddressValidity($result['original'], $result['suggestion']);
        } catch (BadResponseException $e) {
            $helper->logMessage("An error occurred while contacting the AusPost Delivery Choices API:\n" . $e->getMessage(), Zend_Log::ERR);
            $result['success'] = false;
        } catch (Exception $e) {
            Mage::logException($e);
            $result['success'] = false;
        }

        return $result;
    }
public function validateAddress(array $street, $state, $suburb, $postcode, $country)
    {
        $address = array(
            'address_line_1' => strtoupper($street[0]),
            'state' => strtoupper($state),
            'suburb' => strtoupper($suburb),
            'postcode' => strtoupper($postcode),
            'country' => strtoupper($country),
        );

        if (count($street) > 1) {
            $address['address_line_2'] = strtoupper($street[1]);
        }

        /** @var $helper Fontis_Australia_Helper_Data */
        $helper = Mage::helper('australia');
        $result = array();
        try {
            $result = $this->client->validateAddress($address);

            $result = $result['ValidateAustralianAddressResponse'];
            $result['success'] = true;

            $result['original'] = $this->_getAddressString(
                trim($address['address_line_1'] . (isset($address['address_line_2']) ? ' ' . $address['address_line_2'] : '')),
                $address['suburb'],
                $address['state'],
                $address['postcode']
            );

            // If the address isn't valid
            if (!$result['ValidAustralianAddress']) {
                return $result;
            }
            // Unset the delivery point identifier as it isn't relevant in this context.
            unset($result['Address']['DeliveryPointIdentifier']);

            $resultAddress = $result['Address'];
            $result['suggestion'] = $this->_getAddressString(
                $resultAddress['AddressLine'],
                $resultAddress['SuburbOrPlaceOrLocality'],
                $resultAddress['StateOrTerritory'],
                $resultAddress['PostCode']
            );

            /** @var $regionModel Mage_Directory_Model_Region */
            $regionModel = Mage::getModel('directory/region')->loadByCode($resultAddress['StateOrTerritory'], $resultAddress['Country']['CountryCode']);
            $regionId = $regionModel->getId();

            $result['suggestedAddress'] = array(
                'street1' => $resultAddress['AddressLine'],
                'city' => $resultAddress['SuburbOrPlaceOrLocality'],
                'regionId' => $regionId,
                'postcode' => $resultAddress['PostCode'],
            );

            // If we have a valid address append it to the response so the JavaScript can act accordingly.
            $result['validAddress'] = $this->_checkAddressValidity($result['original'], $result['suggestion']);
        } catch (BadResponseException $e) {
            $helper->logMessage("An error occurred while contacting the AusPost Delivery Choices API:\n" . $e->getMessage(), Zend_Log::ERR);
            $result['success'] = false;
        } catch (Exception $e) {
            Mage::logException($e);
            $result['success'] = false;
        }

        return $result;
    }
public function validateAddress ( array $ street , $ state , $ suburb , $ postcode , $ country ) { $ address = array ( 'address_line_1' => strtoupper ( $ street [ 0 ] ) , 'state' => strtoupper ( $ state ) , 'suburb' => strtoupper ( $ suburb ) , 'postcode' => strtoupper ( $ postcode ) , 'country' => strtoupper ( $ country ) , ) ; if ( count ( $ street ) > 1 ) { $ address [ 'address_line_2' ] = strtoupper ( $ street [ 1 ] ) ; } /** @var $helper Fontis_Australia_Helper_Data */ $ helper = Mage :: helper ( 'australia' ) ; $ result = array ( ) ; try { $ result = $ this -> client -> validateAddress ( $ address ) ; $ result = $ result [ 'ValidateAustralianAddressResponse' ] ; $ result [ 'success' ] = true ; $ result [ 'original' ] = $ this -> _getAddressString ( trim ( $ address [ 'address_line_1' ] . ( isset ( $ address [ 'address_line_2' ] ) ? ' ' . $ address [ 'address_line_2' ] : '' ) ) , $ address [ 'suburb' ] , $ address [ 'state' ] , $ address [ 'postcode' ] ) ; // If the address isn't valid if ( ! $ result [ 'ValidAustralianAddress' ] ) { return $ result ; } // Unset the delivery point identifier as it isn't relevant in this context. unset ( $ result [ 'Address' ] [ 'DeliveryPointIdentifier' ] ) ; $ resultAddress = $ result [ 'Address' ] ; $ result [ 'suggestion' ] = $ this -> _getAddressString ( $ resultAddress [ 'AddressLine' ] , $ resultAddress [ 'SuburbOrPlaceOrLocality' ] , $ resultAddress [ 'StateOrTerritory' ] , $ resultAddress [ 'PostCode' ] ) ; /** @var $regionModel Mage_Directory_Model_Region */ $ regionModel = Mage :: getModel ( 'directory/region' ) -> loadByCode ( $ resultAddress [ 'StateOrTerritory' ] , $ resultAddress [ 'Country' ] [ 'CountryCode' ] ) ; $ regionId = $ regionModel -> getId ( ) ; $ result [ 'suggestedAddress' ] = array ( 'street1' => $ resultAddress [ 'AddressLine' ] , 'city' => $ resultAddress [ 'SuburbOrPlaceOrLocality' ] , 'regionId' => $ regionId , 'postcode' => $ resultAddress [ 'PostCode' ] , ) ; // If we have a valid address append it to the response so the JavaScript can act accordingly. $ result [ 'validAddress' ] = $ this -> _checkAddressValidity ( $ result [ 'original' ] , $ result [ 'suggestion' ] ) ; } catch ( BadResponseException $ e ) { $ helper -> logMessage ( "An error occurred while contacting the AusPost Delivery Choices API:\n" . $ e -> getMessage ( ) , Zend_Log :: ERR ) ; $ result [ 'success' ] = false ; } catch ( Exception $ e ) { Mage :: logException ( $ e ) ; $ result [ 'success' ] = false ; } return $ result ; }
Converts the customer provided address data into an Australia
Post-supported format.

@param array $street Address lines
@param string $state Address state
@param string $suburb Address city / suburb
@param string $postcode Address postcode
@param string $country Address country

@return array
Converts the customer provided address data into an Australia Post - supported format .