Skip to content

Commit

Permalink
feat: get reply
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed May 3, 2022
1 parent 5b45f02 commit 8ffcf62
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
22 changes: 11 additions & 11 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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()
);
}
}
27 changes: 26 additions & 1 deletion src/Message/AcceptNotificationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
16 changes: 9 additions & 7 deletions src/Message/AcceptNotificationResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
23 changes: 1 addition & 22 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions src/Message/CompletePurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -20,9 +18,4 @@ public function getMessage()
{
return $this->data['RtnMsg'];
}

public function getTransactionStatus()
{
return $this->isSuccessful() ? self::STATUS_COMPLETED : self::STATUS_FAILED;
}
}
3 changes: 2 additions & 1 deletion tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/Message/AcceptNotificationRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8ffcf62

Please sign in to comment.