22
33namespace Omnipay \AuthorizeNet \Message ;
44
5+ /**
6+ * The CompleteRequest object is invoked in the callback handler.
7+ */
8+
59use Omnipay \Tests \TestCase ;
610
711class DPMCompleteAuthorizeRequestTest extends TestCase
@@ -21,21 +25,19 @@ public function testGetDataInvalid()
2125 $ this ->request ->getData ();
2226 }
2327
24- public function testGetHash ()
28+ public function testGetDpmHash ()
2529 {
2630 $ this ->assertSame (md5 ('' ), $ this ->request ->getHash ());
2731
2832 $ this ->request ->setHashSecret ('hashsec ' );
2933 $ this ->request ->setApiLoginId ('apilogin ' );
30- $ this ->request ->setTransactionId ('trnid ' );
31- $ this ->request ->setAmount ('10.00 ' );
3234
33- $ this ->assertSame (md5 ('hashsecapilogintrnid10. 00 ' ), $ this ->request ->getHash ( ));
35+ $ this ->assertSame (md5 ('hashsec ' . ' apilogin ' . ' trnid ' . ' 10. 00 ' ), $ this ->request ->getDpmHash ( ' trnid ' , ' 10.00 ' ));
3436 }
3537
3638 public function testSend ()
3739 {
38- // Note: the hash contains no data supplied by the merchant site, apart
40+ // The hash contains no data supplied by the merchant site, apart
3941 // from the secret. This is the first point at which we see the transaction
4042 // reference (x_trans_id), and this hash is to validate that the reference and
4143 // the amount have not be tampered with en-route.
@@ -50,13 +52,39 @@ public function testSend()
5052 );
5153 $ this ->request ->setApiLoginId ('user ' );
5254 $ this ->request ->setHashSecret ('shhh ' );
53- //$this->request->setAmount('10.00');
54- // $this->request->setTransactionReference('12345 ');
55+
56+ $ this ->request ->setAmount ( ' 10.00 ' );
5557
5658 $ response = $ this ->request ->send ();
5759
5860 $ this ->assertTrue ($ response ->isSuccessful ());
5961 $ this ->assertSame ('12345 ' , $ response ->getTransactionReference ());
6062 $ this ->assertNull ($ response ->getMessage ());
6163 }
64+
65+ /**
66+ * @expectedException \Omnipay\Common\Exception\InvalidRequestException
67+ * @expectedExceptionMessage Incorrect amount
68+ */
69+ public function testSendWrongAmount ()
70+ {
71+ $ this ->getHttpRequest ()->request ->replace (
72+ array (
73+ 'x_response_code ' => '1 ' ,
74+ 'x_trans_id ' => '12345 ' ,
75+ 'x_amount ' => '10.00 ' ,
76+ 'x_MD5_Hash ' => strtolower (md5 ('shhh ' . 'user ' . '12345 ' . '10.00 ' )),
77+ )
78+ );
79+ $ this ->request ->setApiLoginId ('user ' );
80+ $ this ->request ->setHashSecret ('shhh ' );
81+
82+ // In the callback, the merchant application sets the amount that
83+ // was expected to be authorised. We expected 20.00 but are being
84+ // told it was 10.00.
85+
86+ $ this ->request ->setAmount ('20.00 ' );
87+
88+ $ response = $ this ->request ->send ();
89+ }
6290}
0 commit comments