@@ -55,18 +55,21 @@ public function __construct(array $data = [], $key = '', $type = '', $formatted
5555 }
5656
5757 /**
58- * @return string
58+ * @return array| string
5959 */
6060 private function parseResult ()
6161 {
6262 $ result = $ _POST ;
63-
6463 if (empty ($ result ))
6564 $ result = file_get_contents ('php://input ' );
6665 return $ result ;
6766
6867 }
6968
69+ /**
70+ * @param $result
71+ * @return array|string
72+ */
7073 private function formatResult ($ result )
7174 {
7275 if ($ this ->apiVersion === '1.0 ' && is_string ($ result )) {
@@ -78,13 +81,27 @@ private function formatResult($result)
7881 $ result = ResponseHelper::jsonToArray ($ result );
7982 break ;
8083 }
84+ } else if ($ this ->apiVersion === '2.0 ' ) {
85+ $ result = ResponseHelper::jsonToArray ($ result );
8186 }
8287 return $ result ;
8388 }
8489
90+ /**
91+ * Get formatted data
92+ * @return array
93+ */
8594 public function getData ()
8695 {
96+ if (!$ this ->result or $ this ->result == '' )
97+ return [];
98+
99+ if (isset ($ this ->result ['response ' ]))
100+ $ this ->result = $ this ->result ['response ' ];
101+
87102 if ($ this ->apiVersion === '2.0 ' ) {
103+ if (!isset ($ this ->result ['data ' ]))
104+ return [];
88105 $ result = ResponseHelper::getBase64Data (['response ' => $ this ->result ]);
89106 $ result ['encodedData ' ] = $ this ->result ['data ' ];
90107 $ result ['signature ' ] = $ this ->result ['signature ' ];
@@ -113,6 +130,7 @@ public function getToken()
113130 }
114131
115132 /**
133+ * @param $param
116134 * @return bool
117135 */
118136 public function getParam ($ param )
@@ -122,11 +140,13 @@ public function getParam($param)
122140 }
123141
124142 /**
143+ * @param null $data
125144 * @return bool
126145 */
127- public function isValid ()
146+ public function isValid ($ data = null )
128147 {
129- $ data = $ this ->getData ();
148+ if ($ data == null )
149+ $ data = $ this ->getData ();
130150 return ResultHelper::isPaymentValid ($ data , $ this ->secretKey , $ this ->apiVersion );
131151 }
132152
@@ -138,12 +158,11 @@ public function isProcessing()
138158 $ data = $ this ->getData ();
139159 if (!isset ($ data ['order_status ' ]))
140160 return false ;
141- $ valid = $ this ->isValid ();
161+ $ valid = $ this ->isValid ($ data );
142162 if ($ valid && $ data ['order_status ' ] === 'processing ' )
143163 return true ;
144164
145165 return false ;
146-
147166 }
148167
149168 /**
@@ -154,12 +173,11 @@ public function isDeclined()
154173 $ data = $ this ->getData ();
155174 if (!isset ($ data ['order_status ' ]))
156175 return false ;
157- $ valid = $ this ->isValid ();
176+ $ valid = $ this ->isValid ($ data );
158177 if ($ valid && $ data ['order_status ' ] === 'declined ' )
159178 return true ;
160179
161180 return false ;
162-
163181 }
164182
165183 /**
@@ -170,11 +188,10 @@ public function isExpired()
170188 $ data = $ this ->getData ();
171189 if (!isset ($ data ['order_status ' ]))
172190 return false ;
173- $ valid = $ this ->isValid ();
191+ $ valid = $ this ->isValid ($ data );
174192 if ($ valid && $ data ['order_status ' ] === 'expired ' )
175193 return true ;
176194
177195 return false ;
178-
179196 }
180197}
0 commit comments