@@ -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