File tree Expand file tree Collapse file tree 9 files changed +141
-5
lines changed Expand file tree Collapse file tree 9 files changed +141
-5
lines changed Original file line number Diff line number Diff line change 10
10
use Omnipay \ECPay \Message \FetchTransactionRequest ;
11
11
use Omnipay \ECPay \Message \PurchaseRequest ;
12
12
use Omnipay \ECPay \Message \RefundRequest ;
13
+ use Omnipay \ECPay \Message \VoidRequest ;
13
14
use Omnipay \ECPay \Traits \HasDefaults ;
14
15
15
16
/**
16
17
* Skeleton Gateway.
17
18
* @method RequestInterface authorize(array $options = [])
18
19
* @method RequestInterface completeAuthorize(array $options = [])
19
20
* @method RequestInterface capture(array $options = [])
20
- * @method RequestInterface void(array $options = [])
21
21
* @method RequestInterface createCard(array $options = [])
22
22
* @method RequestInterface updateCard(array $options = [])
23
23
* @method RequestInterface deleteCard(array $options = [])
@@ -86,4 +86,9 @@ public function refund(array $options = [])
86
86
{
87
87
return $ this ->createRequest (RefundRequest::class, $ options );
88
88
}
89
+
90
+ public function void (array $ options = [])
91
+ {
92
+ return $ this ->createRequest (VoidRequest::class, $ options );
93
+ }
89
94
}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public function getTradeNo()
28
28
29
29
public function getData ()
30
30
{
31
- $ this ->validate ('transactionId ' , 'transactionReference ' );
31
+ $ this ->validate ('transactionId ' , 'transactionReference ' , ' amount ' );
32
32
33
33
return [
34
34
'MerchantTradeNo ' => $ this ->getTransactionId (),
@@ -40,7 +40,7 @@ public function getData()
40
40
41
41
public function sendData ($ data )
42
42
{
43
- return $ this ->response = new RefundResponse ($ this , $ this ->doAction ($ data ));
43
+ return $ this ->response = new VoidOrRefundResponse ($ this , $ this ->doAction ($ data ));
44
44
}
45
45
46
46
/**
Original file line number Diff line number Diff line change 2
2
3
3
namespace Omnipay \ECPay \Message ;
4
4
5
- class RefundResponse extends AbstractResponse
5
+ class VoidOrRefundResponse extends AbstractResponse
6
6
{
7
7
/**
8
8
* Is the response successful?
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Omnipay \ECPay \Message ;
4
+
5
+ use ECPay_ActionType ;
6
+
7
+ class VoidRequest extends RefundRequest
8
+ {
9
+ public function setAction ($ value )
10
+ {
11
+ return $ this ->setParameter ('action ' , $ value );
12
+ }
13
+
14
+ public function getAction ()
15
+ {
16
+ return $ this ->getParameter ('action ' ) ?: ECPay_ActionType::N;
17
+ }
18
+
19
+ public function getData ()
20
+ {
21
+ $ this ->validate ('transactionId ' , 'transactionReference ' , 'amount ' );
22
+
23
+ return [
24
+ 'MerchantTradeNo ' => $ this ->getTransactionId (),
25
+ 'TradeNo ' => $ this ->getTransactionReference (),
26
+ 'Action ' => $ this ->getAction (),
27
+ 'TotalAmount ' => $ this ->getAmount (),
28
+ ];
29
+ }
30
+ }
Original file line number Diff line number Diff line change @@ -114,7 +114,20 @@ public function testRefund()
114
114
]))->send ();
115
115
116
116
self ::assertTrue ($ response ->isSuccessful ());
117
+ self ::assertEquals ('1909021549160081 ' , $ response ->getTransactionReference ());
118
+ self ::assertEquals ('2821567410556 ' , $ response ->getTransactionId ());
119
+ }
120
+
121
+ public function testVoid ()
122
+ {
123
+ $ response = $ this ->gateway ->void (array_merge ($ this ->options , [
124
+ 'transactionReference ' => '1909021549160081 ' ,
125
+ 'transactionId ' => '2821567410556 ' ,
126
+ 'amount ' => 1000 ,
127
+ ]))->send ();
128
+
117
129
self ::assertTrue ($ response ->isSuccessful ());
118
- self ::assertTrue ($ response ->isSuccessful ());
130
+ self ::assertEquals ('1909021549160081 ' , $ response ->getTransactionReference ());
131
+ self ::assertEquals ('2821567410556 ' , $ response ->getTransactionId ());
119
132
}
120
133
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Omnipay \ECPay \Tests \Message ;
4
+
5
+ use Omnipay \ECPay \Tests \Stubs \StubRefundRequest ;
6
+ use Omnipay \Tests \TestCase ;
7
+
8
+ class RefundRequestTest extends TestCase
9
+ {
10
+ public function testGetData ()
11
+ {
12
+ $ options = [
13
+ 'MerchantID ' => '2000132 ' ,
14
+ 'MerchantTradeNo ' => '2821567410556 ' ,
15
+ 'TradeNo ' => '1909021549160081 ' ,
16
+ 'TotalAmount ' => 1000 ,
17
+ ];
18
+ $ request = new StubRefundRequest ($ this ->getHttpClient (), $ this ->getHttpRequest ());
19
+ $ request ->initialize ($ options );
20
+
21
+ self ::assertEquals ([
22
+ 'MerchantTradeNo ' => '2821567410556 ' ,
23
+ 'TradeNo ' => '1909021549160081 ' ,
24
+ 'Action ' => 'R ' ,
25
+ 'TotalAmount ' => '1000.00 ' ,
26
+ ], $ request ->getData ());
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Omnipay \ECPay \Tests \Message ;
4
+
5
+ use Omnipay \ECPay \Tests \Stubs \StubVoidRequest ;
6
+ use Omnipay \Tests \TestCase ;
7
+
8
+ class VoidRequestTest extends TestCase
9
+ {
10
+ public function testGetData ()
11
+ {
12
+ $ options = [
13
+ 'MerchantID ' => '2000132 ' ,
14
+ 'MerchantTradeNo ' => '2821567410556 ' ,
15
+ 'TradeNo ' => '1909021549160081 ' ,
16
+ 'TotalAmount ' => 1000 ,
17
+ ];
18
+ $ request = new StubVoidRequest ($ this ->getHttpClient (), $ this ->getHttpRequest ());
19
+ $ request ->initialize ($ options );
20
+
21
+ self ::assertEquals ([
22
+ 'MerchantTradeNo ' => '2821567410556 ' ,
23
+ 'TradeNo ' => '1909021549160081 ' ,
24
+ 'Action ' => 'N ' ,
25
+ 'TotalAmount ' => '1000.00 ' ,
26
+ ], $ request ->getData ());
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -24,4 +24,13 @@ public function refund(array $options = [])
24
24
{
25
25
return $ this ->createRequest (StubRefundRequest::class, $ options );
26
26
}
27
+
28
+ /**
29
+ * @param array $options
30
+ * @return RequestInterface
31
+ */
32
+ public function void (array $ options = [])
33
+ {
34
+ return $ this ->createRequest (StubVoidRequest::class, $ options );
35
+ }
27
36
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Omnipay \ECPay \Tests \Stubs ;
4
+
5
+ use Omnipay \ECPay \Message \VoidRequest ;
6
+
7
+ class StubVoidRequest extends VoidRequest
8
+ {
9
+ /**
10
+ * @param array $data
11
+ * @return array
12
+ */
13
+ protected function doAction ($ data )
14
+ {
15
+ return [
16
+ 'MerchantID ' => $ this ->getMerchantID (),
17
+ 'MerchantTradeNo ' => $ data ['MerchantTradeNo ' ],
18
+ 'TradeNo ' => $ data ['TradeNo ' ],
19
+ 'RtnCode ' => '1 ' ,
20
+ 'RtnMsg ' => '' ,
21
+ ];
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments