diff --git a/README.md b/README.md
index 46190c0..8118a85 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,9 @@ This wrapper allows you to perform some basic calls to the USPS api. Some of the
- Service Delivery Calculator
- Confirm Tracking
+Be sure to read through the USPS develeloper documentation first!
+* https://www.usps.com/business/web-tools-apis/general-api-developer-guide.htm
+
Requirements
============
@@ -26,6 +29,18 @@ Examples
=======
Please check the 'demos' directory for usage examples on the various types of api calls and actions you can perform.
+To run the demos you'll need to refresh Composer autoloading:
+```
+wget https://getcomposer.org/composer.phar
+php composer.phar dump-autoload
+```
+
+To run via the built-in PHP web server:
+* Run this command from the root directory of this project:
+```
+php -S localhost:8888
+```
+* From your browser: `http://localhost:8888`
Authors
diff --git a/demos/address_verify.php b/demos/address_verify.php
index e40ebd9..08fcd0f 100644
--- a/demos/address_verify.php
+++ b/demos/address_verify.php
@@ -1,12 +1,16 @@
setTestMode(true);
+$verify->setTestMode(true);
// Create new address object and assign the properties
// apartently the order you assign them is important so make sure
diff --git a/demos/citystatelookup.php b/demos/citystatelookup.php
index 3cf178d..5f74b14 100644
--- a/demos/citystatelookup.php
+++ b/demos/citystatelookup.php
@@ -1,12 +1,16 @@
setTestMode(true);
+$verify->setTestMode(true);
// Add the zip code we want to lookup the city and state
$verify->addZipCode('91730');
diff --git a/demos/domestic_rate.php b/demos/domestic_rate.php
index 288bdfc..07002a8 100644
--- a/demos/domestic_rate.php
+++ b/demos/domestic_rate.php
@@ -1,12 +1,16 @@
setTestMode(true);
+$rate->setTestMode(true);
// Create new package object and assign the properties
// apartently the order you assign them is important so make sure
diff --git a/demos/firstclassservicestandard.php b/demos/firstclassservicestandard.php
index c8fd590..887532e 100644
--- a/demos/firstclassservicestandard.php
+++ b/demos/firstclassservicestandard.php
@@ -1,9 +1,12 @@
setTestMode(true);
diff --git a/demos/international_express_label.php b/demos/international_express_label.php
index f391f3e..af6197c 100644
--- a/demos/international_express_label.php
+++ b/demos/international_express_label.php
@@ -1,18 +1,18 @@
setApiVersion('ExpressMailIntl');
-
-// PriorityMailIntl
-$label->setApiVersion('PriorityMailIntl');
-
-// FirstClassMailIntl
-$label->setApiVersion('FirstClassMailIntl');
+$label->setApiVersion($version);
// During test mode this seems not to always work as expected
$label->setTestMode(true);
diff --git a/demos/open_label.php b/demos/open_label.php
index 577d8a0..f81f076 100644
--- a/demos/open_label.php
+++ b/demos/open_label.php
@@ -1,10 +1,17 @@
setTestMode(true);
$label->setFromAddress('John', 'Doe', '', '5161 Lankershim Blvd', 'North Hollywood', 'CA', '91601', '# 204');
$label->setToAddress('Vincent Gabriel', '5440 Tujunga Ave', 'North Hollywood', 'CA', '91601', '707');
diff --git a/demos/priority_label.php b/demos/priority_label.php
index f9686fc..012c3e5 100644
--- a/demos/priority_label.php
+++ b/demos/priority_label.php
@@ -1,9 +1,14 @@
setTestMode(true);
@@ -29,7 +34,7 @@
//echo "\n Confirmation:" . $label->getConfirmationNumber();
$label = $label->getLabelContents();
-
+
if($label) {
$contents = base64_decode($label);
header('Content-type: application/pdf');
diff --git a/demos/servicedeliverycalculator.php b/demos/servicedeliverycalculator.php
index 518e793..392a961 100644
--- a/demos/servicedeliverycalculator.php
+++ b/demos/servicedeliverycalculator.php
@@ -1,9 +1,13 @@
setTestMode(true);
diff --git a/demos/trackconfirm.php b/demos/trackconfirm.php
index 327c6ac..a2a6239 100644
--- a/demos/trackconfirm.php
+++ b/demos/trackconfirm.php
@@ -1,9 +1,13 @@
setTestMode(true);
@@ -22,4 +26,4 @@
echo 'Error: ' . $tracking->getErrorMessage();
}
-?>
\ No newline at end of file
+?>
diff --git a/demos/zipcodelookup.php b/demos/zipcodelookup.php
index f3301cc..57d0c62 100644
--- a/demos/zipcodelookup.php
+++ b/demos/zipcodelookup.php
@@ -1,12 +1,16 @@
setTestMode(true);
+$zipcode->setTestMode(true);
// Create new address object and assign the properties
// apartently the order you assign them is important so make sure
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..f9de65c
--- /dev/null
+++ b/index.php
@@ -0,0 +1,40 @@
+';
+$list = new RecursiveDirectoryIterator(__DIR__ . '/demos');
+foreach ($list as $name => $obj) {
+ $html .= ($obj->isFile())
+ ? '
' . basename($name) . ''
+ : '';
+}
+$html .= '';
+?>
+
+
+
+
+USPS PHP API Test
+
+
+
+
+= $html; ?>
+
+
+
diff --git a/src/USPS/USPSBase.php b/src/USPS/USPSBase.php
index 9bfd323..133b6d4 100644
--- a/src/USPS/USPSBase.php
+++ b/src/USPS/USPSBase.php
@@ -11,13 +11,17 @@
* @author Vincent Gabriel
*/
class USPSBase {
- const LIVE_API_URL = 'http://production.shippingapis.com/ShippingAPI.dll';
- const TEST_API_URL = 'http://production.shippingapis.com/ShippingAPITest.dll';
+ const LIVE_API_URL = 'https://stg-secure.shippingapis.com/shippingapi.dll';
+ const TEST_API_URL = 'https://secure.shippingapis.com/shippingapi.dll';
/**
* @var string - the usps username provided by the usps website
*/
protected $username = '';
+ /**
+ * @var string - the usps password provided by the usps website
+ */
+ protected $password = '';
/**
* the error code if one exists
* @var integer
@@ -94,9 +98,11 @@ class USPSBase {
/**
* Constructor
* @param string $username - the usps api username
+ * @param string $password - the usps api password
*/
- public function __construct($username='') {
+ public function __construct($username='', $password='') {
$this->username = $username;
+ $this->password = $password;
}
/**
* set the usps api username we are going to user
@@ -201,10 +207,15 @@ public function getEndpoint() {
*/
protected function getXMLString() {
// Add in the defaults
- $postFields = array(
- '@attributes' => array('USERID' => $this->username),
- );
-
+ if (!empty($this->password)) {
+ $postFields = array(
+ '@attributes' => array('USERID' => $this->username, 'PASSWORD' => $this->password),
+ );
+ } else {
+ $postFields = array(
+ '@attributes' => array('USERID' => $this->username),
+ );
+ }
// Add in the sub class data
$postFields = array_merge($postFields, $this->getPostFields());
diff --git a/src/USPS/USPSRate.php b/src/USPS/USPSRate.php
index d6bd432..a9cf60e 100644
--- a/src/USPS/USPSRate.php
+++ b/src/USPS/USPSRate.php
@@ -59,149 +59,3 @@ public function addPackage(USPSRatePackage $data, $id=null) {
$this->packages['Package'][] = array_merge(array('@attributes' => array('ID' => $packageId)), $data->getPackageInfo());
}
}
-/**
- * USPS Rate Package
- * used by the ups rate class to create packages represented as objects
- * @since 1.0
- * @author Vincent Gabriel
- */
-class USPSRatePackage extends USPSRate {
- /**
- * @var array - list of all packages added so far
- */
- protected $packageInfo = array();
- /**
- * Services constants
- */
- const SERVICE_FIRST_CLASS = 'FIRST CLASS';
- const SERVICE_FIRST_CLASS_COMMERCIAL = 'FIRST CLASS COMMERCIAL';
- const SERVICE_FIRST_CLASS_HFP_COMMERCIAL = 'FIRST CLASS HFP COMMERCIAL';
- const SERVICE_PRIORITY = 'PRIORITY';
- const SERVICE_PRIORITY_COMMERCIAL = 'PRIORITY COMMERCIAL';
- const SERVICE_PRIORITY_HFP_COMMERCIAL = 'PRIORITY HFP COMMERCIAL';
- const SERVICE_EXPRESS = 'EXPRESS';
- const SERVICE_EXPRESS_COMMERCIAL = 'EXPRESS COMMERCIAL';
- const SERVICE_EXPRESS_SH = 'EXPRESS SH';
- const SERVICE_EXPRESS_SH_COMMERCIAL = 'EXPRESS SH COMMERCIAL';
- const SERVICE_EXPRESS_HFP = 'EXPRESS HFP';
- const SERVICE_EXPRESS_HFP_COMMERCIAL = 'EXPRESS HFP COMMERCIAL';
- const SERVICE_PARCEL = 'PARCEL';
- const SERVICE_MEDIA = 'MEDIA';
- const SERVICE_LIBRARY = 'LIBRARY';
- const SERVICE_ALL = 'ALL';
- const SERVICE_ONLINE = 'ONLINE';
- /**
- * First class mail type
- * required when you use one of the first class services
- */
- const MAIL_TYPE_LETTER = 'LETTER';
- const MAIL_TYPE_FLAT = 'FLAT';
- const MAIL_TYPE_PARCEL = 'PARCEL';
- const MAIL_TYPE_POSTCARD = 'POSTCARD';
- const MAIL_TYPE_PACKAGE_SERVICE = 'PACKAGE SERVICE';
- /**
- * Container constants
- */
- const CONTAINER_VARIABLE = 'VARIABLE';
- const CONTAINER_FLAT_RATE_ENVELOPE = 'FLAT RATE ENVELOPE';
- const CONTAINER_PADDED_FLAT_RATE_ENVELOPE = 'PADDED FLAT RATE ENVELOPE';
- const CONTAINER_LEGAL_FLAT_RATE_ENVELOPE = 'LEGAL FLAT RATE ENVELOPE';
- const CONTAINER_SM_FLAT_RATE_ENVELOPE = 'SM FLAT RATE ENVELOPE';
- const CONTAINER_WINDOW_FLAT_RATE_ENVELOPE = 'WINDOW FLAT RATE ENVELOPE';
- const CONTAINER_GIFT_CARD_FLAT_RATE_ENVELOPE = 'GIFT CARD FLAT RATE ENVELOPE';
- const CONTAINER_FLAT_RATE_BOX = 'FLAT RATE BOX';
- const CONTAINER_SM_FLAT_RATE_BOX = 'SM FLAT RATE BOX';
- const CONTAINER_MD_FLAT_RATE_BOX = 'MD FLAT RATE BOX';
- const CONTAINER_LG_FLAT_RATE_BOX = 'LG FLAT RATE BOX';
- const CONTAINER_REGIONALRATEBOXA = 'REGIONALRATEBOXA';
- const CONTAINER_REGIONALRATEBOXB = 'REGIONALRATEBOXB';
- const CONTAINER_REGIONALRATEBOXC = 'REGIONALRATEBOXC';
- const CONTAINER_RECTANGULAR = 'RECTANGULAR';
- const CONTAINER_NONRECTANGULAR = 'NONRECTANGULAR';
- /**
- * Size constants
- */
- const SIZE_LARGE = 'LARGE';
- const SIZE_REGULAR = 'REGULAR';
- /**
- * Set the service property
- * @param string|int $value
- * @return object USPSRatePackage
- */
- public function setService($value) {
- return $this->setField('Service', $value);
- }
- /**
- * Set the first class mail type property
- * @param string|int $value
- * @return object USPSRatePackage
- */
- public function setFirstClassMailType($value) {
- return $this->setField('FirstClassMailType', $value);
- }
- /**
- * Set the zip origin property
- * @param string|int $value
- * @return object USPSRatePackage
- */
- public function setZipOrigination($value) {
- return $this->setField('ZipOrigination', $value);
- }
- /**
- * Set the zip destination property
- * @param string|int $value
- * @return object USPSRatePackage
- */
- public function setZipDestination($value) {
- return $this->setField('ZipDestination', $value);
- }
- /**
- * Set the pounds property
- * @param string|int $value
- * @return object USPSRatePackage
- */
- public function setPounds($value) {
- return $this->setField('Pounds', $value);
- }
- /**
- * Set the ounces property
- * @param string|int $value
- * @return object USPSRatePackage
- */
- public function setOunces($value) {
- return $this->setField('Ounces', $value);
- }
- /**
- * Set the container property
- * @param string|int $value
- * @return object USPSRatePackage
- */
- public function setContainer($value) {
- return $this->setField('Container', $value);
- }
- /**
- * Set the size property
- * @param string|int $value
- * @return object USPSRatePackage
- */
- public function setSize($value) {
- return $this->setField('Size', $value);
- }
- /**
- * Add an element to the stack
- * @param string|int $key
- * @param string|int $value
- * @return object USPSAddress
- */
- public function setField($key, $value) {
- $this->packageInfo[ ucwords($key) ] = $value;
- return $this;
- }
- /**
- * Returns a list of all the info we gathered so far in the current package object
- * @return array
- */
- public function getPackageInfo() {
- return $this->packageInfo;
- }
-}
diff --git a/src/USPS/USPSRatePackage.php b/src/USPS/USPSRatePackage.php
new file mode 100644
index 0000000..d1bad1c
--- /dev/null
+++ b/src/USPS/USPSRatePackage.php
@@ -0,0 +1,149 @@
+setField('Service', $value);
+ }
+ /**
+ * Set the first class mail type property
+ * @param string|int $value
+ * @return object USPSRatePackage
+ */
+ public function setFirstClassMailType($value) {
+ return $this->setField('FirstClassMailType', $value);
+ }
+ /**
+ * Set the zip origin property
+ * @param string|int $value
+ * @return object USPSRatePackage
+ */
+ public function setZipOrigination($value) {
+ return $this->setField('ZipOrigination', $value);
+ }
+ /**
+ * Set the zip destination property
+ * @param string|int $value
+ * @return object USPSRatePackage
+ */
+ public function setZipDestination($value) {
+ return $this->setField('ZipDestination', $value);
+ }
+ /**
+ * Set the pounds property
+ * @param string|int $value
+ * @return object USPSRatePackage
+ */
+ public function setPounds($value) {
+ return $this->setField('Pounds', $value);
+ }
+ /**
+ * Set the ounces property
+ * @param string|int $value
+ * @return object USPSRatePackage
+ */
+ public function setOunces($value) {
+ return $this->setField('Ounces', $value);
+ }
+ /**
+ * Set the container property
+ * @param string|int $value
+ * @return object USPSRatePackage
+ */
+ public function setContainer($value) {
+ return $this->setField('Container', $value);
+ }
+ /**
+ * Set the size property
+ * @param string|int $value
+ * @return object USPSRatePackage
+ */
+ public function setSize($value) {
+ return $this->setField('Size', $value);
+ }
+ /**
+ * Add an element to the stack
+ * @param string|int $key
+ * @param string|int $value
+ * @return object USPSAddress
+ */
+ public function setField($key, $value) {
+ $this->packageInfo[ ucwords($key) ] = $value;
+ return $this;
+ }
+ /**
+ * Returns a list of all the info we gathered so far in the current package object
+ * @return array
+ */
+ public function getPackageInfo() {
+ return $this->packageInfo;
+ }
+}