Skip to content

Commit df07d3b

Browse files
amsrossamacneil
authored andcommitted
Added MD5 hash secret parameter for Authorize.Net SIM. Closes #131 Closes #134
1 parent f40f449 commit df07d3b

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

src/Omnipay/AuthorizeNet/Message/AbstractRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public function setCustomerId($value)
5959
return $this->setParameter('customerId', $value);
6060
}
6161

62+
public function getHashSecret()
63+
{
64+
return $this->getParameter('hashSecret');
65+
}
66+
67+
public function setHashSecret($value)
68+
{
69+
return $this->setParameter('hashSecret', $value);
70+
}
71+
6272
protected function getBaseData()
6373
{
6474
$data = array();

src/Omnipay/AuthorizeNet/Message/SIMCompleteAuthorizeRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getData()
2929

3030
public function getHash()
3131
{
32-
return md5($this->getApiLoginId().$this->getTransactionId().$this->getAmount());
32+
return md5($this->getHashSecret().$this->getApiLoginId().$this->getTransactionId().$this->getAmount());
3333
}
3434

3535
public function send()

src/Omnipay/AuthorizeNet/SIMGateway.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ public function getName()
2424
return 'Authorize.Net SIM';
2525
}
2626

27+
public function getDefaultParameters()
28+
{
29+
$parameters = parent::getDefaultParameters();
30+
$parameters['hashSecret'] = '';
31+
32+
return $parameters;
33+
}
34+
35+
public function getHashSecret()
36+
{
37+
return $this->getParameter('hashSecret');
38+
}
39+
40+
public function setHashSecret($value)
41+
{
42+
return $this->setParameter('hashSecret', $value);
43+
}
44+
45+
2746
public function authorize(array $parameters = array())
2847
{
2948
return $this->createRequest('\Omnipay\AuthorizeNet\Message\SIMAuthorizeRequest', $parameters);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\AuthorizeNet\Message;
13+
14+
use Omnipay\TestCase;
15+
16+
class SIMCompleteAuthorizeRequestTest extends TestCase
17+
{
18+
public function setUp()
19+
{
20+
$this->request = new SIMCompleteAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
21+
}
22+
23+
public function testGetHash()
24+
{
25+
$this->assertSame(md5(''), $this->request->getHash());
26+
27+
$this->request->setHashSecret('hashsec');
28+
$this->request->setApiLoginId('apilogin');
29+
$this->request->setTransactionId('trnid');
30+
$this->request->setAmount('10.00');
31+
32+
$this->assertSame(md5('hashsecapilogintrnid10.00'), $this->request->getHash());
33+
}
34+
}

tests/Omnipay/AuthorizeNet/SIMGatewayTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function setUp()
2121

2222
$this->gateway = new SIMGateway($this->getHttpClient(), $this->getHttpRequest());
2323
$this->gateway->setApiLoginId('example');
24+
$this->gateway->setHashSecret('elpmaxe');
2425

2526
$this->options = array(
2627
'amount' => '10.00',
@@ -47,7 +48,7 @@ public function testCompleteAuthorize()
4748
array(
4849
'x_response_code' => '1',
4950
'x_trans_id' => '12345',
50-
'x_MD5_Hash' => md5('example9910.00'),
51+
'x_MD5_Hash' => md5('elpmaxeexample9910.00'),
5152
)
5253
);
5354

@@ -76,7 +77,7 @@ public function testCompletePurchase()
7677
array(
7778
'x_response_code' => '1',
7879
'x_trans_id' => '12345',
79-
'x_MD5_Hash' => md5('example9910.00'),
80+
'x_MD5_Hash' => md5('elpmaxeexample9910.00'),
8081
)
8182
);
8283

0 commit comments

Comments
 (0)