Skip to content

Commit 6d70a38

Browse files
Merge pull request #81 from unzerdev/fix/magento-98
Add client IP for all requests sent to Unzer API
2 parents f09d92b + c0ece44 commit 6d70a38

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
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).
55

6+
## [3.2.7](https://github.com/unzerdev/magento2/compare/3.2.6..3.2.7)
7+
### Added
8+
* Client's IP address in every request sent to Unzer API
9+
610
## [3.2.6](https://github.com/unzerdev/magento2/compare/3.2.5..3.2.6)
711
### Fixed
812
* Discount amount when taxes are applied

Model/Config.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Payment\Model\CcConfig;
99
use Magento\Payment\Model\MethodInterface;
1010
use Magento\Store\Model\ScopeInterface;
11+
use Magento\Framework\HTTP\PhpEnvironment\Request;
1112
use Unzer\PAPI\Model\Logger\DebugHandler;
1213
use Unzer\PAPI\Model\Method\OverrideApiCredentialInterface;
1314
use UnzerSDK\Unzer;
@@ -75,17 +76,24 @@ class Config extends \Magento\Payment\Gateway\Config\Config
7576
*/
7677
private ScopeConfigInterface $_scopeConfig;
7778

79+
/**
80+
* @var Request
81+
*/
82+
private Request $_request;
83+
7884
/**
7985
* @var CcConfig
8086
*/
8187
private CcConfig $ccConfig;
8288

8389
/**
8490
* Config constructor.
91+
*
8592
* @param Resolver $localeResolver
8693
* @param ScopeConfigInterface $scopeConfig
8794
* @param DebugHandler $debugHandler
8895
* @param CcConfig $ccConfig
96+
* @param Request $request
8997
* @param string|null $methodCode
9098
* @param string $pathPattern
9199
*/
@@ -94,15 +102,17 @@ public function __construct(
94102
ScopeConfigInterface $scopeConfig,
95103
DebugHandler $debugHandler,
96104
CcConfig $ccConfig,
97-
$methodCode = null,
98-
$pathPattern = self::DEFAULT_PATH_PATTERN
105+
Request $request,
106+
?string $methodCode = null,
107+
string $pathPattern = self::DEFAULT_PATH_PATTERN
99108
) {
100109
parent::__construct($scopeConfig, $methodCode, $pathPattern);
101110

102111
$this->_debugHandler = $debugHandler;
103112
$this->_localeResolver = $localeResolver;
104113
$this->_scopeConfig = $scopeConfig;
105114
$this->ccConfig = $ccConfig;
115+
$this->_request = $request;
106116
}
107117

108118
/**
@@ -178,6 +188,12 @@ public function getUnzerClient(string $storeId = null, MethodInterface $paymentM
178188
$this->_localeResolver->getLocale()
179189
);
180190

191+
$clientsIpAddress = $this->_request->getClientIp();
192+
193+
if (filter_var($clientsIpAddress, FILTER_VALIDATE_IP)) {
194+
$client->setClientIp($clientsIpAddress);
195+
}
196+
181197
$client->setDebugMode($this->isDebugMode($storeId));
182198
$client->setDebugHandler($this->_debugHandler);
183199

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "unzerdev/magento2",
33
"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).",
44
"type": "magento2-module",
5-
"version": "3.2.6",
5+
"version": "3.2.7",
66
"license": "Apache-2.0",
77
"require": {
88
"php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0",

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4-
<module name="Unzer_PAPI" setup_version="3.2.6">
4+
<module name="Unzer_PAPI" setup_version="3.2.7">
55
<sequence>
66
<module name="Magento_Checkout"/>
77
<module name="Magento_Config" />

0 commit comments

Comments
 (0)