From 7b9bf9490c4fa8717c6c1e7849698bc3271ef5f6 Mon Sep 17 00:00:00 2001 From: Tristan Hall Date: Sat, 13 Mar 2021 09:03:09 -0500 Subject: [PATCH 1/3] Add static property to set the protocol used with the API URLs. Add getProtocol and setProtocol static methods to USPSBase to allow changing the API protocol as needed. Signed-off-by: Tristan Hall --- src/TrackConfirm.php | 2 +- src/USPSBase.php | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/TrackConfirm.php b/src/TrackConfirm.php index 02e3334..a3e58ab 100644 --- a/src/TrackConfirm.php +++ b/src/TrackConfirm.php @@ -18,7 +18,7 @@ class TrackConfirm extends USPSBase public function getEndpoint() { - return self::$testMode ? 'http://production.shippingapis.com/ShippingAPITest.dll' : 'http://production.shippingapis.com/ShippingAPI.dll'; + return sprintf('%s://%s', static::getProtocol(), self::$testMode ? 'production.shippingapis.com/ShippingAPITest.dll' : 'production.shippingapis.com/ShippingAPI.dll'); } /** diff --git a/src/USPSBase.php b/src/USPSBase.php index 71f4d26..62e52b8 100644 --- a/src/USPSBase.php +++ b/src/USPSBase.php @@ -12,8 +12,8 @@ */ abstract class USPSBase { - const LIVE_API_URL = 'https://secure.shippingapis.com/ShippingAPI.dll'; - const TEST_API_URL = 'http://production.shippingapis.com/ShippingAPITest.dll'; + const LIVE_API_URL = 'secure.shippingapis.com/ShippingAPI.dll'; + const TEST_API_URL = 'production.shippingapis.com/ShippingAPITest.dll'; /** * @var string - the usps username provided by the usps website @@ -65,6 +65,10 @@ abstract class USPSBase * @var bool - set whether we are in a test mode or not */ public static $testMode = false; + /** + * @var string - set whether to use HTTP or HTTPS + */ + public static $protocol = 'https'; /** * @var array - different kind of supported api calls by this wrapper */ @@ -223,9 +227,30 @@ protected function doRequest($ch = null) return $this->getResponse(); } + /** + * Return the protocol (HTTP or HTTPS) to use for the API URLs. + * + * @return string + */ + public static function getProtocol() + { + return static::$protocol; + } + + /** + * Set the protocol (HTTP or HTTPS) to use for the API URLs. + * + * @aaram string $protocol + * @return void + */ + public static function setProtocol($protocol) + { + static::$protocol = $protocol; + } + public function getEndpoint() { - return self::$testMode ? self::TEST_API_URL : self::LIVE_API_URL; + return sprintf('%s://%s', static::getProtocol(), self::$testMode ? self::TEST_API_URL : self::LIVE_API_URL); } abstract public function getPostFields(); From 70080725cd189645a1c3d38c22d167fb5afd508a Mon Sep 17 00:00:00 2001 From: Tristan Hall Date: Sat, 13 Mar 2021 14:56:37 -0500 Subject: [PATCH 2/3] Revert "Add static property to set the protocol used with the API URLs." This reverts commit 7b9bf9490c4fa8717c6c1e7849698bc3271ef5f6. --- src/TrackConfirm.php | 2 +- src/USPSBase.php | 31 +++---------------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/TrackConfirm.php b/src/TrackConfirm.php index a3e58ab..02e3334 100644 --- a/src/TrackConfirm.php +++ b/src/TrackConfirm.php @@ -18,7 +18,7 @@ class TrackConfirm extends USPSBase public function getEndpoint() { - return sprintf('%s://%s', static::getProtocol(), self::$testMode ? 'production.shippingapis.com/ShippingAPITest.dll' : 'production.shippingapis.com/ShippingAPI.dll'); + return self::$testMode ? 'http://production.shippingapis.com/ShippingAPITest.dll' : 'http://production.shippingapis.com/ShippingAPI.dll'; } /** diff --git a/src/USPSBase.php b/src/USPSBase.php index 62e52b8..71f4d26 100644 --- a/src/USPSBase.php +++ b/src/USPSBase.php @@ -12,8 +12,8 @@ */ abstract class USPSBase { - const LIVE_API_URL = 'secure.shippingapis.com/ShippingAPI.dll'; - const TEST_API_URL = 'production.shippingapis.com/ShippingAPITest.dll'; + const LIVE_API_URL = 'https://secure.shippingapis.com/ShippingAPI.dll'; + const TEST_API_URL = 'http://production.shippingapis.com/ShippingAPITest.dll'; /** * @var string - the usps username provided by the usps website @@ -65,10 +65,6 @@ abstract class USPSBase * @var bool - set whether we are in a test mode or not */ public static $testMode = false; - /** - * @var string - set whether to use HTTP or HTTPS - */ - public static $protocol = 'https'; /** * @var array - different kind of supported api calls by this wrapper */ @@ -227,30 +223,9 @@ protected function doRequest($ch = null) return $this->getResponse(); } - /** - * Return the protocol (HTTP or HTTPS) to use for the API URLs. - * - * @return string - */ - public static function getProtocol() - { - return static::$protocol; - } - - /** - * Set the protocol (HTTP or HTTPS) to use for the API URLs. - * - * @aaram string $protocol - * @return void - */ - public static function setProtocol($protocol) - { - static::$protocol = $protocol; - } - public function getEndpoint() { - return sprintf('%s://%s', static::getProtocol(), self::$testMode ? self::TEST_API_URL : self::LIVE_API_URL); + return self::$testMode ? self::TEST_API_URL : self::LIVE_API_URL; } abstract public function getPostFields(); From 0955dbad3326ee4b6e804dc4877cf1184fd2bbd7 Mon Sep 17 00:00:00 2001 From: Tristan Hall Date: Sat, 13 Mar 2021 14:57:58 -0500 Subject: [PATCH 3/3] =?UTF-8?q?Replace=20=E2=80=9Chttp=E2=80=9D=20with=20?= =?UTF-8?q?=E2=80=9Chttps=E2=80=9D=20in=20API=20URLs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tristan Hall --- src/TrackConfirm.php | 2 +- src/USPSBase.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TrackConfirm.php b/src/TrackConfirm.php index 02e3334..bebaa59 100644 --- a/src/TrackConfirm.php +++ b/src/TrackConfirm.php @@ -18,7 +18,7 @@ class TrackConfirm extends USPSBase public function getEndpoint() { - return self::$testMode ? 'http://production.shippingapis.com/ShippingAPITest.dll' : 'http://production.shippingapis.com/ShippingAPI.dll'; + return self::$testMode ? 'https://production.shippingapis.com/ShippingAPITest.dll' : 'https://production.shippingapis.com/ShippingAPI.dll'; } /** diff --git a/src/USPSBase.php b/src/USPSBase.php index 71f4d26..9bc8b9a 100644 --- a/src/USPSBase.php +++ b/src/USPSBase.php @@ -13,7 +13,7 @@ abstract class USPSBase { const LIVE_API_URL = 'https://secure.shippingapis.com/ShippingAPI.dll'; - const TEST_API_URL = 'http://production.shippingapis.com/ShippingAPITest.dll'; + const TEST_API_URL = 'https://production.shippingapis.com/ShippingAPITest.dll'; /** * @var string - the usps username provided by the usps website