Zend_Service_StrikeIron | Zend_Service Programmer's Reference Guide | Zend_Service_StrikeIron: Advanced Uses

# Zend_Service_StrikeIron: Bundled Services

Zend_Service_StrikeIron comes with wrapper classes for three popular StrikeIron services.

# ZIP Code Information

Zend_Service_StrikeIron_ZipCodeInfo provides a client for StrikeIron's Zip Code Information Service. For more information on this service, visit these StrikeIron resources:

- » Zip Code Information Service Page

- » Zip Code Information Service WSDL

The service contains a getZipCode() method that will retrieve information about a United States ZIP code or Canadian postal code:

1. $strikeIron = new Zend_Service_StrikeIron( array ('username' => 'your-username',
2. 'password' => 'your-password'));
4. // Get a client for the Zip Code Information service
5. $zipInfo = $strikeIron->getService( array ('class' => 'ZipCodeInfo'));
7. // Get the Zip information for 95014
8. $response = $zipInfo->getZipCode( array ('ZipCode' => 95014));
9. $zips = $response->serviceResult;
11. // Display the results
12. if ($zips->count == 0) {
13. echo 'No results found';
14. } else {
15. // a result with one single zip code is returned as an object,
16. // not an array with one element as one might expect.
17. if (! is_array ($zips->zipCodes)) {
18. $zips->zipCodes = array ($zips->zipCodes);
19. }
21. // print all of the possible results
22. foreach ($zips->zipCodes as $z) {
23. $info = $z->zipCodeInfo;
25. // show all properties
26. print_r ($info);
28. // or just the city name
29. echo $info->preferredCityName;
30. }
31. }
33. // Detailed status information
34. // http://www.strikeiron.com/exampledata/StrikeIronZipCodeInformation_v3.pdf
35. $status = $response->serviceStatus;

# U.S. Address Verification

Zend_Service_StrikeIron_USAddressVerification provides a client for StrikeIron's U.S. Address Verification Service. For more information on this service, visit these StrikeIron resources:

- » U.S. Address Verification Service Page

- » U.S. Address Verification Service WSDL

The service contains a verifyAddressUSA() method that will verify an address in the United States:

1. $strikeIron = new Zend_Service_StrikeIron( array ('username' => 'your-username',
2. 'password' => 'your-password'));
4. // Get a client for the Zip Code Information service
5. $verifier = $strikeIron->getService( array ('class' => 'USAddressVerification'));
7. // Address to verify. Not all fields are required but
8. // supply as many as possible for the best results.
9. $address = array ('firm' => 'Zend Technologies',
10. 'addressLine1' => '19200 Stevens Creek Blvd',
11. 'addressLine2' => '',
12. 'city_state_zip' => 'Cupertino CA 95014');
14. // Verify the address
15. $result = $verifier->verifyAddressUSA($address);
17. // Display the results
18. if ($result->addressErrorNumber != 0) {
19. echo $result->addressErrorNumber;
20. echo $result->addressErrorMessage;
21. } else {
22. // show all properties
23. print_r ($result);
25. // or just the firm name
26. echo $result->firm;
28. // valid address?
29. $valid = ($result->valid == 'VALID');
30. }

# Sales & Use Tax Basic

Zend_Service_StrikeIron_SalesUseTaxBasic provides a client for StrikeIron's Sales & Use Tax Basic service. For more information on this service, visit these StrikeIron resources:

- » Sales & Use Tax Basic Service Page

- » Sales & Use Tax Basic Service WSDL

The service contains two methods, getTaxRateUSA() and getTaxRateCanada(), that will retrieve sales and use tax data for the United States and Canada, respectively.

1. $strikeIron = new Zend_Service_StrikeIron( array ('username' => 'your-username',
2. 'password' => 'your-password'));
4. // Get a client for the Sales & Use Tax Basic service
5. $taxBasic = $strikeIron->getService( array ('class' => 'SalesUseTaxBasic'));
7. // Query tax rate for Ontario, Canada
8. $rateInfo = $taxBasic->getTaxRateCanada( array ('province' => 'foo'));
9. print_r ($rateInfo); // show all properties
10. echo $rateInfo->GST; // or just the GST (Goods & Services Tax)
12. // Query tax rate for Cupertino, CA USA
13. $rateInfo = $taxBasic->getTaxRateUS( array ('zip_code' => 95014));
14. print_r ($rateInfo); // show all properties
15. echo $rateInfo->state_sales_tax; // or just the state sales tax

Zend_Service_StrikeIron | Zend_Service Programmer's Reference Guide | Zend_Service_StrikeIron: Advanced Uses