diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 62c7023..7bdd628 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ '5.6', '7.0', '7.1','7.2', '7.3', '7.4', '8.0', '8.1' ] + php: [ '7.1','7.2', '7.3', '7.4', '8.0', '8.1' ] stability: [ prefer-stable ] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} diff --git a/src/Item.php b/src/Item.php index 8fa66c0..e2837d2 100644 --- a/src/Item.php +++ b/src/Item.php @@ -6,6 +6,17 @@ class Item extends BaseItem { + public function __toString() + { + return sprintf( + '#%s %d %s x %u', + $this->getName(), + $this->getPrice(), + $this->getCurrency(), + $this->getQuantity() + ); + } + public function getCurrency() { return $this->getParameter('currency') ?: 'TWD'; @@ -25,15 +36,4 @@ public function setUrl($value) { return $this->setParameter('url', $value); } - - public function __toString() - { - return sprintf( - '#%s %d %s x %u', - $this->getName(), - $this->getPrice(), - $this->getCurrency(), - $this->getQuantity() - ); - } } diff --git a/src/Message/AcceptNotificationRequest.php b/src/Message/AcceptNotificationRequest.php index 02465c1..b443044 100644 --- a/src/Message/AcceptNotificationRequest.php +++ b/src/Message/AcceptNotificationRequest.php @@ -2,7 +2,9 @@ namespace Omnipay\ECPay\Message; -class AcceptNotificationRequest extends CompletePurchaseRequest +use Omnipay\Common\Message\NotificationInterface; + +class AcceptNotificationRequest extends CompletePurchaseRequest implements NotificationInterface { /** * @param array $data @@ -12,4 +14,27 @@ public function sendData($data) { return $this->response = new AcceptNotificationResponse($this, $data); } + + public function getTransactionStatus() + { + return $this->getNotificationResponse()->getTransactionStatus(); + } + + public function getMessage() + { + return $this->getNotificationResponse()->getMessage(); + } + + public function getReply() + { + return $this->getNotificationResponse()->getReply(); + } + + /** + * @return AcceptNotificationResponse + */ + private function getNotificationResponse() + { + return ! $this->response ? $this->send() : $this->response; + } } diff --git a/src/Message/AcceptNotificationResponse.php b/src/Message/AcceptNotificationResponse.php index 0e3eda2..51f0c86 100644 --- a/src/Message/AcceptNotificationResponse.php +++ b/src/Message/AcceptNotificationResponse.php @@ -2,14 +2,16 @@ namespace Omnipay\ECPay\Message; -class AcceptNotificationResponse extends CompletePurchaseResponse +use Omnipay\Common\Message\NotificationInterface; + +class AcceptNotificationResponse extends CompletePurchaseResponse implements NotificationInterface { - /** - * Response Message. - * - * @return null|string A response message from the payment gateway - */ - public function getMessage() + public function getTransactionStatus() + { + return $this->isSuccessful() ? self::STATUS_COMPLETED : self::STATUS_FAILED; + } + + public function getReply() { return '1|OK'; } diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php index 9863e31..292f5c9 100644 --- a/src/Message/CompletePurchaseRequest.php +++ b/src/Message/CompletePurchaseRequest.php @@ -7,15 +7,13 @@ use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Exception\InvalidResponseException; use Omnipay\Common\Message\AbstractRequest; -use Omnipay\Common\Message\NotificationInterface; -use Omnipay\Common\Message\ResponseInterface; use Omnipay\ECPay\Traits\HasCustomFields; use Omnipay\ECPay\Traits\HasDefaults; use Omnipay\ECPay\Traits\HasECPay; use Omnipay\ECPay\Traits\HasMerchantTradeNo; use Omnipay\ECPay\Traits\HasStoreID; -class CompletePurchaseRequest extends AbstractRequest implements NotificationInterface +class CompletePurchaseRequest extends AbstractRequest { use HasECPay; use HasDefaults; @@ -239,25 +237,6 @@ public function sendData($data) return $this->response = new CompletePurchaseResponse($this, $data); } - public function getTransactionStatus() - { - return $this->getNotification()->getTransactionStatus(); - } - - public function getMessage() - { - return $this->getNotification()->getMessage(); - } - - /** - * @return ResponseInterface - * @throws InvalidResponseException - */ - private function getNotification() - { - return ! $this->response ? $this->send() : $this->response; - } - /** * @param array $data * @return array diff --git a/src/Message/CompletePurchaseResponse.php b/src/Message/CompletePurchaseResponse.php index aeed035..923f0e8 100644 --- a/src/Message/CompletePurchaseResponse.php +++ b/src/Message/CompletePurchaseResponse.php @@ -2,9 +2,7 @@ namespace Omnipay\ECPay\Message; -use Omnipay\Common\Message\NotificationInterface; - -class CompletePurchaseResponse extends AbstractResponse implements NotificationInterface +class CompletePurchaseResponse extends AbstractResponse { public function isSuccessful() { @@ -20,9 +18,4 @@ public function getMessage() { return $this->data['RtnMsg']; } - - public function getTransactionStatus() - { - return $this->isSuccessful() ? self::STATUS_COMPLETED : self::STATUS_FAILED; - } } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index c84bb13..39b406a 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -90,7 +90,8 @@ public function testAcceptNotification() ]))->send(); self::assertTrue($response->isSuccessful()); - self::assertEquals('1|OK', $response->getMessage()); + self::assertEquals('Succeeded', $response->getMessage()); + self::assertEquals('1|OK', $response->getReply()); } public function testFetchTransaction() diff --git a/tests/Message/AcceptNotificationRequestTest.php b/tests/Message/AcceptNotificationRequestTest.php index c50f0da..5c1e35d 100644 --- a/tests/Message/AcceptNotificationRequestTest.php +++ b/tests/Message/AcceptNotificationRequestTest.php @@ -62,7 +62,8 @@ public function testSendData($results) self::assertEquals($options['MerchantTradeNo'], $notification->getTransactionId()); self::assertEquals($options['TradeNo'], $notification->getTransactionReference()); self::assertEquals(NotificationInterface::STATUS_COMPLETED, $notification->getTransactionStatus()); - self::assertEquals('1|OK', $notification->getMessage()); + self::assertEquals('Succeeded', $notification->getMessage()); + self::assertEquals('1|OK', $notification->getReply()); } public function testInvalidCheckMacValue()