|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\AuthorizeNet\Message; |
| 4 | + |
| 5 | +use Omnipay\Tests\TestCase; |
| 6 | + |
| 7 | +class DPMAuthorizeRequestTest extends TestCase |
| 8 | +{ |
| 9 | + public function setUp() |
| 10 | + { |
| 11 | + $this->request = new DPMAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); |
| 12 | + $this->request->initialize( |
| 13 | + array( |
| 14 | + 'clientIp' => '10.0.0.1', |
| 15 | + 'amount' => '12.00', |
| 16 | + 'returnUrl' => 'https://www.example.com/return', |
| 17 | + 'liveEndpoint' => 'https://secure.authorize.net/gateway/transact.dll', |
| 18 | + 'developerEndpoint' => 'https://test.authorize.net/gateway/transact.dll', |
| 19 | + ) |
| 20 | + ); |
| 21 | + } |
| 22 | + |
| 23 | + public function testGetData() |
| 24 | + { |
| 25 | + $data = $this->request->getData(); |
| 26 | + |
| 27 | + $this->assertSame('AUTH_ONLY', $data['x_type']); |
| 28 | + $this->assertArrayNotHasKey('x_show_form', $data); |
| 29 | + $this->assertArrayNotHasKey('x_test_request', $data); |
| 30 | + } |
| 31 | + |
| 32 | + public function testGetDataTestMode() |
| 33 | + { |
| 34 | + $this->request->setTestMode(true); |
| 35 | + |
| 36 | + $data = $this->request->getData(); |
| 37 | + |
| 38 | + $this->assertSame('TRUE', $data['x_test_request']); |
| 39 | + } |
| 40 | + |
| 41 | + public function testGetHash() |
| 42 | + { |
| 43 | + $this->request->setApiLoginId('user'); |
| 44 | + $this->request->setTransactionKey('key'); |
| 45 | + $data = array( |
| 46 | + 'x_fp_sequence' => 'a', |
| 47 | + 'x_fp_timestamp' => 'b', |
| 48 | + 'x_amount' => 'c', |
| 49 | + ); |
| 50 | + |
| 51 | + $expected = hash_hmac('md5', 'user^a^b^c^', 'key'); |
| 52 | + |
| 53 | + $this->assertSame($expected, $this->request->getHash($data)); |
| 54 | + } |
| 55 | + |
| 56 | + public function testSend() |
| 57 | + { |
| 58 | + $response = $this->request->send(); |
| 59 | + |
| 60 | + $this->assertFalse($response->isSuccessful()); |
| 61 | + $this->assertTrue($response->isRedirect()); |
| 62 | + $this->assertNotEmpty($response->getRedirectUrl()); |
| 63 | + $this->assertSame('POST', $response->getRedirectMethod()); |
| 64 | + |
| 65 | + $redirectData = $response->getRedirectData(); |
| 66 | + $this->assertSame('https://www.example.com/return', $redirectData['x_relay_url']); |
| 67 | + } |
| 68 | +} |
0 commit comments