Skip to content

Commit 801a674

Browse files
committed
Additional DPM tests, including check that CC expiry is empty.
1 parent 4e49d8c commit 801a674

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class DPMCompleteAuthorizeRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new DPMCompleteRequest($this->getHttpClient(), $this->getHttpRequest());
12+
}
13+
14+
/**
15+
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
16+
* @expectedExceptionMessage Incorrect hash
17+
*/
18+
public function testGetDataInvalid()
19+
{
20+
$this->getHttpRequest()->request->replace(array('x_MD5_Hash' => 'invalid'));
21+
$this->request->getData();
22+
}
23+
24+
public function testGetHash()
25+
{
26+
$this->assertSame(md5(''), $this->request->getHash());
27+
28+
$this->request->setHashSecret('hashsec');
29+
$this->request->setApiLoginId('apilogin');
30+
$this->request->setTransactionId('trnid');
31+
$this->request->setAmount('10.00');
32+
33+
$this->assertSame(md5('hashsecapilogintrnid10.00'), $this->request->getHash());
34+
}
35+
36+
public function testSend()
37+
{
38+
// Note: the hash contains no data supplied by the merchant site, apart
39+
// from the secret. This is the first point at which we see the transaction
40+
// reference (x_trans_id), and this hash is to validate that the reference and
41+
// the amount have not be tampered with en-route.
42+
43+
$this->getHttpRequest()->request->replace(
44+
array(
45+
'x_response_code' => '1',
46+
'x_trans_id' => '12345',
47+
'x_amount' => '10.00',
48+
'x_MD5_Hash' => strtolower(md5('shhh' . 'user' . '12345' . '10.00')),
49+
)
50+
);
51+
$this->request->setApiLoginId('user');
52+
$this->request->setHashSecret('shhh');
53+
//$this->request->setAmount('10.00');
54+
//$this->request->setTransactionReference('12345');
55+
56+
$response = $this->request->send();
57+
58+
$this->assertTrue($response->isSuccessful());
59+
$this->assertSame('12345', $response->getTransactionReference());
60+
$this->assertNull($response->getMessage());
61+
}
62+
}

tests/Message/DPMPurchaseRequestTest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,25 @@ class DPMPurchaseRequestTest extends TestCase
88
{
99
public function setUp()
1010
{
11+
// The card for DPM will always start out blank, so remove the card details.
12+
13+
$validCard = array_merge(
14+
$this->getValidCard(),
15+
array(
16+
'number' => '',
17+
'expiryMonth' => '',
18+
'expiryYear' => '',
19+
'cvv' => '',
20+
)
21+
);
22+
1123
$this->request = new DPMPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
1224
$this->request->initialize(
1325
array(
1426
'clientIp' => '10.0.0.1',
1527
'amount' => '12.00',
1628
'customerId' => 'cust-id',
17-
'card' => $this->getValidCard(),
29+
'card' => $validCard,
1830
'returnUrl' => 'https://www.example.com/return',
1931
'liveEndpoint' => 'https://secure.authorize.net/gateway/transact.dll',
2032
'developerEndpoint' => 'https://test.authorize.net/gateway/transact.dll',
@@ -29,6 +41,48 @@ public function testGetData()
2941
$this->assertSame('AUTH_CAPTURE', $data['x_type']);
3042
$this->assertSame('10.0.0.1', $data['x_customer_ip']);
3143
$this->assertSame('cust-id', $data['x_cust_id']);
44+
45+
$this->assertSame('', $data['x_card_num']);
46+
$this->assertSame('', $data['x_exp_date']);
47+
$this->assertSame('', $data['x_card_code']);
48+
3249
$this->assertArrayNotHasKey('x_test_request', $data);
3350
}
51+
52+
public function testGetDataTestMode()
53+
{
54+
$this->request->setTestMode(true);
55+
56+
$data = $this->request->getData();
57+
58+
$this->assertSame('TRUE', $data['x_test_request']);
59+
}
60+
61+
public function testGetHash()
62+
{
63+
$this->request->setApiLoginId('user');
64+
$this->request->setTransactionKey('key');
65+
$data = array(
66+
'x_fp_sequence' => 'a',
67+
'x_fp_timestamp' => 'b',
68+
'x_amount' => 'c',
69+
);
70+
71+
$expected = hash_hmac('md5', 'user^a^b^c^', 'key');
72+
73+
$this->assertSame($expected, $this->request->getHash($data));
74+
}
75+
76+
public function testSend()
77+
{
78+
$response = $this->request->send();
79+
80+
$this->assertFalse($response->isSuccessful());
81+
$this->assertTrue($response->isRedirect());
82+
$this->assertNotEmpty($response->getRedirectUrl());
83+
$this->assertSame('POST', $response->getRedirectMethod());
84+
85+
$redirectData = $response->getRedirectData();
86+
$this->assertSame('https://www.example.com/return', $redirectData['x_relay_url']);
87+
}
3488
}

0 commit comments

Comments
 (0)