@@ -13,6 +13,10 @@ class Response
1313 * @var string
1414 */
1515 protected $ orderID ;
16+ /**
17+ * @var string
18+ */
19+ protected $ paymentKey ;
1620 /**
1721 * @var string
1822 */
@@ -29,15 +33,17 @@ class Response
2933 /**
3034 * Response constructor.
3135 * @param $data
36+ * @param $type
3237 * @throws ApiException
3338 */
34- public function __construct ($ data )
39+ public function __construct ($ data, $ type = '' )
3540 {
3641 if (isset ($ data ['order_id ' ]))
3742 $ this ->orderID = $ data ['order_id ' ];
3843 $ data = $ data ['response ' ];
3944 $ this ->requestType = Configuration::getRequestType ();
4045 $ this ->apiVersion = Configuration::getApiVersion ();
46+ $ this ->setKeyByOperationType ($ type );
4147 switch ($ this ->requestType ) {
4248 case 'xml ' :
4349 $ response = ResponseHelper::xmlToArray ($ data );
@@ -144,7 +150,7 @@ public function getOrderID()
144150 public function isApproved ()
145151 {
146152 $ data = $ this ->buildVerifyData ();
147- return ResultHelper::isPaymentApproved ($ data , '' , $ this ->apiVersion );
153+ return ResultHelper::isPaymentApproved ($ data , $ this -> paymentKey , $ this ->apiVersion );
148154 }
149155
150156 /**
@@ -154,6 +160,19 @@ public function isApproved()
154160 public function isValid ()
155161 {
156162 $ data = $ this ->buildVerifyData ();
157- return ResultHelper::isPaymentValid ($ data , '' , $ this ->apiVersion );
163+ return ResultHelper::isPaymentValid ($ data , $ this ->paymentKey , $ this ->apiVersion );
164+ }
165+
166+ /**
167+ * setting secret key by operation type
168+ * @param $type
169+ */
170+ protected function setKeyByOperationType ($ type = '' )
171+ {
172+ if ($ type === 'credit ' ) {
173+ $ this ->paymentKey = Configuration::getCreditKey ();
174+ } else {
175+ $ this ->paymentKey = Configuration::getSecretKey ();
176+ }
158177 }
159178}
0 commit comments