diff --git a/CHANGELOG.md b/CHANGELOG.md index 345a8cf..f7ca09d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [3.2.7](https://github.com/unzerdev/magento2/compare/3.2.6..3.2.7) +### Added +* Client's IP address in every request sent to Unzer API + ## [3.2.6](https://github.com/unzerdev/magento2/compare/3.2.5..3.2.6) ### Fixed * Discount amount when taxes are applied diff --git a/Model/Config.php b/Model/Config.php index c8f03b0..db39d27 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -8,6 +8,7 @@ use Magento\Payment\Model\CcConfig; use Magento\Payment\Model\MethodInterface; use Magento\Store\Model\ScopeInterface; +use Magento\Framework\HTTP\PhpEnvironment\Request; use Unzer\PAPI\Model\Logger\DebugHandler; use Unzer\PAPI\Model\Method\OverrideApiCredentialInterface; use UnzerSDK\Unzer; @@ -75,6 +76,11 @@ class Config extends \Magento\Payment\Gateway\Config\Config */ private ScopeConfigInterface $_scopeConfig; + /** + * @var Request + */ + private Request $_request; + /** * @var CcConfig */ @@ -82,10 +88,12 @@ class Config extends \Magento\Payment\Gateway\Config\Config /** * Config constructor. + * * @param Resolver $localeResolver * @param ScopeConfigInterface $scopeConfig * @param DebugHandler $debugHandler * @param CcConfig $ccConfig + * @param Request $request * @param string|null $methodCode * @param string $pathPattern */ @@ -94,8 +102,9 @@ public function __construct( ScopeConfigInterface $scopeConfig, DebugHandler $debugHandler, CcConfig $ccConfig, - $methodCode = null, - $pathPattern = self::DEFAULT_PATH_PATTERN + Request $request, + ?string $methodCode = null, + string $pathPattern = self::DEFAULT_PATH_PATTERN ) { parent::__construct($scopeConfig, $methodCode, $pathPattern); @@ -103,6 +112,7 @@ public function __construct( $this->_localeResolver = $localeResolver; $this->_scopeConfig = $scopeConfig; $this->ccConfig = $ccConfig; + $this->_request = $request; } /** @@ -178,6 +188,12 @@ public function getUnzerClient(string $storeId = null, MethodInterface $paymentM $this->_localeResolver->getLocale() ); + $clientsIpAddress = $this->_request->getClientIp(); + + if (filter_var($clientsIpAddress, FILTER_VALIDATE_IP)) { + $client->setClientIp($clientsIpAddress); + } + $client->setDebugMode($this->isDebugMode($storeId)); $client->setDebugHandler($this->_debugHandler); diff --git a/composer.json b/composer.json index 63c46c5..495efc3 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "unzerdev/magento2", "description": "This extension for Magento 2 provides a direct integration of the Unzer payment types to your Magento 2 shop via the Unzer Payment API (PAPI).", "type": "magento2-module", - "version": "3.2.6", + "version": "3.2.7", "license": "Apache-2.0", "require": { "php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0", diff --git a/etc/module.xml b/etc/module.xml index f717fe6..80a570e 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - +