1818
1919namespace Paynl \Result \Transaction ;
2020
21- use Paynl \Result \Result ;
2221use Paynl \Error \Error ;
22+ use Paynl \Result \Result ;
23+
2324/**
2425 * Description of Transaction
2526 *
2627 * @author Andy Pieters <andy@pay.nl>
2728 */
2829class Transaction extends Result
2930{
30- /**
31- * @return string The transaction id
32- */
33- public function getId ()
34- {
35- return $ this ->data ['transactionId ' ];
36- }
37-
3831 /**
3932 * @return bool Transaction is paid
4033 */
@@ -69,6 +62,24 @@ public function isCanceled()
6962 return $ this ->data ['paymentDetails ' ]['state ' ] < 0 ;
7063 }
7164
65+ public function isAuthorized ()
66+ {
67+ return $ this ->data ['paymentDetails ' ]['state ' ] == 95 ;
68+ }
69+
70+ public function void (){
71+ if (!$ this ->isAuthorized ()){
72+ throw new Error ('Cannod void transaction, status is not authorized ' );
73+ }
74+ return \Paynl \Transaction::void ($ this ->getId ());
75+ }
76+ public function capture (){
77+ if (!$ this ->isAuthorized ()){
78+ throw new Error ('Cannod capture transaction, status is not authorized ' );
79+ }
80+ return \Paynl \Transaction::capture ($ this ->getId ());
81+ }
82+
7283 /**
7384 * @param bool|true $allowPartialRefunds
7485 *
@@ -95,14 +106,6 @@ public function isPartiallyRefunded()
95106 return $ this ->data ['paymentDetails ' ]['stateName ' ] == 'PARTIAL_REFUND ' ;
96107 }
97108
98- /**
99- * @return bool
100- */
101- public function isBeingVerified ()
102- {
103- return $ this ->data ['paymentDetails ' ]['stateName ' ] == 'VERIFY ' ;
104- }
105-
106109 /**
107110 * @return float Paid amount in original currency
108111 */
@@ -191,13 +194,9 @@ public function getExtra3()
191194 return $ this ->data ['statsDetails ' ]['extra3 ' ];
192195 }
193196
194- private function _reload (){
195- $ result = \Paynl \Transaction::get ($ this ->getId ());
196- $ this ->data = $ result ->getData ();
197- }
198-
199- public function approve (){
200- if ($ this ->isBeingVerified ()){
197+ public function approve ()
198+ {
199+ if ($ this ->isBeingVerified ()) {
201200 $ result = \Paynl \Transaction::approve ($ this ->getId ());
202201 $ this ->_reload (); //status is changed, so refresh the object
203202 return $ result ;
@@ -206,8 +205,31 @@ public function approve(){
206205 }
207206 }
208207
209- public function decline (){
210- if ($ this ->isBeingVerified ()){
208+ /**
209+ * @return bool
210+ */
211+ public function isBeingVerified ()
212+ {
213+ return $ this ->data ['paymentDetails ' ]['stateName ' ] == 'VERIFY ' ;
214+ }
215+
216+ /**
217+ * @return string The transaction id
218+ */
219+ public function getId ()
220+ {
221+ return $ this ->data ['transactionId ' ];
222+ }
223+
224+ private function _reload ()
225+ {
226+ $ result = \Paynl \Transaction::get ($ this ->getId ());
227+ $ this ->data = $ result ->getData ();
228+ }
229+
230+ public function decline ()
231+ {
232+ if ($ this ->isBeingVerified ()) {
211233 $ result = \Paynl \Transaction::decline ($ this ->getId ());
212234 $ this ->_reload ();//status is changed, so refresh the object
213235 return $ result ;
0 commit comments