From bf55748858a7c0de9c5e3c6bb2d520d82a9f50db Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Wed, 12 Dec 2018 00:27:03 +0000 Subject: [PATCH] Issue #124 implement isSuccessful() with acceptNotification --- src/Message/Response.php | 11 ----------- src/Traits/ResponseFieldsTrait.php | 11 +++++++++++ tests/Message/ServerNotifyRequestTest.php | 6 ++++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Message/Response.php b/src/Message/Response.php index 5960f99..34d54d3 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -15,17 +15,6 @@ class Response extends AbstractResponse implements RedirectResponseInterface, Co { use ResponseFieldsTrait; - /** - * @return bool True if the transaction is successful and complete. - */ - public function isSuccessful() - { - return $this->getStatus() === static::SAGEPAY_STATUS_OK - || $this->getStatus() === static::SAGEPAY_STATUS_OK_REPEATED - || $this->getStatus() === static::SAGEPAY_STATUS_REGISTERED - || $this->getStatus() === static::SAGEPAY_STATUS_AUTHENTICATED; - } - /** * Gateway Reference * diff --git a/src/Traits/ResponseFieldsTrait.php b/src/Traits/ResponseFieldsTrait.php index 29ec068..a14525a 100644 --- a/src/Traits/ResponseFieldsTrait.php +++ b/src/Traits/ResponseFieldsTrait.php @@ -23,6 +23,17 @@ protected function getDataItem($name, $default = null) return isset($this->data[$name]) ? $this->data[$name] : $default; } + /** + * @return bool True if the transaction is successful and complete. + */ + public function isSuccessful() + { + return $this->getStatus() === static::SAGEPAY_STATUS_OK + || $this->getStatus() === static::SAGEPAY_STATUS_OK_REPEATED + || $this->getStatus() === static::SAGEPAY_STATUS_REGISTERED + || $this->getStatus() === static::SAGEPAY_STATUS_AUTHENTICATED; + } + /** * Get the cardReference generated when creating a card reference * during an authorisation or payment, or as an explicit request. diff --git a/tests/Message/ServerNotifyRequestTest.php b/tests/Message/ServerNotifyRequestTest.php index 0445318..37f70ae 100644 --- a/tests/Message/ServerNotifyRequestTest.php +++ b/tests/Message/ServerNotifyRequestTest.php @@ -100,6 +100,12 @@ public function testServerNotifyResponseSuccess() "Status=OK\r\nRedirectUrl=https://www.example.com/\r\nStatusDetail=detail" ); $this->request->confirm('https://www.example.com/', 'detail'); + + // Issue https://github.com/thephpleague/omnipay-sagepay/issues/124 + // The isSuccessful() method is moved to the trait that shares many + // common response fields with the notification server request. + + $this->assertTrue($this->request->isSuccessful()); } public function testServerNotifyRequestFailure()