diff --git a/Block/Advert/AbstractAdvert.php b/Block/Advert/AbstractAdvert.php index 33a8b49..645b4f6 100644 --- a/Block/Advert/AbstractAdvert.php +++ b/Block/Advert/AbstractAdvert.php @@ -7,9 +7,6 @@ use \Magento\Framework\Currency; /** - * @category Zip - * @package ZipPayment - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -31,8 +28,6 @@ abstract class AbstractAdvert extends \Magento\Framework\View\Element\Template protected $_registry; /** - * Checkout session - * * @var \Magento\Checkout\Model\Session */ protected $_checkoutSession; @@ -74,6 +69,17 @@ abstract class AbstractAdvert extends \Magento\Framework\View\Element\Template ] ]; + /** + * AbstractAdvert constructor. + * + * @param \Magento\Framework\View\Element\Template\Context $context + * @param \Zip\ZipPayment\Model\Config $config + * @param \Magento\Framework\Registry $registry + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param PriceCurrencyInterface $priceCurrency + * @param array $data + */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Zip\ZipPayment\Model\Config $config, @@ -92,6 +98,11 @@ public function __construct( $this->_priceCurrency = $priceCurrency; } + /** + * Returns the final price of the current product + * + * @return float + */ public function getProductPrice() { $product = $this->_registry->registry('current_product'); @@ -99,6 +110,11 @@ public function getProductPrice() return $price; } + /** + * Returns the quote grand total + * + * @return float|int + */ public function getCartTotal() { $totals = $this->_checkoutSession->getQuote()->getTotals(); @@ -109,6 +125,12 @@ public function getCartTotal() return $totalAmount; } + /** + * Formats the price without the currency symbol + * + * @param float|int $price + * @return string + */ public function getCurrencyFormat($price) { $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); @@ -116,6 +138,11 @@ public function getCurrencyFormat($price) return $currency->format($price, ['display' => Currency::NO_SYMBOL], false); } + /** + * Returns the current currency symbol + * + * @return string + */ public function getCurrencySymbol() { return $this->_priceCurrency->getCurrencySymbol(); @@ -124,7 +151,9 @@ public function getCurrencySymbol() /** * Check if widget has been enabled * - * @return bool + * @param string $widget + * @param string $page + * @return mixed */ protected function _configShow($widget, $page) { @@ -138,6 +167,8 @@ protected function _configShow($widget, $page) /** * Check if widget html selector has value * + * @param string $widget + * @param string $page * @return bool */ protected function _isSelectorExist($widget, $page) @@ -149,7 +180,9 @@ protected function _isSelectorExist($widget, $page) /** * Returns the config path * - * @return bool + * @param string $widget + * @param string $page + * @return string|null */ protected function _getConfigPath($widget, $page) { @@ -161,7 +194,9 @@ protected function _getConfigPath($widget, $page) } /** - * get element selectors for current widgets + * Get element selectors for current widgets + * + * @return array */ public function getElementSelectors() { diff --git a/Block/Advert/Banner.php b/Block/Advert/Banner.php index e2fe89b..0168afa 100644 --- a/Block/Advert/Banner.php +++ b/Block/Advert/Banner.php @@ -5,7 +5,6 @@ use Magento\Catalog\Block as CatalogBlock; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -14,7 +13,7 @@ class Banner extends AbstractAdvert implements CatalogBlock\ShortcutInterface /** * @const string */ - const ADVERT_TYPE = "banner"; + public const ADVERT_TYPE = "banner"; /** * Get shortcut alias diff --git a/Block/Advert/RootEl.php b/Block/Advert/RootEl.php index b8aa961..359d75f 100644 --- a/Block/Advert/RootEl.php +++ b/Block/Advert/RootEl.php @@ -6,7 +6,6 @@ use Magento\Catalog\Block as CatalogBlock; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -15,13 +14,25 @@ class RootEl extends AbstractAdvert implements CatalogBlock\ShortcutInterface /** * Get country path */ - const COUNTRY_CODE_PATH = 'general/country/default'; + public const COUNTRY_CODE_PATH = 'general/country/default'; /** * @var \Zip\ZipPayment\ViewModel\WidgetConfig */ protected $widgetConfigViewModel; + /** + * RootEl constructor. + * + * @param \Magento\Framework\View\Element\Template\Context $context + * @param \Zip\ZipPayment\Model\Config $config + * @param \Magento\Framework\Registry $registry + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency + * @param \Zip\ZipPayment\ViewModel\WidgetConfig $widgetConfigViewModel + * @param array $data + */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Zip\ZipPayment\Model\Config $config, @@ -67,7 +78,8 @@ public function getEnvironment() } /** - * get region + * Get region + * * @return string */ public function getRegion() @@ -75,23 +87,40 @@ public function getRegion() return $this->_config->getRegion(); } + /** + * Get language code + * + * @return string + */ public function getLanguageCode() { return $this->_config->getLanguageCode(); } + /** + * Get minimum order total + * + * @return float + */ public function getOrderTotalMinimum() { return $this->_config->getOrderTotalMinimum(); } + /** + * Get maximum order total + * + * @return float + */ public function getOrderTotalMaximum() { return $this->_config->getOrderTotalMaximum(); } /** - * display product widget in line + * Display product widget in line + * + * @return string */ public function isDisplayInlineWidget() { diff --git a/Block/Advert/Tagline.php b/Block/Advert/Tagline.php index 1bcd706..3842d73 100644 --- a/Block/Advert/Tagline.php +++ b/Block/Advert/Tagline.php @@ -5,7 +5,6 @@ use Magento\Catalog\Block as CatalogBlock; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -14,7 +13,7 @@ class Tagline extends AbstractAdvert implements CatalogBlock\ShortcutInterface /** * @const string */ - const WIDGET_TYPE = "tagline"; + public const WIDGET_TYPE = "tagline"; /** * Get shortcut alias diff --git a/Block/Advert/Widget.php b/Block/Advert/Widget.php index b17869e..e7e8df0 100644 --- a/Block/Advert/Widget.php +++ b/Block/Advert/Widget.php @@ -10,7 +10,7 @@ class Widget extends AbstractAdvert implements CatalogBlock\ShortcutInterface /** * @const string */ - const ADVERT_TYPE = "widget"; + public const ADVERT_TYPE = "widget"; /** * @var NotAllowedProductsProvider @@ -22,6 +22,18 @@ class Widget extends AbstractAdvert implements CatalogBlock\ShortcutInterface */ private $checkoutSession; + /** + * Widget constructor. + * + * @param \Magento\Framework\View\Element\Template\Context $context + * @param \Zip\ZipPayment\Model\Config $config + * @param \Magento\Framework\Registry $registry + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param CheckoutSession $checkoutSession + * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency + * @param NotAllowedProductsProvider $notAllowedProductsProvider + * @param array $data + */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Zip\ZipPayment\Model\Config $config, @@ -37,6 +49,11 @@ public function __construct( $this->checkoutSession = $checkoutSession; } + /** + * Returns the formatted cart total or product price for the current page + * + * @return string + */ public function getPrice() { $price = 0; diff --git a/Block/Error.php b/Block/Error.php index 4e8cf40..cc76359 100644 --- a/Block/Error.php +++ b/Block/Error.php @@ -5,7 +5,6 @@ use Magento\Framework\View\Element\Template; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -14,18 +13,28 @@ class Error extends Template /** * @const string */ - const ERROR_BODY = 'payment/zippayment/zip_messages/error_body'; + public const ERROR_BODY = 'payment/zippayment/zip_messages/error_body'; /** * @const string */ - const ERROR_HEADER = 'payment/zippayment/zip_messages/error_header'; + public const ERROR_HEADER = 'payment/zippayment/zip_messages/error_header'; /** - * @var Magento\Framework\Message\ManagerInterface + * @var \Magento\Framework\Message\ManagerInterface */ protected $_messageManager; + + /** + * @var \Zip\ZipPayment\Model\Config + */ protected $_config; + /** + * @param Template\Context $context + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Zip\ZipPayment\Model\Config $config + * @param array $data + */ public function __construct( Template\Context $context, \Magento\Framework\Message\ManagerInterface $messageManager, diff --git a/Block/Info.php b/Block/Info.php index 2e0ac8f..c2574de 100644 --- a/Block/Info.php +++ b/Block/Info.php @@ -5,7 +5,6 @@ use Magento\Payment\Block\ConfigurableInfo; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Block/Referred.php b/Block/Referred.php index a4eb6dc..45e0e78 100644 --- a/Block/Referred.php +++ b/Block/Referred.php @@ -5,7 +5,6 @@ use Magento\Framework\View\Element\Template; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -14,15 +13,28 @@ class Referred extends Template /** * @const string */ - const REFERRED_HEADER = 'payment/zippayment/zip_messages/referred_header'; + public const REFERRED_HEADER = 'payment/zippayment/zip_messages/referred_header'; /** * @const string */ - const REFERRED_BODY = 'payment/zippayment/zip_messages/referred_body'; + public const REFERRED_BODY = 'payment/zippayment/zip_messages/referred_body'; + /** + * @var \Magento\Framework\Message\ManagerInterface + */ protected $_messageManager; + + /** + * @var \Zip\ZipPayment\Model\Config + */ protected $_config; + /** + * @param Template\Context $context + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Zip\ZipPayment\Model\Config $config + * @param array $data + */ public function __construct( Template\Context $context, \Magento\Framework\Message\ManagerInterface $messageManager, diff --git a/Block/System/Config/Fieldset/Payment.php b/Block/System/Config/Fieldset/Payment.php index 4a42fc0..6a76d24 100644 --- a/Block/System/Config/Fieldset/Payment.php +++ b/Block/System/Config/Fieldset/Payment.php @@ -32,7 +32,6 @@ public function __construct( parent::__construct($context, $authSession, $jsHelper, $data); } - /** * Add custom css class * diff --git a/Block/System/Config/HealthCheck.php b/Block/System/Config/HealthCheck.php index 86aeb07..25494e0 100644 --- a/Block/System/Config/HealthCheck.php +++ b/Block/System/Config/HealthCheck.php @@ -8,23 +8,34 @@ /** * Block class of Admin health check field * - * @author Zip Co - Plugin Team * @link https://zip.co **/ class HealthCheck extends Field { - const HEALTH_CHECK_CACHE_ID = 'zip_payment_health_check'; + public const HEALTH_CHECK_CACHE_ID = 'zip_payment_health_check'; /** * @var string */ protected $_template = 'Zip_ZipPayment::system/config/check_credential_button.phtml'; + /** + * Render the field without scope and default value controls + * + * @param AbstractElement $element + * @return string + */ public function render(AbstractElement $element) { $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); return parent::render($element); } + /** + * Return the label for a health check status + * + * @param int|null $statusLevel + * @return \Magento\Framework\Phrase|null + */ public function getStatusLabel($statusLevel = null) { $statusList = [ @@ -46,6 +57,12 @@ public function getAjaxHealthCheckUrl() return $this->getUrl('zippayment/healthcheck', ['_current' => true]); } + /** + * Return the button html + * + * @param AbstractElement $element + * @return string + */ protected function _getElementHtml(AbstractElement $element) { return $this->_toHtml(); diff --git a/CHANGELOG.md b/CHANGELOG.md index 46e53f6..b755971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to the Zip Payment module for Magento 2 are documented in this file. +## 1.3.1 + +### Changed +- PHP 8.2 or later is required: PHP 8.1 is end of life and got no fix for + CVE-2026-109618 and CVE-2026-109619. +- Region for Widget offers Australia only; a saved region other than Australia is + reset to it on upgrade. +- The README describes the extension as available in Australia only. +- The credential check no longer sends the public key, which it never used. +- The code passes the Magento coding standard with no warnings. + +### Fixed +- At checkout on Magento 2.4.7 and later the widget lost its region and environment: + the strict Content Security Policy blocked the inline script that sets them. +- Checkout failed with a fatal error when a product image could not be loaded. +- An unexpected error after a charge was created left the charge and the order open; + both are now cancelled, unless the charge can no longer be cancelled. +- An invalid charge response ended in a PHP `TypeError` instead of the error message. +- A failed charge cancellation was not logged. +- PHP 8.2 deprecation notices from a dynamic property and from null passed to + `strlen()` and `stristr()`. + ## 1.3.0 ### Changed diff --git a/Controller/Adminhtml/HealthCheck/Index.php b/Controller/Adminhtml/HealthCheck/Index.php index 9257421..bed2d58 100644 --- a/Controller/Adminhtml/HealthCheck/Index.php +++ b/Controller/Adminhtml/HealthCheck/Index.php @@ -2,7 +2,7 @@ namespace Zip\ZipPayment\Controller\Adminhtml\HealthCheck; -use Zip\ZipPayment\Model\CommonUtil; +use Zip\ZipPayment\Model\Config\Source\Environment; class Index extends \Magento\Backend\App\Action { @@ -12,7 +12,7 @@ class Index extends \Magento\Backend\App\Action protected $resultFactory; /** - * @var Zip\ZipPayment\Model\Config\HealthCheck + * @var \Zip\ZipPayment\Model\Config\HealthCheck */ protected $_healthCheck; @@ -21,23 +21,31 @@ class Index extends \Magento\Backend\App\Action */ protected $_logger; + /** + * @var Environment + */ + private $environmentSource; + /** * Index constructor. * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Zip\ZipPayment\Model\Config\HealthCheck $healthCheck * @param \Zip\ZipPayment\Helper\Logger $logger + * @param Environment $environmentSource */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Zip\ZipPayment\Model\Config\HealthCheck $healthCheck, - \Zip\ZipPayment\Helper\Logger $logger + \Zip\ZipPayment\Helper\Logger $logger, + Environment $environmentSource ) { parent::__construct($context); $this->resultFactory = $resultJsonFactory; $this->_healthCheck = $healthCheck; $this->_logger = $logger; + $this->environmentSource = $environmentSource; } /** @@ -48,14 +56,10 @@ public function __construct( public function execute() { $apiKey = $this->getRequest()->getParam('apikey'); - $publicKey = $this->getRequest()->getParam('publickey'); $environment = $this->getRequest()->getParam('env'); if (preg_match('/^[\*]+$/m', $apiKey ?? '')) { $apiKey = null; } - if (preg_match('/^[\*]+$/m', $publicKey ?? '')) { - $publicKey = null; - } $environmentList = $this->getEnvironmentList(); if (!in_array($environment, $environmentList)) { $environment = null; @@ -65,7 +69,7 @@ public function execute() /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultFactory->create(); try { - $healthCheck = $this->_healthCheck->getHealthResult($websiteId, $apiKey, $publicKey, $environment); + $healthCheck = $this->_healthCheck->getHealthResult($websiteId, $apiKey, $environment); $response = $healthCheck; } catch (\Exception $e) { $this->_logger->error($e->getMessage()); @@ -77,16 +81,12 @@ public function execute() } /** - * get environment list - * @return array + * Return environments to check the credentials against + * + * @return string[] */ private function getEnvironmentList() { - $result = [ - CommonUtil::PRODUCTION, - CommonUtil::SANDBOX - ]; - - return $result; + return array_column($this->environmentSource->toOptionArray(), 'value'); } } diff --git a/Controller/Complete/Index.php b/Controller/Complete/Index.php index c5edc25..ac1c471 100644 --- a/Controller/Complete/Index.php +++ b/Controller/Complete/Index.php @@ -9,7 +9,6 @@ use Zip\ZipPayment\Model\CommonUtil; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Controller/Standard/AbstractStandard.php b/Controller/Standard/AbstractStandard.php index fcf9f2a..91a1b32 100644 --- a/Controller/Standard/AbstractStandard.php +++ b/Controller/Standard/AbstractStandard.php @@ -7,32 +7,27 @@ use Zip\ZipPayment\Model\CommonUtil; /** - * @category Zip - * @package ZipPayment - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ abstract class AbstractStandard extends Action { - const CHECKOUT_ID_KEY = 'id'; - const CHECKOUT_STATUS_APPROVED = 'approved'; + public const CHECKOUT_ID_KEY = 'id'; + public const CHECKOUT_STATUS_APPROVED = 'approved'; /** * Common Route * * @const */ - const ZIPMONEY_STANDARD_ROUTE = "zippayment/standard"; - const ZIPMONEY_COMPLETE_ROUTE = "zippayment/complete"; + public const ZIPMONEY_STANDARD_ROUTE = "zippayment/standard"; + public const ZIPMONEY_COMPLETE_ROUTE = "zippayment/complete"; /** * Error Route * * @const */ - const ZIPMONEY_ERROR_ROUTE = "zippayment/standard/error"; + public const ZIPMONEY_ERROR_ROUTE = "zippayment/standard/error"; /** - * Config - * * @var \Zip\ZipPayment\Model\Config */ protected $_config; @@ -172,6 +167,26 @@ abstract class AbstractStandard extends Action */ protected $_storeManager; + /** + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Framework\View\Result\PageFactory $pageFactory + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Sales\Model\OrderFactory $orderFactory + * @param \Magento\Framework\Url\Helper\Data $urlHelper + * @param \Magento\Customer\Model\Url $customerUrl + * @param \Magento\Framework\Json\Helper\Data $jsonHelper + * @param \Magento\Checkout\Model\PaymentInformationManagement $paymentInformationManagement + * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository + * @param \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $quoteCollectionFactory + * @param \Magento\Quote\Model\ResourceModel\Quote\Payment\CollectionFactory $quotePaymentCollectionFactory + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + * @param \Zip\ZipPayment\Model\Checkout\Factory $checkoutFactory + * @param \Zip\ZipPayment\Model\TokenisationFactory $tokenFactory + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\View\Result\PageFactory $pageFactory, @@ -218,6 +233,8 @@ public function __construct( /** * Sets quote for the customer. * + * @param bool|string $token + * @return void * @throws \Magento\Framework\Exception\LocalizedException */ public function _setCustomerQuote($token = false) @@ -246,7 +263,8 @@ public function _setCustomerQuote($token = false) /** * Checks if the Session Quote is valid, if not use the db quote. * - * @return \Magento\Quote\Model\Quote + * @param bool|string $token + * @return \Magento\Quote\Model\Quote|false */ protected function _retrieveQuote($token = false) { @@ -255,7 +273,6 @@ protected function _retrieveQuote($token = false) return $sessionQuote; } $zipMoneyCheckoutId = $this->getRequest()->getParam('checkoutId'); - $use_checkout_api_quote = false; if ($sessionQuote) { $addtionalPaymentInfo = $sessionQuote->getPayment()->getAdditionalInformation(); if (array_key_exists('zip_checkout_id', $addtionalPaymentInfo)) { @@ -268,32 +285,25 @@ protected function _retrieveQuote($token = false) } else { $this->_logger->error(__("Checkout Id does not exist in the session quote.")); } - $use_checkout_api_quote = true; } else { - // Return Session Quote $this->_logger->error(__("Session Quote does not exist.")); - $use_checkout_api_quote = true; } - //Retrurn DB Quote - if ($use_checkout_api_quote) { - $checkoutApiQuote = $this->_getQuoteByUsingCheckoutApi($zipMoneyCheckoutId); - if (!$checkoutApiQuote) { - $this->_logger->warn(__("Quote doesnot exist for the given checkout_id.")); - return false; - } else { - $this->_logger->info(__("Loading Quote by using zip checkout get api")); - } - return $checkoutApiQuote; + $checkoutApiQuote = $this->_getQuoteByUsingCheckoutApi($zipMoneyCheckoutId); + if (!$checkoutApiQuote) { + $this->_logger->warn(__("Quote doesnot exist for the given checkout_id.")); + return false; } + $this->_logger->info(__("Loading Quote by using zip checkout get api")); + return $checkoutApiQuote; } /** - * @param $zip_checkout_id + * Retrieve quote details by using zip checkout get api call + * + * @param string $zip_checkout_id * @return \Magento\Framework\DataObject|\Magento\Quote\Model\Quote * @throws \Magento\Framework\Exception\LocalizedException * @throws \zipMoney\ApiException - * - * Retrieve quote details by using zip checkout get api call */ protected function _getQuoteByUsingCheckoutApi($zip_checkout_id) { @@ -363,7 +373,9 @@ protected function _getCustomerSession() } /** - * @param $quote + * Activates the quote unless it has already been converted to an order + * + * @param \Magento\Quote\Model\Quote $quote * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ @@ -391,6 +403,7 @@ protected function _activateQuote($quote) /** * Redirects to the referred page. * + * @return void */ public function referredAction() { @@ -412,6 +425,7 @@ public function referredAction() /** * Redirects to the error page. * + * @return void */ public function errorAction() { @@ -502,7 +516,8 @@ protected function _getQuote() /** * Sets checkout quote object * - * @return \Zip\ZipPayment\Controller\Standard\AsbtractStandard + * @param \Magento\Quote\Model\Quote $quote + * @return $this */ protected function _setQuote($quote) { @@ -545,6 +560,10 @@ protected function _initCharge() /** * Sets the Http Headers, Response Code and Responde Body + * + * @param mixed $data + * @param int $responseCode + * @return void */ protected function _sendResponse($data, $responseCode = \Magento\Framework\Webapi\Response::HTTP_OK) { @@ -571,6 +590,7 @@ protected function _isResultValid() /** * Redirects to the cart or error page. * + * @return void */ protected function _redirectToCartOrError() { @@ -584,6 +604,7 @@ protected function _redirectToCartOrError() /** * Redirects to the cart page. * + * @return void */ protected function _redirectToCart() { @@ -593,6 +614,7 @@ protected function _redirectToCart() /** * Redirects to the error page. * + * @return void */ protected function _redirectToError() { @@ -618,6 +640,8 @@ protected function _deactivateQuote($quote) } /** + * Returns the quote currency code + * * @return string */ protected function _getCurrencyCode() @@ -626,7 +650,9 @@ protected function _getCurrencyCode() } /** - * check database customer already has token + * Checks whether the customer already has a stored token + * + * @return bool */ protected function _isCustomerSelectedTokenisationBefore() { @@ -638,7 +664,9 @@ protected function _isCustomerSelectedTokenisationBefore() } /** - * remove token from the database + * Removes the customer token from the database + * + * @return void */ protected function _removeCustomerToken() { diff --git a/Controller/Standard/Error.php b/Controller/Standard/Error.php index 99ad71b..870ea0b 100644 --- a/Controller/Standard/Error.php +++ b/Controller/Standard/Error.php @@ -3,7 +3,6 @@ namespace Zip\ZipPayment\Controller\Standard; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link https://zip.co diff --git a/Controller/Standard/Index.php b/Controller/Standard/Index.php index 5fc148f..271151e 100644 --- a/Controller/Standard/Index.php +++ b/Controller/Standard/Index.php @@ -5,7 +5,6 @@ use Zip\ZipPayment\Model\CommonUtil; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Controller/Standard/Referred.php b/Controller/Standard/Referred.php index 152ec68..b26e6c7 100644 --- a/Controller/Standard/Referred.php +++ b/Controller/Standard/Referred.php @@ -3,7 +3,6 @@ namespace Zip\ZipPayment\Controller\Standard; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Gateway/Command/InitializeStrategyCommand.php b/Gateway/Command/InitializeStrategyCommand.php index 65572fe..2ab2ecc 100644 --- a/Gateway/Command/InitializeStrategyCommand.php +++ b/Gateway/Command/InitializeStrategyCommand.php @@ -6,7 +6,6 @@ use Psr\Log\LoggerInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -17,6 +16,9 @@ class InitializeStrategyCommand implements CommandInterface */ private $logger; + /** + * @param LoggerInterface $logger + */ public function __construct( LoggerInterface $logger ) { diff --git a/Gateway/Http/Client/AbstractTransaction.php b/Gateway/Http/Client/AbstractTransaction.php index 02531d1..2f847b0 100644 --- a/Gateway/Http/Client/AbstractTransaction.php +++ b/Gateway/Http/Client/AbstractTransaction.php @@ -5,19 +5,45 @@ use \zipMoney\Configuration; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ class AbstractTransaction { - + /** + * @var \Magento\Framework\Encryption\EncryptorInterface + */ protected $_encryptor; + + /** + * @var \Zip\ZipPayment\Helper\Payload + */ protected $_payloadHelper; + + /** + * @var \Zip\ZipPayment\Helper\Logger + */ protected $_logger; + + /** + * @var \Zip\ZipPayment\Helper\Data + */ protected $_helper; + + /** + * @var \Zip\ZipPayment\Model\Config + */ protected $_config; + /** + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + * @param array $data + */ public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Encryption\EncryptorInterface $encryptor, diff --git a/Gateway/Http/Client/TransactionCancel.php b/Gateway/Http/Client/TransactionCancel.php index 80d5ab5..3c7a121 100644 --- a/Gateway/Http/Client/TransactionCancel.php +++ b/Gateway/Http/Client/TransactionCancel.php @@ -6,20 +6,27 @@ use Magento\Payment\Gateway\Http\ClientException; /** - * @category Zip - * @package ZipPayment - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://www.zip.co */ -/** - * Class TransactionCapture - */ class TransactionCancel extends AbstractTransaction implements ClientInterface { + /** + * @var \zipMoney\Api\ChargesApi + */ protected $_service = null; + /** + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + * @param \zipMoney\Api\ChargesApi $chargesApi + * @param array $data + */ public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Encryption\EncryptorInterface $encryptor, @@ -37,6 +44,7 @@ public function __construct( } /** + * Send the cancel request to Zip * * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject * @return array diff --git a/Gateway/Http/Client/TransactionCapture.php b/Gateway/Http/Client/TransactionCapture.php index 1cf1538..6f0d9a2 100644 --- a/Gateway/Http/Client/TransactionCapture.php +++ b/Gateway/Http/Client/TransactionCapture.php @@ -5,14 +5,26 @@ use Magento\Payment\Gateway\Http\ClientInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://www.zip.co */ class TransactionCapture extends AbstractTransaction implements ClientInterface { + /** + * @var \zipMoney\Api\ChargesApi + */ protected $_service = null; + /** + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + * @param \zipMoney\Api\ChargesApi $chargesApi + * @param array $data + */ public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Encryption\EncryptorInterface $encryptor, @@ -29,6 +41,8 @@ public function __construct( } /** + * Send the capture request to Zip + * * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject * @return array */ diff --git a/Gateway/Http/Client/TransactionRefund.php b/Gateway/Http/Client/TransactionRefund.php index b2c0db9..64c13b0 100644 --- a/Gateway/Http/Client/TransactionRefund.php +++ b/Gateway/Http/Client/TransactionRefund.php @@ -6,14 +6,26 @@ use Magento\Payment\Gateway\Http\ClientException; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://www.zip.co */ class TransactionRefund extends AbstractTransaction implements ClientInterface { + /** + * @var \zipMoney\Api\RefundsApi + */ protected $_service = null; + /** + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + * @param \zipMoney\Api\RefundsApi $refundsApi + * @param array $data + */ public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Encryption\EncryptorInterface $encryptor, @@ -29,6 +41,8 @@ public function __construct( } /** + * Send the refund request to Zip + * * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject * @return array */ diff --git a/Gateway/Http/TransferFactory.php b/Gateway/Http/TransferFactory.php index 4a8da5d..4bc3e19 100644 --- a/Gateway/Http/TransferFactory.php +++ b/Gateway/Http/TransferFactory.php @@ -7,7 +7,6 @@ use Magento\Payment\Gateway\Http\TransferInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://www.zip.co */ diff --git a/Gateway/Request/AbstractDataBuilder.php b/Gateway/Request/AbstractDataBuilder.php index 5914d3e..399810d 100644 --- a/Gateway/Request/AbstractDataBuilder.php +++ b/Gateway/Request/AbstractDataBuilder.php @@ -9,12 +9,14 @@ use Magento\Payment\Gateway\Request\BuilderInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://www.zip.co */ abstract class AbstractDataBuilder implements BuilderInterface { + /** + * @var \Zip\ZipPayment\Helper\Logger + */ protected $_logger; /** * @var \Zip\ZipPayment\Helper\Payload @@ -29,6 +31,12 @@ abstract class AbstractDataBuilder implements BuilderInterface */ protected $_order; + /** + * @param \Magento\Sales\Model\Order $order + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Helper\Logger $logger + */ public function __construct( \Magento\Sales\Model\Order $order, \Zip\ZipPayment\Helper\Payload $payloadHelper, @@ -41,6 +49,13 @@ public function __construct( $this->_order = $order; } + /** + * Convert a base currency amount to the order currency + * + * @param \Magento\Sales\Model\Order\Payment $payment + * @param float $baseAmount + * @return float + */ public function getMultiCurrencyAmount($payment, $baseAmount) { $order = $payment->getOrder(); diff --git a/Gateway/Request/CancelDataBuilder.php b/Gateway/Request/CancelDataBuilder.php index 3d34f82..eea970b 100644 --- a/Gateway/Request/CancelDataBuilder.php +++ b/Gateway/Request/CancelDataBuilder.php @@ -10,7 +10,6 @@ use Magento\Sales\Api\Data\OrderPaymentInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://www.zip.co */ diff --git a/Gateway/Request/CaptureDataBuilder.php b/Gateway/Request/CaptureDataBuilder.php index 715f1da..c7e5681 100644 --- a/Gateway/Request/CaptureDataBuilder.php +++ b/Gateway/Request/CaptureDataBuilder.php @@ -10,7 +10,6 @@ use Magento\Sales\Api\Data\OrderPaymentInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://www.zip.co */ diff --git a/Gateway/Request/RefundDataBuilder.php b/Gateway/Request/RefundDataBuilder.php index 495e037..4bf90a9 100644 --- a/Gateway/Request/RefundDataBuilder.php +++ b/Gateway/Request/RefundDataBuilder.php @@ -10,7 +10,6 @@ use Magento\Sales\Api\Data\OrderPaymentInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://www.zip.co */ diff --git a/Gateway/Response/CancelHandler.php b/Gateway/Response/CancelHandler.php index dc59f86..3ca51f8 100644 --- a/Gateway/Response/CancelHandler.php +++ b/Gateway/Response/CancelHandler.php @@ -10,7 +10,6 @@ use Magento\Payment\Gateway\Response\HandlerInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Gateway/Response/CaptureHandler.php b/Gateway/Response/CaptureHandler.php index 906c30d..7f0cc23 100644 --- a/Gateway/Response/CaptureHandler.php +++ b/Gateway/Response/CaptureHandler.php @@ -10,7 +10,6 @@ use Magento\Payment\Gateway\Response\HandlerInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Gateway/Response/RefundHandler.php b/Gateway/Response/RefundHandler.php index e46f939..6f77834 100644 --- a/Gateway/Response/RefundHandler.php +++ b/Gateway/Response/RefundHandler.php @@ -10,7 +10,6 @@ use Magento\Payment\Gateway\Response\HandlerInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Gateway/Validator/CancelResponseValidator.php b/Gateway/Validator/CancelResponseValidator.php index 491ab8a..94fdad0 100644 --- a/Gateway/Validator/CancelResponseValidator.php +++ b/Gateway/Validator/CancelResponseValidator.php @@ -6,7 +6,6 @@ use Magento\Payment\Gateway\Validator\ResultInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Gateway/Validator/CaptureResponseValidator.php b/Gateway/Validator/CaptureResponseValidator.php index 6b2fa63..ae5db12 100644 --- a/Gateway/Validator/CaptureResponseValidator.php +++ b/Gateway/Validator/CaptureResponseValidator.php @@ -6,13 +6,12 @@ use Magento\Payment\Gateway\Validator\ResultInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ class CaptureResponseValidator extends AbstractValidator { - const RESULT_CODE = 'RESULT_CODE'; + public const RESULT_CODE = 'RESULT_CODE'; /** * Performs validation of response diff --git a/Gateway/Validator/Method/NotAllowedProductsValidator.php b/Gateway/Validator/Method/NotAllowedProductsValidator.php index a438763..0e258af 100644 --- a/Gateway/Validator/Method/NotAllowedProductsValidator.php +++ b/Gateway/Validator/Method/NotAllowedProductsValidator.php @@ -4,8 +4,15 @@ class NotAllowedProductsValidator extends \Magento\Payment\Gateway\Validator\AbstractValidator { + /** + * @var \Zip\ZipPayment\Model\ResourceModel\NotAllowedProductsProvider + */ private \Zip\ZipPayment\Model\ResourceModel\NotAllowedProductsProvider $notAllowedProductsProvider; + /** + * @param \Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory + * @param \Zip\ZipPayment\Model\ResourceModel\NotAllowedProductsProvider $notAllowedProductsProvider + */ public function __construct( \Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory, \Zip\ZipPayment\Model\ResourceModel\NotAllowedProductsProvider $notAllowedProductsProvider @@ -14,6 +21,12 @@ public function __construct( $this->notAllowedProductsProvider = $notAllowedProductsProvider; } + /** + * Fail validation when the quote holds a product from an excluded category + * + * @param array $validationSubject + * @return \Magento\Payment\Gateway\Validator\ResultInterface + */ public function validate(array $validationSubject): \Magento\Payment\Gateway\Validator\ResultInterface { /** @var \Magento\Quote\Model\Quote $quote */ @@ -30,4 +43,3 @@ public function validate(array $validationSubject): \Magento\Payment\Gateway\Val return $this->createResult(true); } } - diff --git a/Gateway/Validator/RefundResponseValidator.php b/Gateway/Validator/RefundResponseValidator.php index 856a122..29940e3 100644 --- a/Gateway/Validator/RefundResponseValidator.php +++ b/Gateway/Validator/RefundResponseValidator.php @@ -6,7 +6,6 @@ use Magento\Payment\Gateway\Validator\ResultInterface; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Helper/Data.php b/Helper/Data.php index 3af4354..6067eac 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -6,7 +6,6 @@ use zipMoney\ApiException; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -38,6 +37,13 @@ class Data extends AbstractHelper /** * Set quote and config instances + * + * @param \Magento\Framework\App\Helper\Context $context + * @param \Magento\Sales\Model\OrderFactory $orderFactory + * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata + * @param \Magento\Framework\Module\ModuleListInterface $moduleList + * @param \Zip\ZipPayment\Model\Config $config */ public function __construct( \Magento\Framework\App\Helper\Context $context, @@ -58,6 +64,7 @@ public function __construct( /** * Returns the json_encoded string * + * @param mixed $object * @return string */ public function jsonEncode($object) @@ -130,7 +137,7 @@ public function __() * Cancels the order * * @param \Magento\Sales\Model\Order $order - * @param string $customer_email + * @param string|null $order_comment */ public function cancelOrder($order, $order_comment = null) { @@ -180,6 +187,8 @@ public function getExtensionVersion() } /** + * Activates the quote unless it has already been converted to an order + * * @param \Magento\Quote\Model\Quote $quote * @return bool * @throws \Magento\Framework\Exception\LocalizedException diff --git a/Helper/Logger.php b/Helper/Logger.php index 739d044..07eaaac 100644 --- a/Helper/Logger.php +++ b/Helper/Logger.php @@ -5,7 +5,6 @@ use \Zip\ZipPayment\Logger\Logger as ZipMoneyLogger; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link http://zip.co */ @@ -24,11 +23,18 @@ class Logger extends AbstractHelper 6 => 200, // 'INFO' , 7 => 100, // 'DEBUG' ]; + + /** + * @var array|null + */ protected $_privateDataKeys = null; + /** * Logs the info message to the logfile * - * @param string $message , int $storeId + * @param mixed $message + * @param int|null $storeId + * @return void */ public function info($message, $storeId = null) { @@ -38,7 +44,9 @@ public function info($message, $storeId = null) /** * Writes the log to the logfile * - * @param string $message , int $logLevel, int $storeId + * @param mixed $message + * @param int $logLevel + * @param int|null $storeId * @return bool */ protected function _log($message, $logLevel = ZipMoneyLogger::INFO, $storeId = null) @@ -70,7 +78,9 @@ protected function _log($message, $logLevel = ZipMoneyLogger::INFO, $storeId = n /** * Logs the debug message to the logfile * - * @param string $message , int $storeId + * @param mixed $message + * @param int|null $storeId + * @return void */ public function debug($message, $storeId = null) { @@ -80,7 +90,9 @@ public function debug($message, $storeId = null) /** * Logs the warn message to the logfile * - * @param string $message , int $storeId + * @param mixed $message + * @param int|null $storeId + * @return void */ public function warn($message, $storeId = null) { @@ -90,7 +102,9 @@ public function warn($message, $storeId = null) /** * Logs the notice message to the logfile * - * @param string $message , int $storeId + * @param mixed $message + * @param int|null $storeId + * @return void */ public function notice($message, $storeId = null) { @@ -100,7 +114,9 @@ public function notice($message, $storeId = null) /** * Logs the error message to the logfile * - * @param string $message , int $storeId + * @param mixed $message + * @param int|null $storeId + * @return void */ public function error($message, $storeId = null) { @@ -110,7 +126,9 @@ public function error($message, $storeId = null) /** * Logs the critical message to the logfile * - * @param string $message , int $storeId + * @param mixed $message + * @param int|null $storeId + * @return void */ public function critical($message, $storeId = null) { @@ -120,7 +138,9 @@ public function critical($message, $storeId = null) /** * Logs the alert message to the logfile * - * @param string $message , int $storeId + * @param mixed $message + * @param int|null $storeId + * @return void */ public function alert($message, $storeId = null) { @@ -130,7 +150,9 @@ public function alert($message, $storeId = null) /** * Logs the emergency message to the logfile * - * @param string $message , int $storeId + * @param mixed $message + * @param int|null $storeId + * @return void */ public function emergency($message, $storeId = null) { @@ -138,8 +160,10 @@ public function emergency($message, $storeId = null) } /** - * hide the customer privacy data from our log - * such as phone, address, email, lastname, dob + * Masks customer private data (phone, address, email, last name, dob) in an array + * + * @param mixed $debugData + * @return mixed */ protected function sanitizeArrData($debugData) { @@ -150,7 +174,7 @@ protected function sanitizeArrData($debugData) $debugData[$key] = $this->sanitizeArrData($debugData[$key]); } elseif (in_array($key, $this->getPrivateData()) && !is_numeric($key)) { $debugData[$key] = '****'; - } elseif (stristr($val, 'Authorization: Bearer') !== false) { + } elseif (stristr((string)$val, 'Authorization: Bearer') !== false) { $debugData[$key] = '****'; } } @@ -160,7 +184,9 @@ protected function sanitizeArrData($debugData) } /** - * Need to protect privacy here before we logging + * Returns the keys whose values are masked before logging + * + * @return string[] */ public function getPrivateData() { @@ -175,9 +201,15 @@ public function getPrivateData() ]; } + /** + * Masks private data in a JSON string or an array and returns it as a string + * + * @param mixed $debug + * @return string|false|null + */ public function sanitizePrivateData($debug) { - if (is_null($debug)) { + if ($debug === null) { return null; } diff --git a/Helper/Payload.php b/Helper/Payload.php index 3cee50f..52b3f5f 100644 --- a/Helper/Payload.php +++ b/Helper/Payload.php @@ -25,7 +25,6 @@ use zipMoney\Model\CheckoutFeatures; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co. * @link https://zop.co */ @@ -149,6 +148,27 @@ class Payload extends AbstractHelper */ protected $_checkoutFactory; + /** + * @param \Magento\Framework\App\Helper\Context $context + * @param \Magento\Customer\Model\CustomerFactory $customerFactory + * @param \Magento\Catalog\Model\ProductFactory $productFactory + * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory + * @param \Magento\Catalog\Helper\Image $imageHelper + * @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Customer\Model\Logger $customerLogger + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\App\Request\Http $request + * @param \Magento\Quote\Model\QuoteFactory $quoteFactory + * @param \Zip\ZipPayment\Model\Config $config + * @param \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\Collection $transactionCollection + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\TokenisationFactory $tokenFactory + * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata + * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor + * @param \Magento\Paypal\Model\Express\Checkout\Factory $checkoutFactory + */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Customer\Model\CustomerFactory $customerFactory, @@ -292,8 +312,8 @@ public function setQuote($quote) * Get customer data for shopper section in json from existing quote if the customer does not exist * * @param \zipMoney\Model\Shopper $shopper - * @param mixed \Magento\Sales\Model\Order | \Magento\Quote\Model\Quote $order_or_quote - * @return \zipMoney\Model\Shopper + * @param \Magento\Sales\Model\Order|\Magento\Quote\Model\Quote $order_or_quote + * @return \zipMoney\Model\Shopper|null */ public function getOrderOrQuoteCustomer($shopper, $order_or_quote) { @@ -516,10 +536,8 @@ protected function _getAddress($address) /** * Prepares the Order details * - * @param mixed \zipMoney\Model\CheckoutOrder - * | \zipMoney\Model\ChargeOrder $reqOrder - * @return mixed \zipMoney\Model\CheckoutOrder - * | \zipMoney\Model\ChargeOrder + * @param \zipMoney\Model\CheckoutOrder|\zipMoney\Model\ChargeOrder $reqOrder + * @return \zipMoney\Model\CheckoutOrder|\zipMoney\Model\ChargeOrder */ public function getOrderDetails($reqOrder) { @@ -683,11 +701,11 @@ public function getOrderItems() } /** - * Returns the child product + * Returns the description of the item's product, or of its child product * - * @param mixed \Magento\Quote\Model\ResourceModel\Quote\Item | \Magento\Sales\Model\Order\Item $item + * @param \Magento\Quote\Model\Quote\Item|\Magento\Sales\Model\Order\Item $item * @param int $storeId - * @return string + * @return string|null */ private function _getDescription($item, $storeId) { @@ -716,7 +734,7 @@ private function _getDescription($item, $storeId) /** * Returns the child product * - * @param mixed \Magento\Quote\Model\ResourceModel\Quote\Item | \Magento\Sales\Model\Order\Item $item + * @param \Magento\Quote\Model\Quote\Item|\Magento\Sales\Model\Order\Item $item * @return \Magento\Catalog\Model\Product */ public function getChildProduct($item) @@ -728,11 +746,11 @@ public function getChildProduct($item) } /** - * Returns the child product + * Returns the product short description, falling back to the full description * - * @param mixed \Magento\Quote\Model\ResourceModel\Quote\Item | \Magento\Sales\Model\Order\Item $item + * @param \Magento\Catalog\Model\Product $product * @param int $storeId - * @return string + * @return string|null */ private function _getProductDescription($product, $storeId) { @@ -754,20 +772,23 @@ private function _getProductDescription($product, $storeId) } /** - * Returns the child product + * Returns the thumbnail URL of the item's product * - * @param mixed \Magento\Quote\Model\ResourceModel\Quote\Item | \Magento\Sales\Model\Order\Item $item + * @param \Magento\Quote\Model\Quote\Item|\Magento\Sales\Model\Order\Item $item * @return string */ protected function _getProductImage($item) { $imageUrl = ''; + $product = null; try { //only use visible product do not care type $item must be visible cart product $product = $item->getProduct(); $imageUrl = (string) $this->_imageHelper->init($product, 'thumbnail')->getUrl(); } catch (\Exception $e) { - $this->_logger->warning('An error occurred during getting item image for product ' . $product->getId()); + $this->_logger->warn( + 'An error occurred during getting item image for product ' . ($product ? $product->getId() : '') + ); $this->_logger->error($e->getMessage()); $this->_logger->debug($e->getTraceAsString()); } @@ -848,12 +869,16 @@ public function getTokenisationFeature() /** * Returns the checkoutconfiguration * + * @param bool|string $token * @return \zipMoney\Model\CheckoutConfiguration */ public function getCheckoutConfiguration($token = false) { $checkout_config = new CheckoutConfiguration(); - $redirect_url = $this->_urlBuilder->getUrl('zippayment/complete', ['_secure' => true, '_query' => ['token' => $token]]); + $redirect_url = $this->_urlBuilder->getUrl( + 'zippayment/complete', + ['_secure' => true, '_query' => ['token' => $token]] + ); $checkout_config->setRedirectUri($redirect_url); return $checkout_config; @@ -863,6 +888,7 @@ public function getCheckoutConfiguration($token = false) * Prepares the charge payload * * @param \Magento\Sales\Model\Order $order + * @param bool|string $token * @return \zipMoney\Model\CreateChargeRequest */ public function getChargePayload($order, $token) @@ -901,7 +927,8 @@ public function getTokenPayload() } /** * Returns the authority - * @param bool $token + * + * @param bool|string $token * @return \zipMoney\Model\Authority */ public function getAuthority($token = false) @@ -981,7 +1008,7 @@ public function getCapturePayload($order, $amount) $order = $this->getOrder(); $captureChargeReq->setAmount((float)$amount); - $captureChargeReq->setCaptureIsPartial(true); + $captureChargeReq->setCaptureIsPartial(true); return $captureChargeReq; } @@ -989,7 +1016,8 @@ public function getCapturePayload($order, $amount) /** * Returns the json_encoded string * - * @return string + * @param mixed $object + * @return string|false */ public function jsonEncode($object) { diff --git a/Logger/Handler.php b/Logger/Handler.php index 5652fa2..60a3b49 100644 --- a/Logger/Handler.php +++ b/Logger/Handler.php @@ -5,7 +5,6 @@ class Handler extends \Magento\Framework\Logger\Handler\Base { /** - * File name * @var string */ protected $fileName = '/var/log/zippayment.log'; diff --git a/Model/Charge.php b/Model/Charge.php index 6d94a84..72da12e 100644 --- a/Model/Charge.php +++ b/Model/Charge.php @@ -9,7 +9,6 @@ use Zip\ZipPayment\Model\CommonUtil; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.zipmoney.com.au/ @@ -67,26 +66,42 @@ class Charge extends AbstractCheckout protected $_dataObjectHelper; /** - * @var \Zip\ZipPayment\Model\TokenisationFactory + * @var \Zip\ZipPayment\Model\Tokenisation */ protected $_tokenisationFactory; /** * @var \Magento\Store\Model\StoreManagerInterface */ + protected $_storeManager; /** - * Set quote and config instances + * Charge constructor. * - * @param array $params - */ - - /** - * @var \Magento\Store\Model\StoreManagerInterface + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Customer\Model\CustomerFactory $customerFactory + * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository + * @param \Magento\Quote\Api\CartManagementInterface $cartManagement + * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + * @param \Magento\Sales\Api\OrderPaymentRepositoryInterface $orderPaymentRepository + * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement + * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Magento\Customer\Model\Url $customerUrl + * @param \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender + * @param \Magento\Framework\DataObject\Copy $objectCopyService + * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + * @param \zipMoney\Api\ChargesApi $chargesApi + * @param \Zip\ZipPayment\Model\TokenisationFactory $tokenFactory + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param array $data + * @throws \Magento\Framework\Exception\LocalizedException */ - - protected $_storeManager; - public function __construct( \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -148,9 +163,10 @@ public function __construct( /** * Charges the customer against the order * + * @param bool $token + * @param string|null $checkoutId * @return \zipMoney\Model\Charge * @throws \Magento\Framework\Exception\LocalizedException - * @param bool $token */ public function charge($token, $checkoutId = null) { @@ -158,7 +174,6 @@ public function charge($token, $checkoutId = null) throw new \Magento\Framework\Exception\LocalizedException(__('The order does not exist.')); } - $payload = $this->_payloadHelper->getChargePayload($this->_order, $token); $this->_logger->debug("Charge Payload:- " . $this->_logger->sanitizePrivateData($payload)); @@ -191,13 +206,12 @@ public function charge($token, $checkoutId = null) } $this->_chargeResponse($charge, $this->_config->isCharge()); - } catch (\Exception $e) { + } catch (\Throwable $e) { $errorMessage = $cancelOrderMessage = "Unexpected behavior ." . $e->getMessage(); - if (!$e instanceof \zipMoney\ApiException - && !$e instanceof \Magento\Framework\Exception\LocalizedException - ) { + $isExpected = $e instanceof \zipMoney\ApiException + || $e instanceof \Magento\Framework\Exception\LocalizedException; + if (!$isExpected) { $this->_logger->alert($errorMessage); - throw $e; } if ($e instanceof \zipMoney\ApiException) { @@ -209,17 +223,40 @@ public function charge($token, $checkoutId = null) $cancelOrderMessage = $apiError; } + $chargeReleased = true; if (isset($charge) && $charge->getId()) { try { // Try to cancel the charge if we have it. $this->_api->chargesCancel($charge->getId()); - } catch (\Exception $e) { - // do nothing + } catch (\Exception $cancelException) { + $chargeReleased = false; + $this->_logger->error( + "Failed to cancel charge " . $charge->getId() . ": " . $cancelException->getMessage() + ); } } - // Cancel the order - $this->_helper->cancelOrder($this->_order, $cancelOrderMessage); - throw new \Magento\Framework\Exception\LocalizedException($errorMessage); + if ($isExpected) { + $this->_helper->cancelOrder($this->_order, $cancelOrderMessage); + throw new \Magento\Framework\Exception\LocalizedException( + $errorMessage instanceof \Magento\Framework\Phrase ? $errorMessage : __('%1', $errorMessage) + ); + } + if (!$chargeReleased) { + $this->_logger->alert( + "Charge " . $charge->getId() . " could not be cancelled; order " + . $this->_order->getIncrementId() . " is left open for manual review" + ); + throw $e; + } + try { + $this->_helper->cancelOrder($this->_order, $cancelOrderMessage); + } catch (\Throwable $cancelOrderException) { + $this->_logger->error( + "Failed to cancel order " . $this->_order->getIncrementId() . ": " + . $cancelOrderException->getMessage() + ); + } + throw $e; } return $charge; } @@ -328,9 +365,6 @@ protected function _capture($txnId, $isAuthAndCapture = false) $this->_logger->info($this->_helper->__("Payment Captured")); $this->_orderRepository->save($this->_order); - - // Invoice - $invoice = $payment->getCreatedInvoice(); } /** @@ -350,6 +384,7 @@ protected function _verifyOrderState() /** * Checks if transaction exists * + * @param string $txnId * @throws \Magento\Framework\Exception\LocalizedException */ protected function _checkTransactionExists($txnId) @@ -369,6 +404,7 @@ protected function _checkTransactionExists($txnId) /** * Authorises the charge * + * @param string $txnId */ protected function _authorise($txnId) { @@ -639,7 +675,9 @@ protected function _involveNewCustomer() } /** - * remove token from the database + * Remove token from the database + * + * @return void */ protected function _removeCustomerToken() { diff --git a/Model/Checkout.php b/Model/Checkout.php index 1f8f9b8..0ab6614 100644 --- a/Model/Checkout.php +++ b/Model/Checkout.php @@ -7,7 +7,7 @@ class Checkout extends AbstractCheckout { - const STATUS_MAGENTO_AUTHORIZED = "zip_authorised"; + public const STATUS_MAGENTO_AUTHORIZED = "zip_authorised"; /** * @var Magento\Checkout\Helper\Data */ @@ -21,6 +21,25 @@ class Checkout extends AbstractCheckout */ protected $_checkoutId = null; + /** + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Checkout\Helper\Data $checkoutHelper + * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository + * @param \Magento\Sales\Model\OrderFactory $orderFactory + * @param \Magento\Customer\Model\CustomerFactory $customerFactory + * @param \Magento\Checkout\Model\PaymentInformationManagement $paymentInformationManagement + * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement + * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + * @param \zipMoney\Api\CheckoutsApi $checkoutsApi + * @param array $data + * @throws \Magento\Framework\Exception\LocalizedException + */ public function __construct( \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -65,7 +84,6 @@ public function __construct( /** * Create quote in Zip side if not existed, and request for redirect url * - * @param \Magento\ $quote * @param bool $token * @return \zipMoney\Model\Checkout * @throws \Magento\Framework\Exception\LocalizedException diff --git a/Model/Checkout/AbstractCheckout.php b/Model/Checkout/AbstractCheckout.php index 8052a92..c2eb781 100644 --- a/Model/Checkout/AbstractCheckout.php +++ b/Model/Checkout/AbstractCheckout.php @@ -5,9 +5,6 @@ use \Magento\Checkout\Model\Type\Onepage; /** - * @category Zip - * @package ZipPayment - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -16,7 +13,7 @@ abstract class AbstractCheckout /** * @const */ - const STATUS_MAGENTO_AUTHORIZED = "zip_authorised"; + public const STATUS_MAGENTO_AUTHORIZED = "zip_authorised"; /** * @var \Magento\Quote\Api\CartRepositoryInterface */ @@ -62,6 +59,16 @@ abstract class AbstractCheckout */ protected $_customerFactory; + /** + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Customer\Model\CustomerFactory $customerFactory + * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + */ public function __construct( \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -138,6 +145,7 @@ public function getApi() /** * Sets api instance * + * @param object|string $api * @return \Zip\ZipPayment\Model\Checkout\AbstractCheckout */ public function setApi($api) @@ -201,6 +209,7 @@ public function setOrder($order) /** * Generates uniq id * + * @param string|null $seed * @return string */ public function genIdempotencyKey($seed = null) diff --git a/Model/Checkout/Factory.php b/Model/Checkout/Factory.php index d201b6a..48860a1 100644 --- a/Model/Checkout/Factory.php +++ b/Model/Checkout/Factory.php @@ -5,7 +5,6 @@ /** * Factory class for \Zip\ZipPayment\Model\Checkout * - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Model/Checks/CanUseForQuoteItems.php b/Model/Checks/CanUseForQuoteItems.php index 6e87832..882fea9 100644 --- a/Model/Checks/CanUseForQuoteItems.php +++ b/Model/Checks/CanUseForQuoteItems.php @@ -7,6 +7,13 @@ class CanUseForQuoteItems implements \Magento\Payment\Model\Checks\SpecificationInterface { + /** + * Check the quote items against the method's quote_items validator, if it has one + * + * @param MethodInterface $paymentMethod + * @param Quote $quote + * @return bool + */ public function isApplicable(MethodInterface $paymentMethod, Quote $quote): bool { try { @@ -19,4 +26,3 @@ public function isApplicable(MethodInterface $paymentMethod, Quote $quote): bool return $result->isValid(); } } - diff --git a/Model/CommonUtil.php b/Model/CommonUtil.php index e4aa39b..71d2a93 100644 --- a/Model/CommonUtil.php +++ b/Model/CommonUtil.php @@ -1,10 +1,6 @@ */ namespace Zip\ZipPayment\Model; @@ -12,26 +8,14 @@ class CommonUtil { // currencies - const CURRENCY_AUD = 'AUD'; - const CURRENCY_NZD = 'NZD'; - const CURRENCY_GBP = 'GBP'; - const CURRENCY_USD = 'USD'; + public const CURRENCY_AUD = 'AUD'; // Zip widget will display inside the iframe - const IFRAME = 'iframe'; + public const IFRAME = 'iframe'; // Zip widget will display inline - const INLINE = 'inline'; + public const INLINE = 'inline'; // environment - const SANDBOX = 'sandbox'; - const PRODUCTION = 'production'; - - /** - * @return array[] - */ - public static function getEnvironmentList() - { - return [['value' => self::SANDBOX, 'label' => __('Sandbox')], - ['value' => self::PRODUCTION, 'label' => __('Production')]]; - } + public const SANDBOX = 'sandbox'; + public const PRODUCTION = 'production'; } diff --git a/Model/Config.php b/Model/Config.php index 0f1a756..8399d00 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -8,192 +8,192 @@ class Config implements ConfigInterface { - const MODULE_NAME = 'Zip_ZipPayment'; + public const MODULE_NAME = 'Zip_ZipPayment'; /** * Method Code name in magento * * @const */ - const METHOD_CODE = 'zippayment'; + public const METHOD_CODE = 'zippayment'; /** * ZipMoney Authorised Status * * @const */ - const STATUS_MAGENTO_AUTHORIZED = "zip_authorised"; + public const STATUS_MAGENTO_AUTHORIZED = "zip_authorised"; /** * Private Key * * @const */ - const PAYMENT_ZIPMONEY_PRIVATE_KEY = 'merchant_private_key'; + public const PAYMENT_ZIPMONEY_PRIVATE_KEY = 'merchant_private_key'; /** * Public Key * * @const */ - const PAYMENT_ZIPMONEY_PUBLIC_KEY = 'merchant_public_key'; + public const PAYMENT_ZIPMONEY_PUBLIC_KEY = 'merchant_public_key'; /** * API Envronment * * @const */ - const PAYMENT_ZIPMONEY_ENVIRONMENT = 'environment'; + public const PAYMENT_ZIPMONEY_ENVIRONMENT = 'environment'; /** * Region * * @const */ - const PAYMENT_ZIPMONEY_WIDGET_REGION = 'widget_region'; + public const PAYMENT_ZIPMONEY_WIDGET_REGION = 'widget_region'; - const PAYMENT_ZIPMONEY_WIDGET_DISPLAY_MODE = 'display_widget_mode'; + public const PAYMENT_ZIPMONEY_WIDGET_DISPLAY_MODE = 'display_widget_mode'; /** * Payment Method Title * * @const */ - const PAYMENT_ZIPMONEY_TITLE = 'title'; + public const PAYMENT_ZIPMONEY_TITLE = 'title'; /** * Product Type * * @const */ - const PAYMENT_ZIPMONEY_PRODUCT = 'product'; + public const PAYMENT_ZIPMONEY_PRODUCT = 'product'; /** * Log Setting * * @const */ - const PAYMENT_ZIPMONEY_LOG_SETTINGS = 'log_settings'; + public const PAYMENT_ZIPMONEY_LOG_SETTINGS = 'log_settings'; /** * Payment Action * * @const */ - const PAYMENT_ZIPMONEY_PAYMENT_ACTION = 'payment_action'; + public const PAYMENT_ZIPMONEY_PAYMENT_ACTION = 'payment_action'; /** * Incontext Checkout * * @const */ - const PAYMENT_ZIPMONEY_ENABLE_TOKENISATION = 'enable_tokenisation'; + public const PAYMENT_ZIPMONEY_ENABLE_TOKENISATION = 'enable_tokenisation'; /** * Exclude Categories * * @const */ - const PAYMENT_ZIPMONEY_EXCLUDE_CATEGORIES = 'exclude_categories'; + public const PAYMENT_ZIPMONEY_EXCLUDE_CATEGORIES = 'exclude_categories'; /** * Minimum Order Total * * @const */ - const PAYMENT_ZIPMONEY_MINIMUM_TOTAL = 'min_order_total'; + public const PAYMENT_ZIPMONEY_MINIMUM_TOTAL = 'min_order_total'; /** * Maximum Order Total * * @const */ - const PAYMENT_ZIPMONEY_MAXIMUM_TOTAL = 'max_order_total'; + public const PAYMENT_ZIPMONEY_MAXIMUM_TOTAL = 'max_order_total'; /** * Incontext Checkout * * @const */ - const ADVERTS_HOMEPAGE_BANNER_ACTIVE = 'zip_advert/homepage/banner'; + public const ADVERTS_HOMEPAGE_BANNER_ACTIVE = 'zip_advert/homepage/banner'; /** * Homepage banner html element selector */ - const ADVERTS_HOMEPAGE_BANNER_SELECTOR = 'zip_advert/homepage/banner_selector'; + public const ADVERTS_HOMEPAGE_BANNER_SELECTOR = 'zip_advert/homepage/banner_selector'; /** * Product Page Banner Active * * @const */ - const ADVERTS_PRODUCT_BANNER_ACTIVE = 'zip_advert/productpage/banner'; + public const ADVERTS_PRODUCT_BANNER_ACTIVE = 'zip_advert/productpage/banner'; /** * Porduct page banner html selector */ - const ADVERTS_PRODUCT_BANNER_SELECTOR = 'zip_advert/productpage/banner_selector'; + public const ADVERTS_PRODUCT_BANNER_SELECTOR = 'zip_advert/productpage/banner_selector'; /** * Cart Page Banner Active * * @const */ - const ADVERTS_CART_BANNER_ACTIVE = 'zip_advert/cartpage/banner'; + public const ADVERTS_CART_BANNER_ACTIVE = 'zip_advert/cartpage/banner'; /** * Cart Page Banner html element selector */ - const ADVERTS_CART_BANNER_SELECTOR = 'zip_advert/cartpage/banner_selector'; + public const ADVERTS_CART_BANNER_SELECTOR = 'zip_advert/cartpage/banner_selector'; /** * Category Page Banner Active * * @const */ - const ADVERTS_CATEGORY_BANNER_ACTIVE = 'zip_advert/categorypage/banner'; + public const ADVERTS_CATEGORY_BANNER_ACTIVE = 'zip_advert/categorypage/banner'; /** * Category Page Banner html element selector */ - const ADVERTS_CATEGORY_BANNER_SELECTOR = 'zip_advert/categorypage/banner_selector'; + public const ADVERTS_CATEGORY_BANNER_SELECTOR = 'zip_advert/categorypage/banner_selector'; /** * Product Page Widget Active * * @const */ - const ADVERTS_PRODUCT_IMAGE_ACTIVE = 'zip_advert/productpage/widget'; + public const ADVERTS_PRODUCT_IMAGE_ACTIVE = 'zip_advert/productpage/widget'; /** * Product Page Widget html element selector * * @const */ - const ADVERTS_PRODUCT_IMAGE_SELECTOR = 'zip_advert/productpage/widget_selector'; + public const ADVERTS_PRODUCT_IMAGE_SELECTOR = 'zip_advert/productpage/widget_selector'; /** * Cart Page Widget Active * * @const */ - const ADVERTS_CART_IMAGE_ACTIVE = 'zip_advert/cartpage/widget'; + public const ADVERTS_CART_IMAGE_ACTIVE = 'zip_advert/cartpage/widget'; /** * Cart Page Widget html element selector * * @const */ - const ADVERTS_CART_IMAGE_SELECTOR = 'zip_advert/cartpage/widget_selector'; + public const ADVERTS_CART_IMAGE_SELECTOR = 'zip_advert/cartpage/widget_selector'; /** * Payment Method Logo Url * * @const */ - const PAYMENT_METHOD_LOGO_ZIP = "https://static.zip.co/logo/25px/zip.png"; + public const PAYMENT_METHOD_LOGO_ZIP = "https://static.zip.co/logo/25px/zip.png"; /** - * Error Codes Map + * Zip API error codes mapped to the codes shown to the customer * * @var array */ @@ -246,6 +246,11 @@ class Config implements ConfigInterface */ protected $_cacheTypeList; + /** + * @var string|null + */ + protected $pathPattern; + /** * @var \Magento\Framework\Message\ManagerInterface */ @@ -256,13 +261,27 @@ class Config implements ConfigInterface */ protected $_locale; + /** + * @var \Magento\Framework\Module\ModuleListInterface + */ protected $_moduleList; /** - * @var \Magento\Framework\Registry + * @var \Magento\Framework\UrlInterface */ private $_urlBuilder; + /** + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList + * @param \Magento\Config\Model\ResourceModel\Config $resourceConfig + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Magento\Framework\UrlInterface $urlBuilder + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Magento\Framework\Locale\Resolver $locale + * @param \Magento\Framework\Module\ModuleListInterface $moduleList + */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, @@ -302,8 +321,7 @@ public function setStoreId($storeId) /** * Checks whether method is active or not * - * @param $method - * @param int $storeId + * @param int|null $storeId * @return bool */ public function isMethodActive($storeId = null) @@ -356,7 +374,7 @@ public function getConfigData($field, $storeId = null) * Returns payment configuration value * * @param string $key - * @param null $storeId + * @param int|null $storeId * @return null|string */ public function getValue($key, $storeId = null) @@ -383,7 +401,8 @@ public function getValue($key, $storeId = null) /** * Returns Merchant Private Key * - * @return int + * @param int|null $storeId + * @return string|null */ public function getMerchantPrivateKey($storeId = null) { @@ -393,6 +412,7 @@ public function getMerchantPrivateKey($storeId = null) /** * Returns Merchant Public key * + * @param int|null $storeId * @return string */ public function getMerchantPublicKey($storeId = null) @@ -403,6 +423,7 @@ public function getMerchantPublicKey($storeId = null) /** * Returns Api Environment * + * @param int|null $storeId * @return string */ public function getEnvironment($storeId = null) @@ -413,6 +434,7 @@ public function getEnvironment($storeId = null) /** * Returns Exclude Categories * + * @param int|null $storeId * @return array */ public function getExcludeCategories($storeId = null): array @@ -435,7 +457,7 @@ public function getDefaultMerchantPrivateKey() /** * Returns the default config * - * @param $path + * @param string $key * @return mixed */ public function getDefaultConfig($key) @@ -474,6 +496,7 @@ public function getDefaultEnvironment() /** * Returns Region * + * @param int|null $storeId * @return string */ public function getRegion($storeId = null) @@ -483,7 +506,8 @@ public function getRegion($storeId = null) /** * Returns Widget Display mode - * @param null $storeId + * + * @param int|null $storeId * @return mixed|string|null */ public function getWidgetDisplayMode($storeId = null) @@ -519,7 +543,7 @@ public function isTokenisationEnabled() /** * Returns the minimum order total * - * @return bool + * @return float */ public function getOrderTotalMinimum() { @@ -527,9 +551,9 @@ public function getOrderTotalMinimum() } /** - * Returns the minimum order total + * Returns the maximum order total * - * @return bool + * @return float */ public function getOrderTotalMaximum() { @@ -549,6 +573,7 @@ public function isCharge() /** * Returns the log setting * + * @param int|null $storeId * @return int */ public function getLogSetting($storeId = null) @@ -559,7 +584,8 @@ public function getLogSetting($storeId = null) /** * Returns the mapped error code * - * @return int + * @param string $errorCode + * @return string|null */ public function getMappedErrorCode($errorCode) { @@ -572,8 +598,8 @@ public function getMappedErrorCode($errorCode) /** * Sets method instance used for retrieving method specific data * - * @param MethodInterface $method - * @return \Zip\ZipPayment\Model + * @param \Magento\Payment\Model\MethodInterface $methodInstance + * @return $this */ public function setMethodInstance($methodInstance) { @@ -654,8 +680,8 @@ public function getCheckoutUrl() /** * Returns the config * - * @param $path - * @param int $storeId + * @param string $path + * @param int|null $storeId * @return mixed */ public function getStoreConfig($path, $storeId = null) @@ -674,6 +700,11 @@ public function getStoreConfig($path, $storeId = null) return $value; } + /** + * Returns the language part of the current locale, e.g. "en" for en_AU + * + * @return string + */ public function getLanguageCode() { $currentLanguageCode = substr($this->_locale->getLocale(), 0, strpos($this->_locale->getLocale(), '_')); @@ -681,7 +712,9 @@ public function getLanguageCode() } /** - * get module version + * Returns the module setup version + * + * @return string */ public function getVersion() { diff --git a/Model/Config/CategorySourceRegistry.php b/Model/Config/CategorySourceRegistry.php index bc1d064..480f897 100644 --- a/Model/Config/CategorySourceRegistry.php +++ b/Model/Config/CategorySourceRegistry.php @@ -4,13 +4,27 @@ class CategorySourceRegistry { + /** + * @var bool + */ private bool $showAllCategories = false; + /** + * Whether the category source should list all categories + * + * @return bool + */ public function getShowAllCategories(): bool { return $this->showAllCategories; } + /** + * Set whether the category source should list all categories + * + * @param bool $value + * @return void + */ public function setShowAllCategories(bool $value): void { $this->showAllCategories = $value; diff --git a/Model/Config/HealthCheck.php b/Model/Config/HealthCheck.php index 88dc244..b6879ef 100644 --- a/Model/Config/HealthCheck.php +++ b/Model/Config/HealthCheck.php @@ -8,32 +8,22 @@ /** * Admin Model of health check * - * @author Zip Co - Plugin Team **/ class HealthCheck { - const STATUS_SUCCESS = 1; - const STATUS_WARNING = 2; - const STATUS_ERROR = 3; - const STATUS_OK = 0; + public const STATUS_SUCCESS = 1; + public const STATUS_WARNING = 2; + public const STATUS_ERROR = 3; + public const STATUS_OK = 0; + /** + * @var array + */ protected $_result = [ 'overall_status' => self::STATUS_SUCCESS, 'items' => [] ]; - protected $_region = [ - 'au' => 'Australia', - 'nz' => 'New Zealand', - 'us' => 'United States', - 'uk' => 'United Kingdom', - 'za' => 'South Africa', - 'ca' => 'Canada', - 'ae' => 'United Arab Emirate', - 'mx' => 'Mexico', - 'sa' => 'Saudi Arabia', - ]; - /** * @var \Zip\ZipPayment\Helper\Logger */ @@ -94,9 +84,14 @@ public function __construct( } /** - * check multiple items and get health result + * Check multiple items and get health result + * + * @param int|string $websiteId + * @param string|null $apiKey + * @param string|null $env + * @return array */ - public function getHealthResult($websiteId, $apiKey = null, $publicKey = null, $env = null) + public function getHealthResult($websiteId, $apiKey = null, $env = null) { /** @var Curl $curlObject */ $curlObject = $this->_curlFactory->create(); @@ -106,7 +101,6 @@ public function getHealthResult($websiteId, $apiKey = null, $publicKey = null, $ $storeManager = $objectManager->create(\Magento\Store\Model\StoreManagerInterface::class); $storeId = $storeManager->getWebsite($websiteId)->getDefaultStore()->getId(); - $publicKey = $publicKey ?? $this->_config->getMerchantPublicKey($storeId); $privateKey = $apiKey ?? $this->_config->getMerchantPrivateKey($storeId); $environment = $env ?? $this->_config->getEnvironment($storeId); $apiConfig->setApiKey('Authorization', $privateKey) @@ -152,7 +146,7 @@ public function getHealthResult($websiteId, $apiKey = null, $publicKey = null, $ // check api key length if it is more than or equal 50 then call SMI merchant info endpoint // otherwise call checkout get api endpoint only for Australia - if (strlen($privateKey) <= 50) { + if (strlen((string)$privateKey) <= 50) { $checkoutId = 'au-co_PxSeQfLlpaYn6bLMZSMv13'; $url = $apiConfig->getHost() . '/checkouts/' . $checkoutId; $isAuEndpoint = true; @@ -175,27 +169,7 @@ public function getHealthResult($websiteId, $apiKey = null, $publicKey = null, $ $this->appendItem(self::STATUS_ERROR, __("Your API credential is invalid")); } if (($httpCode >= 200 && $httpCode <= 299) && $isAuEndpoint == false) { - $result = preg_split('/^\r?$/m', $response, 2); - $result = trim($result[1]); - $data = json_decode($result); - $this->appendItem(self::STATUS_OK, "Api key is valid for " . $data->name); - $regions = $data->regions; - if ($regions) { - $regionList = 'Api is valid for below regions:
'; - foreach ($regions as $region) { - if ($region == 'uk') { - $countryName = 'United Kingdom'; - } elseif ($region == 'twisto') { - $countryName = 'Poland
'; - $countryName .= 'Czech Republic'; - } else { - $country = $this->_countryFactory->create()->loadByCode($region); - $countryName = $country->getName(); - } - $regionList .= $countryName . '
'; - } - $this->appendItem(self::STATUS_OK, $regionList); - } + $this->appendMerchantInfo($response); } if (($httpCode == 404 || ($httpCode >= 200 && $httpCode <= 299)) && $isAuEndpoint == true) { @@ -220,7 +194,45 @@ function ($a, $b) { } /** - * append success and failed item into health result + * Append the merchant name and regions from the merchant info response + * + * @param string $response + * @return void + */ + private function appendMerchantInfo($response) + { + $parts = preg_split('/^\r?$/m', (string)$response, 2); + $data = json_decode(trim($parts[1] ?? '')); + if (!is_object($data)) { + $this->appendItem(self::STATUS_WARNING, __("Could not read the merchant details from the API")); + return; + } + $this->appendItem(self::STATUS_OK, "Api key is valid for " . ($data->name ?? '')); + $regions = $data->regions ?? []; + if ($regions) { + $regionList = 'Api is valid for below regions:
'; + foreach ($regions as $region) { + if ($region == 'uk') { + $countryName = 'United Kingdom'; + } elseif ($region == 'twisto') { + $countryName = 'Poland
'; + $countryName .= 'Czech Republic'; + } else { + $country = $this->_countryFactory->create()->loadByCode($region); + $countryName = $country->getName(); + } + $regionList .= $countryName . '
'; + } + $this->appendItem(self::STATUS_OK, $regionList); + } + } + + /** + * Append success and failed item into health result + * + * @param int $status + * @param string|\Magento\Framework\Phrase $label + * @return void */ protected function appendItem($status, $label) { @@ -234,6 +246,11 @@ protected function appendItem($status, $label) ]; } + /** + * Warn about active stores whose secure base URL is not https + * + * @return void + */ protected function checkStoreSSLSettings() { $groups = $this->_storeManager->getWebsite()->getGroups(); diff --git a/Model/Config/Source/Category.php b/Model/Config/Source/Category.php index 0d8aced..83d9291 100644 --- a/Model/Config/Source/Category.php +++ b/Model/Config/Source/Category.php @@ -4,11 +4,34 @@ class Category implements \Magento\Framework\Data\OptionSourceInterface { + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ private \Magento\Store\Model\StoreManagerInterface $storeManager; + + /** + * @var \Magento\Framework\App\RequestInterface + */ private \Magento\Framework\App\RequestInterface $request; + + /** + * @var \Magento\Catalog\Helper\Category + */ private \Magento\Catalog\Helper\Category $categoryHelper; + + /** + * @var \Zip\ZipPayment\Model\Config\CategorySourceRegistry + */ private \Zip\ZipPayment\Model\Config\CategorySourceRegistry $categorySourceRegistry; + /** + * Category constructor. + * + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\App\RequestInterface $request + * @param \Magento\Catalog\Helper\Category $categoryHelper + * @param \Zip\ZipPayment\Model\Config\CategorySourceRegistry $categorySourceRegistry + */ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\RequestInterface $request, @@ -21,6 +44,11 @@ public function __construct( $this->categorySourceRegistry = $categorySourceRegistry; } + /** + * Returns the category options, indented by level + * + * @return array + */ public function toOptionArray(): array { $options = []; @@ -30,6 +58,13 @@ public function toOptionArray(): array return array_reverse($options); } + /** + * Appends the category and its children to the options + * + * @param array $categoryData + * @param array $optionsResult + * @return void + */ private function renderSubCategory(array $categoryData, array &$optionsResult): void { if (isset($categoryData['children'])) { @@ -48,6 +83,11 @@ private function renderSubCategory(array $categoryData, array &$optionsResult): ]; } + /** + * Returns the store category tree, including inactive categories + * + * @return array + */ private function getCategoriesTree(): array { $currentStoreId = $this->storeManager->getStore()->getId(); @@ -62,6 +102,12 @@ private function getCategoriesTree(): array return $this->convertToTree($categories); } + /** + * Builds a tree from the flat category collection + * + * @param \Magento\Framework\Data\Collection $categories + * @return array + */ private function convertToTree(\Magento\Framework\Data\Collection $categories): array { $categoryById = []; @@ -83,6 +129,11 @@ private function convertToTree(\Magento\Framework\Data\Collection $categories): return []; } + /** + * Returns the store id from the store or website request parameter + * + * @return int|null + */ private function getStoreIdByRequest(): ?int { if ($storeId = $this->request->getParam('store')) { diff --git a/Model/Config/Source/DisplayWidget.php b/Model/Config/Source/DisplayWidget.php index 073e3d2..c2203f1 100644 --- a/Model/Config/Source/DisplayWidget.php +++ b/Model/Config/Source/DisplayWidget.php @@ -6,7 +6,6 @@ /** * Used in creating options for sandbox|production config value selection - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Model/Config/Source/Environment.php b/Model/Config/Source/Environment.php index 990fb19..32f1eae 100644 --- a/Model/Config/Source/Environment.php +++ b/Model/Config/Source/Environment.php @@ -5,7 +5,6 @@ use Zip\ZipPayment\Model\CommonUtil; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -18,6 +17,7 @@ class Environment implements \Magento\Framework\Option\ArrayInterface */ public function toOptionArray() { - return CommonUtil::getEnvironmentList(); + return [['value' => CommonUtil::SANDBOX, 'label' => __('Sandbox')], + ['value' => CommonUtil::PRODUCTION, 'label' => __('Production')]]; } } diff --git a/Model/Config/Source/LogSettings.php b/Model/Config/Source/LogSettings.php index d795362..5586264 100644 --- a/Model/Config/Source/LogSettings.php +++ b/Model/Config/Source/LogSettings.php @@ -6,7 +6,6 @@ /** * Used in creating options for sandbox|production config value selection - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Model/Config/Source/PaymentAction.php b/Model/Config/Source/PaymentAction.php index 925dcc9..d3fdd10 100644 --- a/Model/Config/Source/PaymentAction.php +++ b/Model/Config/Source/PaymentAction.php @@ -2,7 +2,6 @@ namespace Zip\ZipPayment\Model\Config\Source; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ diff --git a/Model/Config/Source/Region.php b/Model/Config/Source/Region.php index c90db8e..dde9b78 100644 --- a/Model/Config/Source/Region.php +++ b/Model/Config/Source/Region.php @@ -8,9 +8,19 @@ */ class Region implements \Magento\Framework\Option\ArrayInterface { - protected $_availableCountries = ["au","gb","mx","nz","ca","us","ae","sg","za"]; + /** + * @var string[] + */ + protected $_availableCountries = ["au"]; + + /** + * @var \Magento\Directory\Api\CountryInformationAcquirerInterface + */ protected $countryInformationAcquirer; + /** + * @param \Magento\Directory\Api\CountryInformationAcquirerInterface $countryInformationAcquirer + */ public function __construct( \Magento\Directory\Api\CountryInformationAcquirerInterface $countryInformationAcquirer ) { diff --git a/Model/ResourceModel/NotAllowedProductsProvider.php b/Model/ResourceModel/NotAllowedProductsProvider.php index 77362fd..236819d 100644 --- a/Model/ResourceModel/NotAllowedProductsProvider.php +++ b/Model/ResourceModel/NotAllowedProductsProvider.php @@ -4,9 +4,20 @@ class NotAllowedProductsProvider { + /** + * @var \Zip\ZipPayment\Model\Config + */ private \Zip\ZipPayment\Model\Config $config; + + /** + * @var \Magento\Framework\App\ResourceConnection + */ private \Magento\Framework\App\ResourceConnection $resourceConnection; + /** + * @param \Zip\ZipPayment\Model\Config $config + * @param \Magento\Framework\App\ResourceConnection $resourceConnection + */ public function __construct( \Zip\ZipPayment\Model\Config $config, \Magento\Framework\App\ResourceConnection $resourceConnection @@ -15,6 +26,12 @@ public function __construct( $this->resourceConnection = $resourceConnection; } + /** + * Return ids of products assigned to the excluded categories + * + * @param int|null $storeId + * @return int[] + */ public function provideIds(?int $storeId = null): array { $excludedCategoriesIds = $this->config->getExcludeCategories($storeId); diff --git a/Model/ResourceModel/Tokenisation.php b/Model/ResourceModel/Tokenisation.php index 0ac5ce0..5df9170 100644 --- a/Model/ResourceModel/Tokenisation.php +++ b/Model/ResourceModel/Tokenisation.php @@ -1,7 +1,6 @@ * @copyright 2020 Zip Co Limited * @link http://zip.co */ @@ -10,14 +9,13 @@ class Tokenisation extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { - const ZIP_CUSTOMER_TOKEN_TABLE_NAME = 'zip_customer_token'; - - public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context - ) { - parent::__construct($context); - } + public const ZIP_CUSTOMER_TOKEN_TABLE_NAME = 'zip_customer_token'; + /** + * Initialise the main table and its primary key + * + * @return void + */ protected function _construct() { $this->_init(self::ZIP_CUSTOMER_TOKEN_TABLE_NAME, 'id'); diff --git a/Model/ResourceModel/Tokenisation/Collection.php b/Model/ResourceModel/Tokenisation/Collection.php index ec0a549..3537f0b 100644 --- a/Model/ResourceModel/Tokenisation/Collection.php +++ b/Model/ResourceModel/Tokenisation/Collection.php @@ -1,7 +1,6 @@ * @copyright 2020 Zip Co Limited * @link http://zip.co */ @@ -14,8 +13,13 @@ class Collection extends AbstractCollection { - const ZIP_CUSTOMER_TOKEN_TABLE_NAME = 'zip_customer_token'; + public const ZIP_CUSTOMER_TOKEN_TABLE_NAME = 'zip_customer_token'; + /** + * Initialise the model and resource model + * + * @return void + */ protected function _construct() { parent::_construct(); diff --git a/Model/Token.php b/Model/Token.php index 7bf3a8b..72d6e11 100644 --- a/Model/Token.php +++ b/Model/Token.php @@ -8,7 +8,6 @@ use Zip\ZipPayment\Model\Checkout\AbstractCheckout; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.zipmoney.com.au/ @@ -16,27 +15,84 @@ class Token extends AbstractCheckout { /** - * @var \Zip\ZipPayment\Model\TokenisationFactory + * @var \Zip\ZipPayment\Model\Tokenisation */ - protected $_tokenisationFactory; + /** - * Set quote and config instances - * - * @param array $params + * @var \Magento\Quote\Api\CartManagementInterface */ - protected $_quoteManagement; + + /** + * @var \Magento\Customer\Api\AccountManagementInterface + */ protected $_accountManagement; + + /** + * @var \Magento\Framework\Message\ManagerInterface + */ protected $_messageManager; + + /** + * @var \Magento\Customer\Api\CustomerRepositoryInterface + */ protected $_customerRepository; + + /** + * @var \Magento\Customer\Model\Url + */ protected $_customerUrl; + + /** + * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender + */ protected $_orderSender; + + /** + * @var \Magento\Sales\Api\OrderRepositoryInterface + */ protected $_orderRepository; + + /** + * @var \Magento\Sales\Api\OrderPaymentRepositoryInterface + */ protected $_orderPaymentRepository; + + /** + * @var \Magento\Framework\DataObject\Copy + */ protected $_objectCopyService; + + /** + * @var \Magento\Framework\Api\DataObjectHelper + */ protected $_dataObjectHelper; - + + /** + * Token constructor. + * + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Customer\Model\CustomerFactory $customerFactory + * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository + * @param \Magento\Quote\Api\CartManagementInterface $cartManagement + * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + * @param \Magento\Sales\Api\OrderPaymentRepositoryInterface $orderPaymentRepository + * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement + * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Magento\Customer\Model\Url $customerUrl + * @param \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender + * @param \Magento\Framework\DataObject\Copy $objectCopyService + * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper + * @param \Zip\ZipPayment\Helper\Payload $payloadHelper + * @param \Zip\ZipPayment\Helper\Logger $logger + * @param \Zip\ZipPayment\Helper\Data $helper + * @param \Zip\ZipPayment\Model\Config $config + * @param \zipMoney\Api\TokensApi $tokenApi + * @param \Zip\ZipPayment\Model\TokenisationFactory $tokenFactory + */ public function __construct( \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, diff --git a/Model/Tokenisation.php b/Model/Tokenisation.php index fd5e418..b28c900 100644 --- a/Model/Tokenisation.php +++ b/Model/Tokenisation.php @@ -4,8 +4,13 @@ class Tokenisation extends \Magento\Framework\Model\AbstractModel { + /** + * Initialise the resource model + * + * @return void + */ protected function _construct() { - $this->_init('Zip\ZipPayment\Model\ResourceModel\Tokenisation'); + $this->_init(\Zip\ZipPayment\Model\ResourceModel\Tokenisation::class); } } diff --git a/Model/Ui/ConfigProvider.php b/Model/Ui/ConfigProvider.php index 737518d..0ed602f 100644 --- a/Model/Ui/ConfigProvider.php +++ b/Model/Ui/ConfigProvider.php @@ -1,7 +1,6 @@ * @copyright 2020 Zip Co Limited * @link http://zip.co */ @@ -17,7 +16,6 @@ use Zip\ZipPayment\Model\CommonUtil; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @link https://zip.co */ @@ -26,7 +24,7 @@ class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface /** * @const string */ - const CODE = 'zippayment'; + public const CODE = 'zippayment'; /** * @var ResolverInterface @@ -75,11 +73,12 @@ class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface */ protected $_storeManager; - /** * @param ResolverInterface $localeResolver * @param CurrentCustomer $currentCustomer * @param PaymentHelper $paymentHelper + * @param Config $config + * @param \Zip\ZipPayment\Helper\Logger $logger * @param Session $customerSession * @param \Zip\ZipPayment\Model\TokenisationFactory $tokenFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager @@ -129,7 +128,9 @@ public function getConfig() } /** - * check database customer already has token + * Check database customer already has token + * + * @return bool */ protected function _isCustomerSelectedTokenisationBefore() { @@ -146,11 +147,21 @@ protected function _isCustomerSelectedTokenisationBefore() return false; } + /** + * Check if tokenisation is enabled and the customer is logged in + * + * @return bool + */ protected function _canCustomerSeeTokenisationOption() { return $this->_config->isTokenisationEnabled() && $this->_isCustomerLoggedin(); } + /** + * Check if the customer is logged in + * + * @return bool + */ protected function _isCustomerLoggedin() { if ($this->_customerSession->isLoggedIn()) { @@ -159,6 +170,11 @@ protected function _isCustomerLoggedin() return false; } + /** + * Check if the customer should be redirected using the saved token + * + * @return bool + */ protected function _isRedirect() { return $this->_canCustomerSeeTokenisationOption() && $this->_isCustomerSelectedTokenisationBefore(); diff --git a/README.md b/README.md index 17ebda5..b67bf0e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ -# Magento2 zippayment +# Zip Payment for Magento 2 -Zip gives customers the ability to shop now and pay later with no interest while you as the merchant get paid immediately. Customers select Zip at checkout and get approved instantly and shop securely. Zip is fully integrated with the store’s online checkout and can integrate seamlessly with your store directly via API or by using one of our platform plugins. +Zip gives customers the ability to shop now and pay later with no interest while you as the merchant get paid immediately. Customers select Zip at checkout, get approved instantly and shop securely. + +The extension is available to merchants in Australia. ## Prerequisites -- PHP 8.1 or above +- PHP 8.2 or above - Composer -- Configuration credentials +- A Zip merchant account and its API keys ## Installation instructions @@ -52,45 +54,39 @@ because Magento never reads a module's `composer.json` when the module is droppe there. If that route is needed, it has to be a separate archive — ask rather than improvise one from this repository, which carries no library at all. -### Install using Magento Marketplace +### Install from Adobe Commerce Marketplace -Note:- This extension is not yet available in the Magento Marketplace. This -section will be updated once it is released there. +The extension is also listed on +[Adobe Commerce Marketplace](https://commercemarketplace.adobe.com/zip-magento2.html). +Marketplace delivers the same Composer package through `repo.magento.com`, so the +commands above apply once the extension is added to your Marketplace account. ## Configuration -### Payment Section - -1. Contact Zip instegrations support through one of the following channels depending on your region to request your configuration credentials: - - **UK: integrationsuk@zip.co** - - **NZ: integrationsnz@zip.co** - - **AU: integrations@zip.co** -1. Open the Magento Admin -1. Click the Stores icon in the left hand menu and from there choose Settings > Configuration -1. The configuration page will open. From the little menu on the left hand side of this screen you must click Sales and then -choose Payment Methods when it expands. -1. On the Payment Methods page, click Other Payment Methods so it expands. - -![Alt text](https://static.zip.co/github-images/payment-section-2.jpg "Payment Section") - -1. Set Enable to Yes and a title for the payment method “Zip" -1. Enter the Private Key and Public Key. -1. Set payment action to Capture, or Authorise if you want to authorise on checkout completion and capture later - -### Note: Authorise is only available for AU region only +Request your API keys from Zip at integrations@zip.co. -1. Set log settings to Info or Debug if you want to log all the debug information as well. -1. Set environment to either Sandbox (for your test or development site) or Production (for your live website) -1. Set Sort Order to 0 to place the payment method on top. +In the Magento Admin, go to **Stores > Settings > Configuration > Sales > Payment +Methods** and expand the Zip section. -### Marketing Banners and Widgets Section +1. Set **Enable** to Yes and enter a **Title** for the payment method, e.g. "Zip". +1. Set **Environment** to Sandbox for a test site or Production for a live one. +1. Enter the **Public Key** and **Private Key**. +1. Set **Region for Widget** to Australia. +1. Set **Capture Method** to Capture to take payment when the order is placed, or to + Authorise to authorise at checkout and capture later. +1. Set **Log Setting** to Info, or to Debug to log debug information as well. +1. Optionally restrict the payment method by country, product category and minimum + or maximum order value. +1. Set **Sort Order** to 0 to place Zip at the top of the payment methods. -![Alt text](https://static.zip.co/github-images/marketing-section.png "Markting Banners and Widgets Section") +Banners and widgets for the home, product, category and cart pages are +configured under **Marketing Banners Widgets and Banners** in the same section. At +checkout the Zip payment method always shows its own description and "Learn More" +popup; there is nothing to configure for it. -1. Scroll down and expand Marketing Banners and Widgets section -1. Expand everything and set all options to Yes/No as per your requirement. -1. Click Save Config up the top +Click **Save Config**. -### Questions and feedback +## Questions and feedback -If you have any questions concerning this product or the implementation please contact integrations@zip.co for assistance. +If you have any questions about this extension or its implementation, contact +integrations@zip.co. diff --git a/Setup/Patch/Data/ResetWidgetRegion.php b/Setup/Patch/Data/ResetWidgetRegion.php new file mode 100644 index 0000000..e70eb9e --- /dev/null +++ b/Setup/Patch/Data/ResetWidgetRegion.php @@ -0,0 +1,59 @@ +moduleDataSetup = $moduleDataSetup; + } + + /** + * @inheritdoc + */ + public function apply() + { + $connection = $this->moduleDataSetup->getConnection(); + $connection->update( + $this->moduleDataSetup->getTable('core_config_data'), + ['value' => self::REGION], + ['path = ?' => self::PATH, 'value <> ?' => self::REGION] + ); + + return $this; + } + + /** + * @inheritdoc + */ + public static function getDependencies() + { + return []; + } + + /** + * @inheritdoc + */ + public function getAliases() + { + return []; + } +} diff --git a/Test/Unit/Block/ErrorTest.php b/Test/Unit/Block/ErrorTest.php index 1e006b3..ad746a1 100644 --- a/Test/Unit/Block/ErrorTest.php +++ b/Test/Unit/Block/ErrorTest.php @@ -15,7 +15,6 @@ use Zip\ZipPayment\Model\Config; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.zipmoney.com.au/ diff --git a/Test/Unit/Gateway/Http/Client/TransactionCancelTest.php b/Test/Unit/Gateway/Http/Client/TransactionCancelTest.php index ab324e3..299024e 100644 --- a/Test/Unit/Gateway/Http/Client/TransactionCancelTest.php +++ b/Test/Unit/Gateway/Http/Client/TransactionCancelTest.php @@ -21,7 +21,6 @@ use Zip\ZipPayment\Helper\Data as ZipMoneyDataHelper; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.zipmoney.com.au/ diff --git a/Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php b/Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php index 8668068..fb1cdab 100644 --- a/Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php +++ b/Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php @@ -21,7 +21,6 @@ use Zip\ZipPayment\Helper\Data as ZipMoneyDataHelper; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.zipmoney.com.au/ @@ -38,8 +37,6 @@ class TransactionCaptureTest extends \PHPUnit\Framework\TestCase */ protected $config; - protected $messageManager; - public function setUp() { diff --git a/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php b/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php index 0b193f3..3e31a3b 100644 --- a/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php +++ b/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php @@ -11,7 +11,6 @@ use Zip\ZipPayment\Model\Config; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.zipmoney.com.au/ @@ -28,8 +27,6 @@ class TransactionRefundTest extends \PHPUnit\Framework\TestCase */ protected $config; - protected $messageManager; - public function setUp() { diff --git a/Test/Unit/Model/ChargeTest.php b/Test/Unit/Model/ChargeTest.php index bc7b037..492e163 100644 --- a/Test/Unit/Model/ChargeTest.php +++ b/Test/Unit/Model/ChargeTest.php @@ -22,7 +22,6 @@ use Zip\ZipPayment\Helper\Data as ZipMoneyDataHelper; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.zipmoney.com.au/ @@ -39,8 +38,6 @@ class ChargeTest extends \PHPUnit\Framework\TestCase */ protected $config; - protected $messageManager; - public function setUp() { diff --git a/Test/Unit/Model/CheckoutTest.php b/Test/Unit/Model/CheckoutTest.php index 1265dc4..c2b61d6 100644 --- a/Test/Unit/Model/CheckoutTest.php +++ b/Test/Unit/Model/CheckoutTest.php @@ -29,7 +29,6 @@ use Zip\ZipPayment\Helper\Data as ZipMoneyDataHelper; /** - * @author Zip Plugin Team * @copyright 2020 Zip Co Limited * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.zipmoney.com.au/ @@ -46,8 +45,6 @@ class CheckoutTest extends \PHPUnit\Framework\TestCase */ protected $config; - protected $messageManager; - public function setUp() { diff --git a/ViewModel/WidgetConfig.php b/ViewModel/WidgetConfig.php index 301c9cf..929e172 100644 --- a/ViewModel/WidgetConfig.php +++ b/ViewModel/WidgetConfig.php @@ -4,12 +4,40 @@ class WidgetConfig implements \Magento\Framework\View\Element\Block\ArgumentInterface { + /** + * @var \Zip\ZipPayment\Model\Config + */ protected \Zip\ZipPayment\Model\Config $config; + + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ protected \Magento\Framework\Serialize\SerializerInterface $serializer; + + /** + * @var \Zip\ZipPayment\Model\ResourceModel\NotAllowedProductsProvider + */ protected \Zip\ZipPayment\Model\ResourceModel\NotAllowedProductsProvider $notAllowedProductsProvider; + + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ protected \Magento\Store\Model\StoreManagerInterface $storeManager; + + /** + * @var \Magento\Framework\Registry + */ protected \Magento\Framework\Registry $registry; + /** + * WidgetConfig constructor. + * + * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Zip\ZipPayment\Model\Config $config + * @param \Zip\ZipPayment\Model\ResourceModel\NotAllowedProductsProvider $notAllowedProductsProvider + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\Registry $registry + */ public function __construct( \Magento\Framework\Serialize\SerializerInterface $serializer, \Zip\ZipPayment\Model\Config $config, @@ -58,6 +86,7 @@ public function getCurrentProductId(): ?int /** * Get list of product IDs that are not allowed for Zip payment + * * Only used for cart/checkout pages * * @return array @@ -85,10 +114,6 @@ public function getWidgetConfigJson(): string $config['currentProductId'] = $currentProductId; $config['isCurrentProductAllowed'] = $this->isCurrentProductAllowed(); // Don't send full array on product pages - } else { - // For other pages (cart, checkout) - may need full list if implementing cart-level checks - // But usually validator handles this on server, so we can skip it - // $config['notAllowedProducts'] = $this->getNotAllowedProductIds(); } return $this->serializer->serialize($config); diff --git a/composer.json b/composer.json index 66d7c9e..3487062 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "zip/magento2", "description": "Zip Payment Module for Magento 2", - "version": "1.3.0", + "version": "1.3.1", "type": "magento2-module", "license": [ "OSL-3.0" @@ -13,7 +13,7 @@ } ], "require": { - "php": ">=8.1", + "php": ">=8.2", "ext-curl": "*", "zipmoney/merchantapi-php": "^1.0.24" }, diff --git a/composer.lock b/composer.lock index 88c79c4..ef534ee 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a9e1416dae191c939a4ff49d6dfec87a", + "content-hash": "d7fd4c5ce5da2675e25cfb1a43dbd702", "packages": [ { "name": "zipmoney/merchantapi-php", @@ -67,14 +67,14 @@ ], "packages-dev": [], "aliases": [], - "minimum-stability": "dev", - "stability-flags": [], + "minimum-stability": "stable", + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=8.1", + "php": ">=8.2", "ext-curl": "*" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.9.0" } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index f3b68aa..e14397d 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -3,9 +3,6 @@ /** * Zip_ZipPayment Admin Interface definitions * -* @category ZipMoney -* @package Zip_ZipPayment -* @author Zip Plugin Team * @link https://zip.co */ --> diff --git a/etc/config.xml b/etc/config.xml index a0a6f00..048266c 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -3,9 +3,6 @@ /** * Zip_ZipPayment Config definitions * -* @category Zip -* @package ZipPayment -* @author Zip Plugin Team * @link https://zip.co */ --> diff --git a/etc/di.xml b/etc/di.xml index d5bc9c8..fcde3ba 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -3,9 +3,6 @@ /** * Zip_ZipPayment DI definitions * -* @category Zip -* @package ZipPayment -* @author Zip Plugin Team * @link https://zip.co */ --> diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 41b887b..039c220 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -3,9 +3,6 @@ /** * Zip_ZipPayment DI definitions * -* @category Zip -* @package ZipPayment -* @author Zip Plugin Team * @link https://zip.co */ --> diff --git a/etc/frontend/routes.xml b/etc/frontend/routes.xml index 2eb9fb5..dd22617 100644 --- a/etc/frontend/routes.xml +++ b/etc/frontend/routes.xml @@ -3,9 +3,6 @@ /** * Zip_ZipPayment Routes definitions * -* @category Zip -* @package ZipPayment -* @author Zip Plugin Team * @link https://zip.co */ --> diff --git a/etc/module.xml b/etc/module.xml index acceeaf..9384112 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -3,14 +3,11 @@ /** * Zip_ZipPayment Module definitions * -* @category Zip -* @package ZipPayment -* @author Zip Plugin Team * @link https://zip.co */ --> - + diff --git a/etc/payment.xml b/etc/payment.xml index 883cfab..fa31b17 100644 --- a/etc/payment.xml +++ b/etc/payment.xml @@ -3,9 +3,6 @@ /** * Zip_ZipPayment Payment configuration * -* @category Zip -* @package ZipPayment -* @author Zip Plugin Team * @link https://zip.co */ --> diff --git a/view/adminhtml/templates/system/config/check_credential_button.phtml b/view/adminhtml/templates/system/config/check_credential_button.phtml index fc14903..6ad8ff4 100644 --- a/view/adminhtml/templates/system/config/check_credential_button.phtml +++ b/view/adminhtml/templates/system/config/check_credential_button.phtml @@ -1,6 +1,6 @@
diff --git a/view/frontend/templates/standard/referred.phtml b/view/frontend/templates/standard/referred.phtml index cc4b9f9..74ea3d3 100644 --- a/view/frontend/templates/standard/referred.phtml +++ b/view/frontend/templates/standard/referred.phtml @@ -1,4 +1,4 @@
- escapeHtml($block->getBodyText()); ?> + escapeHtml($block->getBodyText()); ?>