Skip to content

Commit 1073540

Browse files
authored
add merchant_ip to MitPaymentRequest (#6)
1 parent 65978e0 commit 1073540

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/Concerns/Parameters.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Omnipay\EveryPay\Concerns;
44

5+
use RuntimeException;
6+
57
trait Parameters
68
{
79
public function getDefaultParameters()
@@ -105,6 +107,27 @@ public function setClientIp($ip)
105107
return $this->setParameter('user_ip', $ip);
106108
}
107109

110+
/**
111+
* The IP of the Merchant server.
112+
* This is only used for MIT payments (as Customer is not involved in the payment process).
113+
* If no IP is set, it will default to
114+
*/
115+
public function getMerchantIp()
116+
{
117+
if ($ip = $this->getParameter('merchant_ip')) {
118+
return $ip;
119+
} elseif (isset($_SERVER['SERVER_ADDR'])) {
120+
return $_SERVER['SERVER_ADDR'];
121+
} else {
122+
throw new RuntimeException('Unable to determine merchant_ip.');
123+
}
124+
}
125+
126+
public function setMerchantIp($ip)
127+
{
128+
return $this->setParameter('merchant_ip', $ip);
129+
}
130+
108131
public function getSaveCard()
109132
{
110133
return $this->getParameter('saveCard');

src/Messages/MitPaymentRequest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ public function getData()
3636
'amount' => $this->getAmount(),
3737
'order_reference' => $this->getTransactionId(),
3838
'token_agreement' => TokenAgreement::UNSCHEDULED,
39+
40+
'merchant_ip' => $this->getMerchantIp(),
3941
];
4042

4143
if ($this->getEmail()) {
4244
$data['email'] = $this->getEmail();
4345
}
4446

45-
if ($this->getClientIp()) {
46-
$data['customer_ip'] = $this->getClientIp();
47-
}
48-
4947
return array_merge($baseData, $data);
5048
}
5149

tests/EveryPayTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ public function testEmail()
2929
$this->assertSame('[email protected]', $this->gateway->getEmail());
3030
}
3131

32+
public function testClientIp()
33+
{
34+
$this->assertSame($this->gateway, $this->gateway->setClientIp('1.1.1.1'));
35+
$this->assertSame('1.1.1.1', $this->gateway->getClientIp());
36+
}
37+
38+
public function testMerchantIp()
39+
{
40+
$_SERVER['SERVER_ADDR'] = '1.1.1.1';
41+
42+
$this->assertSame('1.1.1.1', $this->gateway->getMerchantIp());
43+
$this->assertSame($this->gateway, $this->gateway->setMerchantIp('2.2.2.2'));
44+
$this->assertSame('2.2.2.2', $this->gateway->getMerchantIp());
45+
}
46+
3247
public function testSaveCard()
3348
{
3449
// Default is false

0 commit comments

Comments
 (0)