diff --git a/.gitignore b/.gitignore index a7924c0e..f46d9e7c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ /vendor /htdocs node_modules +devtools_m2/vendor +devtools_m2/devbox.d \ No newline at end of file diff --git a/Api/ProductDetails.php b/Api/ProductDetails.php index f4bebf5c..af0e4c28 100644 --- a/Api/ProductDetails.php +++ b/Api/ProductDetails.php @@ -26,8 +26,8 @@ class ProductDetails protected $responseFactory; /** - * @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable - */ + * @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable + */ protected $configurable; public function __construct( @@ -56,11 +56,10 @@ public function showDetails($productId) $productImage = $product->getImage(); if (!empty($productImage)) { $productImage = $this->catalogProductMediaConfigFactory->create()->getMediaUrl($productImage); - } - else { - if ($product->getTypeId() != 'configurable'){ + } else { + if ($product->getTypeId() != 'configurable') { $parentProductId = $this->getParentId($productId); - if ($parentProductId){ + if ($parentProductId) { $parentProduct = $this->catalogProductFactory->create()->load($parentProductId); $productImage = $parentProduct->getImage(); if (!empty($productImage)) { @@ -84,9 +83,9 @@ public function showDetails($productId) private function getParentId($childId) { $parentConfigObject = $this->configurable->getParentIdsByChild($childId); - if($parentConfigObject) { - return $parentConfigObject[0]; - } - return false; + if ($parentConfigObject) { + return $parentConfigObject[0]; + } + return false; } } diff --git a/CHANGELOG.md b/CHANGELOG.md index f23a9e8f..bb0bde2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ * Add changelog here. +## 2.0.7 + +* Switch to Laminas HTTP Client: Replaced the existing HTTP client with Laminas for better compatibility and maintainability. +* Code Style and Deprecation Fixes: Applied PHP code style improvements and resolved deprecation warnings to align with modern PHP standards. +* Security Enhancement: Updated security settings to allow JavaScript loading from Drip while maintaining application security. + ## 2.0.6 * In extension's endpoint (drip/product/:id) fetch configurable product image url when child products don't have one assigned diff --git a/Model/ApiCalls/Base.php b/Model/ApiCalls/Base.php index 43592303..b16977f9 100644 --- a/Model/ApiCalls/Base.php +++ b/Model/ApiCalls/Base.php @@ -2,7 +2,16 @@ namespace Drip\Connect\Model\ApiCalls; -use \Drip\Connect\Model\Restapi\RestapiAbstract; +use Drip\Connect\Logger\Logger; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\Framework\ArchiveFactory; +use Magento\Framework\Filesystem\DirectoryList; +use Magento\Store\Model\StoreManagerInterface; +use Drip\Connect\Model\Http\ClientFactory; +use Drip\Connect\Model\Configuration; +use Laminas\Http\Response; +use Laminas\Http\Client\Exception\ExceptionInterface; /** * Restapi base class @@ -11,16 +20,16 @@ class Base extends RestapiAbstract { /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ protected $scopeConfig; /** - * @var \Drip\Connect\Model\Http\ClientFactory + * @var ClientFactory */ protected $connectHttpClientFactory; - /** @var \Magento\Store\Model\StoreManagerInterface */ + /** @var StoreManagerInterface */ protected $storeManager; /** @@ -37,14 +46,14 @@ class Base extends RestapiAbstract * @param String $v3 API version */ public function __construct( - \Drip\Connect\Logger\Logger $logger, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, - \Magento\Framework\ArchiveFactory $archiveFactory, - \Magento\Framework\Filesystem\DirectoryList $directory, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Drip\Connect\Model\Http\ClientFactory $connectHttpClientFactory, - \Drip\Connect\Model\Configuration $config, + Logger $logger, + ScopeConfigInterface $scopeConfig, + WriterInterface $configWriter, + ArchiveFactory $archiveFactory, + DirectoryList $directory, + StoreManagerInterface $storeManager, + ClientFactory $connectHttpClientFactory, + Configuration $config, $endpoint, $v3 = false ) { @@ -55,9 +64,9 @@ public function __construct( $archiveFactory, $directory ); - /* + /* * Since the Drip extension is sending data through the WooBase class - * we are clearing this to prevent issues in other parts of the codebase. + * we are clearing this to prevent issues in other parts of the codebase. */ } @@ -65,7 +74,7 @@ public function __construct( * Call the API * * @param \Drip\Connect\Model\Restapi\Request $request - * @throws \Zend_Http_Client_Exception + * @throws ExceptionInterface */ protected function _callApi($request) { @@ -76,39 +85,51 @@ protected function _callApi($request) $this->_httpClient->setParameterPost($request->getParametersPost()); } if (!empty($request->getRawData())) { - $this->_httpClient->setRawData($request->getRawData()); + $this->_httpClient->setRawBody($request->getRawData()); } $response = $this->_httpClient->request($request->getMethod()); $this->_lastRequestUrl = $this->_httpClient->getUri(); - $this->_lastRequest = $this->_httpClient->getLastRequest(); + $this->_lastRequest = $this->_httpClient->getRequest(); return $response; } protected function _forceValidResponse($request) { - return new \Zend_Http_Response(200, ["Content-type" => "application/json; charset=utf-8"], json_encode([ + $response = new Response(); + $response->setStatusCode(200); + $response->getHeaders()->addHeaderLine("Content-Type", "application/json; charset=utf-8"); + $response->setContent(json_encode([ "Status" => "OK", "Message" => "Forced Valid Response" ])); + return $response; } protected function _forceInvalidResponse($request) { - return new \Zend_Http_Response(200, ["Content-type" => "application/json; charset=utf-8"], json_encode([ + $response = new Response(); + $response->setStatusCode(200); + $response->getHeaders()->addHeaderLine("Content-Type", "application/json; charset=utf-8"); + $response->setContent(json_encode([ "Status" => "OK", "Message" => "Forced Invalid Response" ])); + return $response; } protected function _forceError($request) { - return new \Zend_Http_Response(500, ["Content-type" => "application/json; charset=utf-8"], json_encode([ + $response = new Response(); + $response->setStatusCode(500); + $response->getHeaders()->addHeaderLine("Content-Type", "application/json; charset=utf-8"); + $response->setContent(json_encode([ "Status" => "Error", "Message" => "Forced Error Message" ])); + return $response; } /** diff --git a/Model/ApiCalls/Helper/CreateUpdateSubscriber.php b/Model/ApiCalls/Helper/CreateUpdateSubscriber.php index 31bbec1f..f4fea93e 100644 --- a/Model/ApiCalls/Helper/CreateUpdateSubscriber.php +++ b/Model/ApiCalls/Helper/CreateUpdateSubscriber.php @@ -2,15 +2,20 @@ namespace Drip\Connect\Model\ApiCalls\Helper; +use \Drip\Connect\Model\ApiCalls\BaseFactory; +use \Drip\Connect\Model\ApiCalls\Request\BaseFactory as RequestBaseFactory; +use \Drip\Connect\Model\Configuration; +use \Laminas\Http\Request; + /** * Create or update a subscriber. */ class CreateUpdateSubscriber extends \Drip\Connect\Model\ApiCalls\Helper { public function __construct( - \Drip\Connect\Model\ApiCalls\BaseFactory $connectApiCallsBaseFactory, - \Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory, - \Drip\Connect\Model\Configuration $config, + BaseFactory $connectApiCallsBaseFactory, + RequestBaseFactory $connectApiCallsRequestBaseFactory, + Configuration $config, $data = [] ) { $this->apiClient = $connectApiCallsBaseFactory->create([ @@ -25,7 +30,7 @@ public function __construct( ]; $this->request = $connectApiCallsRequestBaseFactory->create() - ->setMethod(\Zend_Http_Client::POST) + ->setMethod(Request::METHOD_POST) ->setRawData(json_encode($subscribersInfo)); } } diff --git a/Model/ApiCalls/Helper/GetProjectList.php b/Model/ApiCalls/Helper/GetProjectList.php index 18f93101..2fcdb00b 100644 --- a/Model/ApiCalls/Helper/GetProjectList.php +++ b/Model/ApiCalls/Helper/GetProjectList.php @@ -2,17 +2,25 @@ namespace Drip\Connect\Model\ApiCalls\Helper; +use Drip\Connect\Model\ApiCalls\BaseFactory; +use Drip\Connect\Model\ApiCalls\Request\BaseFactory as RequestBaseFactory; +use Drip\Connect\Model\Configuration; +use Laminas\Http\Request; + /** * Get project list helper * * @todo This class doesn't seem to be called from anywhere. Confirm that it is dead. */ -class GetProjectList extends \Drip\Connect\Model\ApiCalls\Helper +class GetProjectList extends Helper { + protected $apiClient; + protected $request; + public function __construct( - \Drip\Connect\Model\ApiCalls\BaseFactory $connectApiCallsBaseFactory, - \Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory, - \Drip\Connect\Model\Configuration $config, + BaseFactory $connectApiCallsBaseFactory, + RequestBaseFactory $connectApiCallsRequestBaseFactory, + Configuration $config, $data = [] ) { $this->apiClient = $connectApiCallsBaseFactory->create([ @@ -21,6 +29,6 @@ public function __construct( ]); $this->request = $connectApiCallsRequestBaseFactory->create() - ->setMethod(\Zend_Http_Client::GET); + ->setMethod(Request::METHOD_GET); } } diff --git a/Model/ApiCalls/Helper/GetSubscriberList.php b/Model/ApiCalls/Helper/GetSubscriberList.php index 1db07590..0bc87aba 100644 --- a/Model/ApiCalls/Helper/GetSubscriberList.php +++ b/Model/ApiCalls/Helper/GetSubscriberList.php @@ -2,6 +2,11 @@ namespace Drip\Connect\Model\ApiCalls\Helper; +use Drip\Connect\Model\ApiCalls\BaseFactory; +use Drip\Connect\Model\ApiCalls\Request\BaseFactory as RequestBaseFactory; +use Drip\Connect\Model\Configuration; +use Laminas\Http\Request; + /** * Get the subscriber list * @@ -9,10 +14,13 @@ */ class GetSubscriberList extends \Drip\Connect\Model\ApiCalls\Helper { + protected $apiClient; + protected $request; + public function __construct( - \Drip\Connect\Model\ApiCalls\BaseFactory $connectApiCallsBaseFactory, - \Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory, - \Drip\Connect\Model\Configuration $config, + BaseFactory $connectApiCallsBaseFactory, + RequestBaseFactory $connectApiCallsRequestBaseFactory, + Configuration $config, $data = [] ) { $data = array_merge([ @@ -30,7 +38,7 @@ public function __construct( ]); $this->request = $connectApiCallsRequestBaseFactory->create() - ->setMethod(\Zend_Http_Client::GET) + ->setMethod(Request::METHOD_GET) ->setParametersGet([ 'status' => $data['status'], 'tags' => $data['tags'], diff --git a/Model/ApiCalls/Helper/RecordAnEvent.php b/Model/ApiCalls/Helper/RecordAnEvent.php index 87eed07f..c498eeab 100644 --- a/Model/ApiCalls/Helper/RecordAnEvent.php +++ b/Model/ApiCalls/Helper/RecordAnEvent.php @@ -2,6 +2,12 @@ namespace Drip\Connect\Model\ApiCalls\Helper; +use Drip\Connect\Model\ApiCalls\BaseFactory; +use Drip\Connect\Model\ApiCalls\Request\BaseFactory as RequestBaseFactory; +use Drip\Connect\Helper\Data; +use Drip\Connect\Model\Configuration; +use Laminas\Http\Request; + /** * Record a subscriber event */ @@ -19,10 +25,10 @@ class RecordAnEvent extends \Drip\Connect\Model\ApiCalls\Helper const EVENT_WISHLIST_REMOVE_PRODUCT = 'Removed item from wishlist'; public function __construct( - \Drip\Connect\Model\ApiCalls\BaseFactory $connectApiCallsBaseFactory, - \Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory, - \Drip\Connect\Helper\Data $connectHelper, - \Drip\Connect\Model\Configuration $config, + BaseFactory $connectApiCallsBaseFactory, + RequestBaseFactory $connectApiCallsRequestBaseFactory, + Data $connectHelper, + Configuration $config, array $data ) { $this->apiClient = $connectApiCallsBaseFactory->create([ @@ -43,7 +49,7 @@ public function __construct( ]; $this->request = $connectApiCallsRequestBaseFactory->create() - ->setMethod(\Zend_Http_Client::POST) + ->setMethod(Request::METHOD_POST) ->setRawData(json_encode($eventsInfo)); } } diff --git a/Model/ApiCalls/Helper/SendEventPayload.php b/Model/ApiCalls/Helper/SendEventPayload.php index 65df61d5..25cb4b26 100644 --- a/Model/ApiCalls/Helper/SendEventPayload.php +++ b/Model/ApiCalls/Helper/SendEventPayload.php @@ -2,18 +2,23 @@ namespace Drip\Connect\Model\ApiCalls\Helper; +use Drip\Connect\Model\ApiCalls\WooBaseFactory; +use Drip\Connect\Model\ApiCalls\Request\BaseFactory; +use Drip\Connect\Model\Configuration; +use Laminas\Http\Request; + /** * Send payload for events */ class SendEventPayload extends \Drip\Connect\Model\ApiCalls\Helper { - /** @var \Drip\Connect\Model\Configuration */ + /** @var Configuration */ protected $config; public function __construct( - \Drip\Connect\Model\ApiCalls\WooBaseFactory $connectApiCallsWooBaseFactory, - \Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory, - \Drip\Connect\Model\Configuration $config, + WooBaseFactory $connectApiCallsWooBaseFactory, + BaseFactory $connectApiCallsRequestBaseFactory, + Configuration $config, array $payload ) { $this->config = $config; @@ -24,7 +29,7 @@ public function __construct( ]); $this->request = $connectApiCallsRequestBaseFactory->create() - ->setMethod(\Zend_Http_Client::POST) + ->setMethod(Request::METHOD_POST) ->setRawData(json_encode($payload)); } @@ -33,11 +38,12 @@ private function integrationUrl() $accountId = $this->config->getAccountParam(); $integrationParam = $this->config->getIntegrationToken(); $endpoint = "https://external-production.woo.drip.sh"; + # $endpoint = "https://external-staging.woo.drip.sh"; if ($this->config->getTestMode()) { $endpoint = "http://mock:1080"; } - return "${endpoint}/${accountId}/integrations/${integrationParam}/events"; + return "{$endpoint}/{$accountId}/integrations/{$integrationParam}/events"; } } diff --git a/Model/ApiCalls/Request/Base.php b/Model/ApiCalls/Request/Base.php index 67c6dd67..e1b37357 100644 --- a/Model/ApiCalls/Request/Base.php +++ b/Model/ApiCalls/Request/Base.php @@ -1,6 +1,7 @@ _httpClient->setParameterPost($request->getParametersPost()); } if (!empty($request->getRawData())) { - $this->_httpClient->setRawData($request->getRawData()); + $this->_httpClient->setRawBody($request->getRawData()); } $response = $this->_httpClient->request($request->getMethod()); $this->_lastRequestUrl = $this->_httpClient->getUri(); - $this->_lastRequest = $this->_httpClient->getLastRequest(); + $this->_lastRequest = $this->_httpClient->getRequest(); return $response; } protected function _forceValidResponse($request) { - return new \Zend_Http_Response(200, ["Content-type" => "application/json; charset=utf-8"], json_encode([ + return $this->_createResponse(200, [ "Status" => "OK", "Message" => "Forced Valid Response" - ])); + ]); } - + protected function _forceInvalidResponse($request) { - return new \Zend_Http_Response(200, ["Content-type" => "application/json; charset=utf-8"], json_encode([ + return $this->_createResponse(200, [ "Status" => "OK", "Message" => "Forced Invalid Response" - ])); + ]); } - + protected function _forceError($request) { - return new \Zend_Http_Response(500, ["Content-type" => "application/json; charset=utf-8"], json_encode([ + return $this->_createResponse(500, [ "Status" => "Error", "Message" => "Forced Error Message" - ])); + ]); + } + + private function _createResponse($statusCode, array $data) + { + $response = new Response(); + $response->setStatusCode($statusCode); + $response->getHeaders()->addHeaderLine("Content-Type", "application/json; charset=utf-8"); + $response->setContent(json_encode($data)); + return $response; } /** diff --git a/Model/Configuration.php b/Model/Configuration.php index 35bc43a9..ab13c2fd 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -2,6 +2,11 @@ namespace Drip\Connect\Model; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Store\Model\ScopeInterface; + /** * Scoped configuration */ @@ -15,17 +20,17 @@ class Configuration const LOG_SETTINGS_PATH = 'dripconnect_general/log_settings'; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @var ScopeConfigInterface $scopeConfig */ protected $scopeConfig; /** - * @var \Magento\Framework\App\Config\Storage\WriterInterface $configWriter + * @var WriterInterface $configWriter */ protected $configWriter; /** - * @var \Magento\Store\Model\StoreManagerInterface $storeManager + * @var StoreManagerInterface $storeManager */ protected $storeManager; @@ -40,15 +45,15 @@ class Configuration protected $scope; /** - * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Store\Model\StoreManagerInterface $storeManager, + * @param WriterInterface $configWriter, + * @param ScopeConfigInterface $scopeConfig + * @param StoreManagerInterface $storeManager, * @param int $websiteId The ID of the Website */ public function __construct( - \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Store\Model\StoreManagerInterface $storeManager, + WriterInterface $configWriter, + ScopeConfigInterface $scopeConfig, + StoreManagerInterface $storeManager, int $websiteId ) { $this->configWriter = $configWriter; @@ -57,9 +62,9 @@ public function __construct( $this->websiteId = $websiteId; if ($this->websiteId == 0) { - $this->scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT; + $this->scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT; } else { - $this->scope = \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES; + $this->scope = ScopeInterface::SCOPE_WEBSITES; } } diff --git a/Model/Http/Client.php b/Model/Http/Client.php index b3c90bd1..f9123d99 100644 --- a/Model/Http/Client.php +++ b/Model/Http/Client.php @@ -2,10 +2,12 @@ namespace Drip\Connect\Model\Http; +use Laminas\Http\Client as LaminasHttpClient; + /** * Rest client */ -class Client extends \Zend_Http_Client +class Client extends LaminasHttpClient { /** @var \Monolog\Logger */ protected $logger; @@ -28,28 +30,30 @@ public function __construct( * Send the HTTP request and return an HTTP response object * * @param string $method - * @return \Zend_Http_Response - * @throws \Zend_Http_Client_Exception + * @return \Laminas\Http\Response + * @throws \Laminas\Http\Client\Exception\ExceptionInterface */ public function request($method = null) { // ID unique to each outgoing API request. - $requestId = uniqid(); - $this->setHeaders('X-Drip-Connect-Request-Id', $requestId); - // ID unique to each triggering Magento page load. Useful for // debouncing multiple events within a single Magento request. - $magentoRequestId = $this->requestIdFactory->create()->requestId(); - $this->setHeaders('X-OMS-Request-Id', $magentoRequestId); + $headers = [ + 'X-Drip-Connect-Request-Id' => uniqid(), + 'X-OMS-Request-Id' => $this->requestIdFactory->create()->requestId(), + ]; + + $this->setHeaders($headers); + $this->setMethod($method); - $requestBody = $this->_prepareBody(); - $requestUrl = $this->getUri(true); - $response = parent::request($method); + $requestBody = $this->getRequest()->getContent(); + $requestUrl = $this->getUri()->toString(); + $response = $this->send(); $responseData = $response->getBody(); - $this->logger->info("[{$requestId}] Request Url: {$requestUrl}"); - $this->logger->info("[{$requestId}] Request Body: {$requestBody}"); - $this->logger->info("[{$requestId}] Response: {$responseData}"); + $this->logger->info("[{$headers['X-Drip-Connect-Request-Id']}] Request Url: {$requestUrl}"); + $this->logger->info("[{$headers['X-Drip-Connect-Request-Id']}] Request Body: {$requestBody}"); + $this->logger->info("[{$headers['X-Drip-Connect-Request-Id']}] Response: {$responseData}"); return $response; } diff --git a/Model/Restapi/Response/ResponseAbstract.php b/Model/Restapi/Response/ResponseAbstract.php index be820fa3..d5b837fc 100644 --- a/Model/Restapi/Response/ResponseAbstract.php +++ b/Model/Restapi/Response/ResponseAbstract.php @@ -2,13 +2,15 @@ namespace Drip\Connect\Model\Restapi\Response; +use Laminas\Http\Response as LaminasResponse; + /** * Abstract base class for responses. */ class ResponseAbstract { /** - * @var \Zend_Http_Response Response as received from API + * @var \Laminas\Http\Response Response as received from API */ protected $_response; @@ -19,22 +21,22 @@ class ResponseAbstract protected $_errorMessage = null; /** - * @param \Zend_Http_Response $response + * @param LaminasResponse $response * @param string $errorMessage */ - public function __construct(\Zend_Http_Response $rawResponse = null, $errorMessage) + public function __construct(LaminasResponse $rawResponse = null, $errorMessage) { if ($errorMessage) { $this->_setError($errorMessage); } else { - $this->_response = $rawResponse; + $this->_response = $rawResponse ?: new LaminasResponse(); } } /** - * Gets the Zend_Http_Response object + * Gets the \Laminas\Http\Response object * - * @return \Zend_Http_Response + * @return LaminasResponse */ public function getResponse() { diff --git a/Model/Restapi/Response/ResponseInterface.php b/Model/Restapi/Response/ResponseInterface.php index 5caf4194..2c221fe2 100644 --- a/Model/Restapi/Response/ResponseInterface.php +++ b/Model/Restapi/Response/ResponseInterface.php @@ -12,7 +12,7 @@ public function toJson(); /** * Gets the response * - * @return \Zend_Http_Response + * @return \Laminas\Http\Response */ public function getResponse(); diff --git a/Model/Restapi/RestapiAbstract.php b/Model/Restapi/RestapiAbstract.php index a682ecd6..4183869a 100644 --- a/Model/Restapi/RestapiAbstract.php +++ b/Model/Restapi/RestapiAbstract.php @@ -2,6 +2,13 @@ namespace Drip\Connect\Model\Restapi; +use Laminas\Http\Response; +use Drip\Connect\Logger\Logger; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\Framework\ArchiveFactory; +use Magento\Framework\Filesystem\DirectoryList; + abstract class RestapiAbstract { const USERAGENT = 'Drip Connect M2'; @@ -9,7 +16,7 @@ abstract class RestapiAbstract /** @var string */ protected $_responseModel; - /** @var \Zend_Http_Client */ + /** @var \Laminas\Http\Client */ protected $_httpClient; /** @var string */ @@ -18,33 +25,33 @@ abstract class RestapiAbstract /** @var string */ protected $_lastRequest; - /** @var \Zend_Http_Response */ + /** @var \Laminas\Http\Response */ protected $_lastResponse; - /** @var \Drip\Connect\Logger\Logger */ + /** @var Logger */ protected $logger; - /** @var \Magento\Framework\App\Config\ScopeConfigInterface */ + /** @var ScopeConfigInterface */ protected $scopeConfig; - /** @var \Magento\Framework\Filesystem\DirectoryList */ + /** @var DirectoryList */ protected $directory; - /** @var \Magento\Framework\ArchiveFactory */ + /** @var ArchiveFactory */ protected $archiveFactory; - /** @var \Magento\Framework\App\Config\Storage\WriterInterface */ + /** @var WriterInterface */ protected $configWriter; /** @var int */ protected $storeId = 0; public function __construct( - \Drip\Connect\Logger\Logger $logger, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, - \Magento\Framework\ArchiveFactory $archiveFactory, - \Magento\Framework\Filesystem\DirectoryList $directory + Logger $logger, + ScopeConfigInterface $scopeConfig, + WriterInterface $configWriter, + ArchiveFactory $archiveFactory, + DirectoryList $directory ) { $this->archiveFactory = $archiveFactory; $this->logger = $logger; @@ -98,7 +105,7 @@ public function getLastRequest() } /** - * @return \Zend_Http_Response + * @return \Laminas\Http\Response */ public function getLastResponse() { @@ -117,7 +124,7 @@ protected function setStoreId(int $storeId) * Call the API * * @param $request - * @throws \Zend_Http_Client_Exception + * @throws \Laminas\Http\Client\Exception\ExceptionInterface */ abstract protected function _callApi($request); @@ -125,7 +132,7 @@ abstract protected function _callApi($request); * Force a valid response * * @param $request - * @throws \Zend_Http_Client_Exception + * @throws \Laminas\Http\Client\Exception\ExceptionInterface */ abstract protected function _forceValidResponse($request); @@ -133,7 +140,7 @@ abstract protected function _forceValidResponse($request); * Force an invalid response * * @param $request - * @throws \Zend_Http_Client_Exception + * @throws \Laminas\Http\Client\Exception\ExceptionInterface */ abstract protected function _forceInvalidResponse($request); @@ -141,7 +148,7 @@ abstract protected function _forceInvalidResponse($request); * Force an error * * @param $request - * @throws \Zend_Http_Client_Exception + * @throws \Laminas\Http\Client\Exception\ExceptionInterface */ abstract protected function _forceError($request); @@ -149,7 +156,7 @@ abstract protected function _forceError($request); * Force a timeout * * @param $request - * @throws \Zend_Http_Client_Exception + * @throws \Laminas\Http\Client\Exception\ExceptionInterface */ protected function _forceTimeout($request) { @@ -163,13 +170,19 @@ protected function _forceTimeout($request) * This is a malformed or unexpected response from the API. * * @param $request - * @return \Zend_Http_Response + * @return \Laminas\Http\Response */ protected function _forceUnknownResponse($request) { $httpStatusCode = 200; $headers = []; $responseBody = "This is an unknown response."; - return new \Zend_Http_Response($httpStatusCode, $headers, $responseBody); + + $response = new Response(); + $response->setStatusCode($httpStatusCode); + $response->getHeaders()->addHeaders($headers); + $response->setContent($responseBody); + + return $response; } } diff --git a/Model/Transformer/Order.php b/Model/Transformer/Order.php index 14e897d4..2b6e0b68 100644 --- a/Model/Transformer/Order.php +++ b/Model/Transformer/Order.php @@ -2,6 +2,15 @@ namespace Drip\Connect\Model\Transformer; +use Drip\Connect\Helper\Data; +use Magento\Sales\Model\Order\AddressFactory; +use Magento\Catalog\Model\ProductFactory; +use Magento\Catalog\Model\Product\Media\ConfigFactory; +use Magento\Newsletter\Model\SubscriberFactory; +use Drip\Connect\Model\ApiCalls\Helper\SendEventPayloadFactory; +use Magento\Sales\Model\Order as ModelOrder; +use Drip\Connect\Model\Configuration; + /** * Order Transformer */ @@ -19,39 +28,39 @@ class Order const ACTION_REFUND = 'refunded'; const ACTION_CANCEL = 'canceled'; - /** @var \Drip\Connect\Helper\Data */ + /** @var Data */ protected $connectHelper; - /** @var \Magento\Sales\Model\Order\AddressFactory */ + /** @var AddressFactory */ protected $salesOrderAddressFactory; - /** @var \Magento\Catalog\Model\ProductFactory */ + /** @var ProductFactory */ protected $catalogProductFactory; - /** @var \Magento\Catalog\Model\Product\Media\ConfigFactory */ + /** @var ConfigFactory */ protected $catalogProductMediaConfigFactory; - /** @var \Magento\Newsletter\Model\SubscriberFactory */ + /** @var SubscriberFactory */ protected $subscriberFactory; - /** @var \Drip\Connect\Model\ApiCalls\Helper\SendEventPayloadFactory */ + /** @var SendEventPayloadFactory */ protected $connectApiCallsHelperSendEventPayloadFactory; - /** @var \Magento\Sales\Model\Order */ + /** @var Order */ protected $order; - /** @var \Drip\Connect\Model\Configuration */ + /** @var Configuration */ protected $config; public function __construct( - \Drip\Connect\Helper\Data $connectHelper, - \Magento\Sales\Model\Order\AddressFactory $salesOrderAddressFactory, - \Magento\Catalog\Model\ProductFactory $catalogProductFactory, - \Magento\Catalog\Model\Product\Media\ConfigFactory $catalogProductMediaConfigFactory, - \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory, - \Drip\Connect\Model\ApiCalls\Helper\SendEventPayloadFactory $connectApiCallsHelperSendEventPayloadFactory, - \Magento\Sales\Model\Order $order, - \Drip\Connect\Model\Configuration $config + Data $connectHelper, + AddressFactory $salesOrderAddressFactory, + ProductFactory $catalogProductFactory, + ConfigFactory $catalogProductMediaConfigFactory, + SubscriberFactory $subscriberFactory, + SendEventPayloadFactory $connectApiCallsHelperSendEventPayloadFactory, + ModelOrder $order, + Configuration $config ) { $this->connectHelper = $connectHelper; $this->salesOrderAddressFactory = $salesOrderAddressFactory; @@ -64,7 +73,7 @@ public function __construct( } /** - * @return \Magento\Sales\Model\Order + * @return ModelOrder */ public function getOrder() { diff --git a/composer.json b/composer.json index 095fbf31..bbaf01b6 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "drip/connect", "description": "Connects your M2 store to drip", "type": "magento2-module", - "version": "2.0.6", + "version": "2.0.7", "homepage": "https://github.com/DripEmail/magento-m2-extension", "license": [ "OSL-3.0" diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml new file mode 100644 index 00000000..fb0110ba --- /dev/null +++ b/etc/csp_whitelist.xml @@ -0,0 +1,13 @@ + + + + + + https://api.getdrip.com + https://tag.getdrip.com + https://sleeknotecustomerscripts.sleeknote.com + https://sleeknotestaticcontent.sleeknote.com + + + + diff --git a/etc/module.xml b/etc/module.xml index 15aef428..26416ddb 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/view/frontend/templates/drip/footer_js.phtml b/view/frontend/templates/drip/footer_js.phtml index 26c12cb3..d23117e0 100644 --- a/view/frontend/templates/drip/footer_js.phtml +++ b/view/frontend/templates/drip/footer_js.phtml @@ -10,7 +10,7 @@ (function() { var dc = document.createElement('script'); dc.type = 'text/javascript'; dc.async = true; - dc.src = '//tag.getdrip.com/.js'; + dc.src = 'https://tag.getdrip.com/.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(dc, s); })();