diff --git a/src/Message/DPMCompleteResponse.php b/src/Message/DPMCompleteResponse.php index eeef08cf..92975509 100644 --- a/src/Message/DPMCompleteResponse.php +++ b/src/Message/DPMCompleteResponse.php @@ -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; - } } diff --git a/src/Message/SIMCompleteAuthorizeResponse.php b/src/Message/SIMCompleteAuthorizeResponse.php index d1933fd7..b32cdd52 100644 --- a/src/Message/SIMCompleteAuthorizeResponse.php +++ b/src/Message/SIMCompleteAuthorizeResponse.php @@ -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; diff --git a/tests/Message/DPMAuthorizeRequestTest.php b/tests/Message/DPMAuthorizeRequestTest.php index 472c1187..1d4157d3 100644 --- a/tests/Message/DPMAuthorizeRequestTest.php +++ b/tests/Message/DPMAuthorizeRequestTest.php @@ -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); diff --git a/tests/Message/DPMCompleteRequestTest.php b/tests/Message/DPMCompleteRequestTest.php index 71c62b08..c22202b5 100644 --- a/tests/Message/DPMCompleteRequestTest.php +++ b/tests/Message/DPMCompleteRequestTest.php @@ -48,6 +48,7 @@ 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'); @@ -55,10 +56,19 @@ public function testSend() $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()); } @@ -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. diff --git a/tests/Message/SIMCompleteAuthorizeRequestTest.php b/tests/Message/SIMCompleteAuthorizeRequestTest.php index 64af2144..840e7424 100644 --- a/tests/Message/SIMCompleteAuthorizeRequestTest.php +++ b/tests/Message/SIMCompleteAuthorizeRequestTest.php @@ -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()); } }