Skip to content

Commit 35a3d58

Browse files
committed
Started adding some tests.
1 parent 1070058 commit 35a3d58

File tree

6 files changed

+124
-2
lines changed

6 files changed

+124
-2
lines changed

src/AIMGateway.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ public function setEndpoints($endpoints)
6262
return $this->setParameter('developerEndpoint', $endpoints['developer']);
6363
}
6464

65+
public function getLiveEndpoint()
66+
{
67+
return $this->getParameter('liveEndpoint');
68+
}
69+
70+
public function setLiveEndpoint($value)
71+
{
72+
return $this->setParameter('liveEndpoint', $value);
73+
}
74+
75+
public function getDeveloperEndpoint()
76+
{
77+
return $this->getParameter('developerEndpoint');
78+
}
79+
80+
public function setDeveloperEndpoint($value)
81+
{
82+
return $this->setParameter('developerEndpoint', $value);
83+
}
84+
6585
public function authorize(array $parameters = array())
6686
{
6787
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest', $parameters);

src/Message/AbstractRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public function setHashSecret($value)
5757
return $this->setParameter('hashSecret', $value);
5858
}
5959

60+
public function getLiveEndpoint()
61+
{
62+
return $this->getParameter('liveEndpoint');
63+
}
64+
6065
public function setLiveEndpoint($value)
6166
{
6267
return $this->setParameter('liveEndpoint', $value);
@@ -67,6 +72,11 @@ public function setDeveloperEndpoint($value)
6772
return $this->setParameter('developerEndpoint', $value);
6873
}
6974

75+
public function getDeveloperEndpoint()
76+
{
77+
return $this->getParameter('developerEndpoint');
78+
}
79+
7080
protected function getBaseData()
7181
{
7282
$data = array();

src/Message/DPMAuthorizeRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ public function getData()
2929

3030
if ($this->getCard()) {
3131
$data['x_card_num'] = $this->getCard()->getNumber();
32+
3233
// Workaround for https://github.com/thephpleague/omnipay-common/issues/29
3334
$expiry_date = $this->getCard()->getExpiryDate('my');
3435
$data['x_exp_date'] = ($expiry_date === '1299' ? '' : $expiry_date);
36+
3537
$data['x_card_code'] = $this->getCard()->getCvv();
3638
} else {
3739
$data['x_card_num'] = '';

src/Message/DPMAuthorizeResponse.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function isTransparentRedirect()
6262
return true;
6363
}
6464

65+
public function isRedirect()
66+
{
67+
return true;
68+
}
69+
6570
// Helpers to build the form.
6671

6772
/**

src/Message/SIMAuthorizeRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function getData()
2222
$data['x_show_form'] = 'PAYMENT_FORM';
2323
$data['x_relay_response'] = 'TRUE';
2424

25-
// The returnUrl MUST be set in Authorize.net admin panel as a
26-
// "Response/Receipt URLs" URL, but not necessarily the default.
25+
// The returnUrl MUST be set in Authorize.net admin panel under
26+
// "Response/Receipt URLs".
2727
$data['x_relay_url'] = $this->getReturnUrl();
2828
$data['x_cancel_url'] = $this->getCancelUrl();
2929

tests/DPMGatewayTest.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet;
4+
5+
use Omnipay\Tests\GatewayTestCase;
6+
//use Omnipay\AuthorizeNet\SIMGatewayTest;
7+
8+
class DPMGatewayTest extends GatewayTestCase //SIMGatewayTest
9+
{
10+
public function setUp()
11+
{
12+
parent::setUp();
13+
14+
$this->gateway = new DPMGateway($this->getHttpClient(), $this->getHttpRequest());
15+
$this->gateway->setApiLoginId('example');
16+
$this->gateway->setTransactionKey('keykey');
17+
$this->gateway->setHashSecret('elpmaxe');
18+
19+
$this->options = array(
20+
'amount' => '10.00',
21+
'transactionId' => '99',
22+
'returnUrl' => 'https://www.example.com/return',
23+
);
24+
}
25+
26+
public function testAuthorize()
27+
{
28+
$response = $this->gateway->authorize($this->options)->send();
29+
30+
$this->assertFalse($response->isSuccessful());
31+
$this->assertTrue($response->isRedirect());
32+
$this->assertNotEmpty($response->getRedirectUrl());
33+
34+
$redirectData = $response->getRedirectData();
35+
$this->assertSame('https://www.example.com/return', $redirectData['x_relay_url']);
36+
}
37+
38+
public function testCompleteAuthorize()
39+
{
40+
$this->getHttpRequest()->request->replace(
41+
array(
42+
'x_response_code' => '1',
43+
'x_trans_id' => '12345',
44+
'x_amount' => '10.00',
45+
'x_MD5_Hash' => md5('elpmaxe' . 'example' . '12345' . '10.00'),
46+
)
47+
);
48+
49+
$response = $this->gateway->completeAuthorize($this->options)->send();
50+
51+
$this->assertTrue($response->isSuccessful());
52+
$this->assertSame('12345', $response->getTransactionReference());
53+
$this->assertNull($response->getMessage());
54+
}
55+
56+
public function testPurchase()
57+
{
58+
$response = $this->gateway->purchase($this->options)->send();
59+
60+
$this->assertFalse($response->isSuccessful());
61+
$this->assertTrue($response->isRedirect());
62+
$this->assertNotEmpty($response->getRedirectUrl());
63+
64+
$redirectData = $response->getRedirectData();
65+
$this->assertSame('https://www.example.com/return', $redirectData['x_relay_url']);
66+
}
67+
68+
public function testCompletePurchase()
69+
{
70+
$this->getHttpRequest()->request->replace(
71+
array(
72+
'x_response_code' => '1',
73+
'x_trans_id' => '12345',
74+
'x_amount' => '10.00',
75+
'x_MD5_Hash' => md5('elpmaxe' . 'example' . '12345' . '10.00'),
76+
)
77+
);
78+
79+
$response = $this->gateway->completePurchase($this->options)->send();
80+
81+
$this->assertTrue($response->isSuccessful());
82+
$this->assertSame('12345', $response->getTransactionReference());
83+
$this->assertNull($response->getMessage());
84+
}
85+
}

0 commit comments

Comments
 (0)