Skip to content

Commit

Permalink
Issue #22 test coverage, some fixes and simplification now much of DP…
Browse files Browse the repository at this point in the history
…M has moved up to SIM.
  • Loading branch information
judgej committed Jul 7, 2015
1 parent 1c6e4d6 commit 21b39c6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 69 deletions.
69 changes: 2 additions & 67 deletions src/Message/DPMCompleteResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,9 @@

namespace Omnipay\AuthorizeNet\Message;

use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RedirectResponseInterface;

/**
* Authorize.Net DPM Complete Authorize Response
* This is the result of handling the callback.
* The result will always be a HTML redirect snippet. This gets
* returned to the gateway, displayed in the user's browser, and a
* redirect is performed using JavaScript and meta refresh (for backup).
* We may want to return to the success page, the failed page or the retry
* page (so the user can correct the form to try again).
* SIM and DPM both have identical needs when handling the notify request.
*/
class DPMCompleteResponse extends SIMCompleteAuthorizeResponse implements RedirectResponseInterface
class DPMCompleteResponse extends SIMCompleteAuthorizeResponse
{
public function isSuccessful()
{
return isset($this->data['x_response_code'])
&& static::RESPONSE_CODE_APPROVED === $this->data['x_response_code'];
}

/**
* If there is an error in the form, then the user should be able to go back
* to the form and give it another shot.
*/
public function isError()
{
return isset($this->data['x_response_code'])
&& static::RESPONSE_CODE_ERROR === $this->data['x_response_code'];
}

/**
* We are in the callback, and we MUST return a HTML fragment to do a redirect.
* All headers we may return are discarded by the gateway, so we cannot use
* the "Location:" header.
*/
public function isRedirect()
{
return true;
}

/**
* We set POST because the default redirect mechanism in Omnipay Common only
* generates a HTML snippet for POST and not for the GET method.
* The redirect method is actually "HTML", where a HTML page is supplied
* to do a redirect using any method it likes.
*/
public function getRedirectMethod()
{
return 'POST';
}

/**
* We probably do not require any redirect data, if the incomplete transaction
* is still in the user's session and we can inspect the results from the saved
* transaction in the database. We cannot send the result through the redirect
* unless it is hashed so the authorisation result cannot be faked.
*/
public function getRedirectData()
{
return array();
}

/**
* The cancel URL is never handled here - that is a direct link from the gateway.
*/
public function getRedirectUrl()
{
// Leave it for the applicatino to decide where to sent the user.
return;
}
}
9 changes: 9 additions & 0 deletions src/Message/SIMCompleteAuthorizeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public function isSuccessful()
return static::RESPONSE_CODE_APPROVED === $this->getCode();
}

/**
* If there is an error in the form, then the user should be able to go back
* to the form and give it another shot.
*/
public function isError()
{
return static::RESPONSE_CODE_ERROR === $this->getCode();
}

public function getTransactionReference()
{
return isset($this->data['x_trans_id']) ? $this->data['x_trans_id'] : null;
Expand Down
1 change: 1 addition & 0 deletions tests/Message/DPMAuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function testSend()
$this->assertSame('https://www.example.com/return', $redirectData['x_relay_url']);
}

// Issue #16 Support notifyUrl
public function testSendNotifyUrl()
{
$this->request->setReturnUrl(null);
Expand Down
12 changes: 11 additions & 1 deletion tests/Message/DPMCompleteRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,27 @@ public function testSend()
'x_trans_id' => '12345',
'x_amount' => '10.00',
'x_MD5_Hash' => strtolower(md5('shhh' . 'user' . '12345' . '10.00')),
'omnipay_transaction_id' => '99',
)
);
$this->request->setApiLoginId('user');
$this->request->setHashSecret('shhh');

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

$this->request->setReturnUrl('http://example.com/');

// Issue #22 Transaction ID in request is picked up from custom field.
$this->assertSame('99', $this->request->getTransactionId());

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

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

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

// In the callback, the merchant application sets the amount that
// In the notify, the merchant application sets the amount that
// was expected to be authorised. We expected 20.00 but are being
// told it was 10.00.

Expand Down
10 changes: 9 additions & 1 deletion tests/Message/SIMCompleteAuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,25 @@ public function testSend()
'x_trans_id' => $posted_trans_id,
'x_amount' => $posted_amount,
'x_MD5_Hash' => md5('shhh' . 'user' . $posted_trans_id . $posted_amount),
'omnipay_transaction_id' => '99',
)
);
$this->request->setApiLoginId('user');
$this->request->setHashSecret('shhh');
$this->request->setAmount('10.00');
//$this->request->setTransactionId(99);
$this->request->setReturnUrl('http://example.com/');

// Issue #22 Transaction ID in request is picked up from custom field.
$this->assertSame('99', $this->request->getTransactionId());

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

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

0 comments on commit 21b39c6

Please sign in to comment.