File tree Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 22
33namespace Omnipay \EveryPay \Concerns ;
44
5+ use RuntimeException ;
6+
57trait 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 ' );
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments