Skip to content

Commit 21b39c6

Browse files
committed
Issue thephpleague#22 test coverage, some fixes and simplification now much of DPM has moved up to SIM.
1 parent 1c6e4d6 commit 21b39c6

File tree

5 files changed

+32
-69
lines changed

5 files changed

+32
-69
lines changed

src/Message/DPMCompleteResponse.php

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,9 @@
22

33
namespace Omnipay\AuthorizeNet\Message;
44

5-
use Omnipay\Common\Message\AbstractResponse;
6-
use Omnipay\Common\Message\RedirectResponseInterface;
7-
85
/**
9-
* Authorize.Net DPM Complete Authorize Response
10-
* This is the result of handling the callback.
11-
* The result will always be a HTML redirect snippet. This gets
12-
* returned to the gateway, displayed in the user's browser, and a
13-
* redirect is performed using JavaScript and meta refresh (for backup).
14-
* We may want to return to the success page, the failed page or the retry
15-
* page (so the user can correct the form to try again).
6+
* SIM and DPM both have identical needs when handling the notify request.
167
*/
17-
class DPMCompleteResponse extends SIMCompleteAuthorizeResponse implements RedirectResponseInterface
8+
class DPMCompleteResponse extends SIMCompleteAuthorizeResponse
189
{
19-
public function isSuccessful()
20-
{
21-
return isset($this->data['x_response_code'])
22-
&& static::RESPONSE_CODE_APPROVED === $this->data['x_response_code'];
23-
}
24-
25-
/**
26-
* If there is an error in the form, then the user should be able to go back
27-
* to the form and give it another shot.
28-
*/
29-
public function isError()
30-
{
31-
return isset($this->data['x_response_code'])
32-
&& static::RESPONSE_CODE_ERROR === $this->data['x_response_code'];
33-
}
34-
35-
/**
36-
* We are in the callback, and we MUST return a HTML fragment to do a redirect.
37-
* All headers we may return are discarded by the gateway, so we cannot use
38-
* the "Location:" header.
39-
*/
40-
public function isRedirect()
41-
{
42-
return true;
43-
}
44-
45-
/**
46-
* We set POST because the default redirect mechanism in Omnipay Common only
47-
* generates a HTML snippet for POST and not for the GET method.
48-
* The redirect method is actually "HTML", where a HTML page is supplied
49-
* to do a redirect using any method it likes.
50-
*/
51-
public function getRedirectMethod()
52-
{
53-
return 'POST';
54-
}
55-
56-
/**
57-
* We probably do not require any redirect data, if the incomplete transaction
58-
* is still in the user's session and we can inspect the results from the saved
59-
* transaction in the database. We cannot send the result through the redirect
60-
* unless it is hashed so the authorisation result cannot be faked.
61-
*/
62-
public function getRedirectData()
63-
{
64-
return array();
65-
}
66-
67-
/**
68-
* The cancel URL is never handled here - that is a direct link from the gateway.
69-
*/
70-
public function getRedirectUrl()
71-
{
72-
// Leave it for the applicatino to decide where to sent the user.
73-
return;
74-
}
7510
}

src/Message/SIMCompleteAuthorizeResponse.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public function isSuccessful()
2323
return static::RESPONSE_CODE_APPROVED === $this->getCode();
2424
}
2525

26+
/**
27+
* If there is an error in the form, then the user should be able to go back
28+
* to the form and give it another shot.
29+
*/
30+
public function isError()
31+
{
32+
return static::RESPONSE_CODE_ERROR === $this->getCode();
33+
}
34+
2635
public function getTransactionReference()
2736
{
2837
return isset($this->data['x_trans_id']) ? $this->data['x_trans_id'] : null;

tests/Message/DPMAuthorizeRequestTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function testSend()
6666
$this->assertSame('https://www.example.com/return', $redirectData['x_relay_url']);
6767
}
6868

69+
// Issue #16 Support notifyUrl
6970
public function testSendNotifyUrl()
7071
{
7172
$this->request->setReturnUrl(null);

tests/Message/DPMCompleteRequestTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,27 @@ public function testSend()
4848
'x_trans_id' => '12345',
4949
'x_amount' => '10.00',
5050
'x_MD5_Hash' => strtolower(md5('shhh' . 'user' . '12345' . '10.00')),
51+
'omnipay_transaction_id' => '99',
5152
)
5253
);
5354
$this->request->setApiLoginId('user');
5455
$this->request->setHashSecret('shhh');
5556

5657
$this->request->setAmount('10.00');
5758

59+
$this->request->setReturnUrl('http://example.com/');
60+
61+
// Issue #22 Transaction ID in request is picked up from custom field.
62+
$this->assertSame('99', $this->request->getTransactionId());
63+
5864
$response = $this->request->send();
5965

6066
$this->assertTrue($response->isSuccessful());
6167
$this->assertSame('12345', $response->getTransactionReference());
68+
$this->assertSame(true, $response->isRedirect());
69+
// CHECKME: does it matter what letter case the method is?
70+
$this->assertSame('GET', $response->getRedirectMethod());
71+
$this->assertSame('http://example.com/', $response->getRedirectUrl());
6272
$this->assertNull($response->getMessage());
6373
}
6474

@@ -79,7 +89,7 @@ public function testSendWrongAmount()
7989
$this->request->setApiLoginId('user');
8090
$this->request->setHashSecret('shhh');
8191

82-
// In the callback, the merchant application sets the amount that
92+
// In the notify, the merchant application sets the amount that
8393
// was expected to be authorised. We expected 20.00 but are being
8494
// told it was 10.00.
8595

tests/Message/SIMCompleteAuthorizeRequestTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,25 @@ public function testSend()
4242
'x_trans_id' => $posted_trans_id,
4343
'x_amount' => $posted_amount,
4444
'x_MD5_Hash' => md5('shhh' . 'user' . $posted_trans_id . $posted_amount),
45+
'omnipay_transaction_id' => '99',
4546
)
4647
);
4748
$this->request->setApiLoginId('user');
4849
$this->request->setHashSecret('shhh');
4950
$this->request->setAmount('10.00');
50-
//$this->request->setTransactionId(99);
51+
$this->request->setReturnUrl('http://example.com/');
52+
53+
// Issue #22 Transaction ID in request is picked up from custom field.
54+
$this->assertSame('99', $this->request->getTransactionId());
5155

5256
$response = $this->request->send();
5357

5458
$this->assertTrue($response->isSuccessful());
5559
$this->assertSame($posted_trans_id, $response->getTransactionReference());
60+
$this->assertSame(true, $response->isRedirect());
61+
// CHECKME: does it matter what letter case the method is?
62+
$this->assertSame('GET', $response->getRedirectMethod());
63+
$this->assertSame('http://example.com/', $response->getRedirectUrl());
5664
$this->assertNull($response->getMessage());
5765
}
5866
}

0 commit comments

Comments
 (0)