Skip to content

Commit 8ffcf62

Browse files
committed
feat: get reply
1 parent 5b45f02 commit 8ffcf62

File tree

8 files changed

+53
-52
lines changed

8 files changed

+53
-52
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: true
1111
matrix:
12-
php: [ '5.6', '7.0', '7.1','7.2', '7.3', '7.4', '8.0', '8.1' ]
12+
php: [ '7.1','7.2', '7.3', '7.4', '8.0', '8.1' ]
1313
stability: [ prefer-stable ]
1414

1515
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

src/Item.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66

77
class Item extends BaseItem
88
{
9+
public function __toString()
10+
{
11+
return sprintf(
12+
'#%s %d %s x %u',
13+
$this->getName(),
14+
$this->getPrice(),
15+
$this->getCurrency(),
16+
$this->getQuantity()
17+
);
18+
}
19+
920
public function getCurrency()
1021
{
1122
return $this->getParameter('currency') ?: 'TWD';
@@ -25,15 +36,4 @@ public function setUrl($value)
2536
{
2637
return $this->setParameter('url', $value);
2738
}
28-
29-
public function __toString()
30-
{
31-
return sprintf(
32-
'#%s %d %s x %u',
33-
$this->getName(),
34-
$this->getPrice(),
35-
$this->getCurrency(),
36-
$this->getQuantity()
37-
);
38-
}
3939
}

src/Message/AcceptNotificationRequest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Omnipay\ECPay\Message;
44

5-
class AcceptNotificationRequest extends CompletePurchaseRequest
5+
use Omnipay\Common\Message\NotificationInterface;
6+
7+
class AcceptNotificationRequest extends CompletePurchaseRequest implements NotificationInterface
68
{
79
/**
810
* @param array $data
@@ -12,4 +14,27 @@ public function sendData($data)
1214
{
1315
return $this->response = new AcceptNotificationResponse($this, $data);
1416
}
17+
18+
public function getTransactionStatus()
19+
{
20+
return $this->getNotificationResponse()->getTransactionStatus();
21+
}
22+
23+
public function getMessage()
24+
{
25+
return $this->getNotificationResponse()->getMessage();
26+
}
27+
28+
public function getReply()
29+
{
30+
return $this->getNotificationResponse()->getReply();
31+
}
32+
33+
/**
34+
* @return AcceptNotificationResponse
35+
*/
36+
private function getNotificationResponse()
37+
{
38+
return ! $this->response ? $this->send() : $this->response;
39+
}
1540
}

src/Message/AcceptNotificationResponse.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace Omnipay\ECPay\Message;
44

5-
class AcceptNotificationResponse extends CompletePurchaseResponse
5+
use Omnipay\Common\Message\NotificationInterface;
6+
7+
class AcceptNotificationResponse extends CompletePurchaseResponse implements NotificationInterface
68
{
7-
/**
8-
* Response Message.
9-
*
10-
* @return null|string A response message from the payment gateway
11-
*/
12-
public function getMessage()
9+
public function getTransactionStatus()
10+
{
11+
return $this->isSuccessful() ? self::STATUS_COMPLETED : self::STATUS_FAILED;
12+
}
13+
14+
public function getReply()
1315
{
1416
return '1|OK';
1517
}

src/Message/CompletePurchaseRequest.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
use Omnipay\Common\Exception\InvalidRequestException;
88
use Omnipay\Common\Exception\InvalidResponseException;
99
use Omnipay\Common\Message\AbstractRequest;
10-
use Omnipay\Common\Message\NotificationInterface;
11-
use Omnipay\Common\Message\ResponseInterface;
1210
use Omnipay\ECPay\Traits\HasCustomFields;
1311
use Omnipay\ECPay\Traits\HasDefaults;
1412
use Omnipay\ECPay\Traits\HasECPay;
1513
use Omnipay\ECPay\Traits\HasMerchantTradeNo;
1614
use Omnipay\ECPay\Traits\HasStoreID;
1715

18-
class CompletePurchaseRequest extends AbstractRequest implements NotificationInterface
16+
class CompletePurchaseRequest extends AbstractRequest
1917
{
2018
use HasECPay;
2119
use HasDefaults;
@@ -239,25 +237,6 @@ public function sendData($data)
239237
return $this->response = new CompletePurchaseResponse($this, $data);
240238
}
241239

242-
public function getTransactionStatus()
243-
{
244-
return $this->getNotification()->getTransactionStatus();
245-
}
246-
247-
public function getMessage()
248-
{
249-
return $this->getNotification()->getMessage();
250-
}
251-
252-
/**
253-
* @return ResponseInterface
254-
* @throws InvalidResponseException
255-
*/
256-
private function getNotification()
257-
{
258-
return ! $this->response ? $this->send() : $this->response;
259-
}
260-
261240
/**
262241
* @param array $data
263242
* @return array

src/Message/CompletePurchaseResponse.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Omnipay\ECPay\Message;
44

5-
use Omnipay\Common\Message\NotificationInterface;
6-
7-
class CompletePurchaseResponse extends AbstractResponse implements NotificationInterface
5+
class CompletePurchaseResponse extends AbstractResponse
86
{
97
public function isSuccessful()
108
{
@@ -20,9 +18,4 @@ public function getMessage()
2018
{
2119
return $this->data['RtnMsg'];
2220
}
23-
24-
public function getTransactionStatus()
25-
{
26-
return $this->isSuccessful() ? self::STATUS_COMPLETED : self::STATUS_FAILED;
27-
}
2821
}

tests/GatewayTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public function testAcceptNotification()
9090
]))->send();
9191

9292
self::assertTrue($response->isSuccessful());
93-
self::assertEquals('1|OK', $response->getMessage());
93+
self::assertEquals('Succeeded', $response->getMessage());
94+
self::assertEquals('1|OK', $response->getReply());
9495
}
9596

9697
public function testFetchTransaction()

tests/Message/AcceptNotificationRequestTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public function testSendData($results)
6262
self::assertEquals($options['MerchantTradeNo'], $notification->getTransactionId());
6363
self::assertEquals($options['TradeNo'], $notification->getTransactionReference());
6464
self::assertEquals(NotificationInterface::STATUS_COMPLETED, $notification->getTransactionStatus());
65-
self::assertEquals('1|OK', $notification->getMessage());
65+
self::assertEquals('Succeeded', $notification->getMessage());
66+
self::assertEquals('1|OK', $notification->getReply());
6667
}
6768

6869
public function testInvalidCheckMacValue()

0 commit comments

Comments
 (0)