/** * Tests that encode and decode are compatible */ public function testEncodeAndDecodeAreCompatible() { $values = array('Some long string with UTF-8 ąččėę проверка', "Some binary symbols �������\n ", 'Some other symbols %=?/-_)22Wq'); foreach ($values as $text) { $this->assertEquals($text, $this->util->decodeSafeUrlBase64($this->util->encodeSafeUrlBase64($text))); } }
/** * Checks signature * * @param array $request * * @return boolean * * @throws WebToPay_Exception_Callback */ public function checkSign(array $request) { if (!isset($request['data']) || !isset($request['ss2'])) { throw new WebToPay_Exception_Callback('Not enough parameters in callback. Possible version mismatch'); } $ss2 = $this->util->decodeSafeUrlBase64($request['ss2']); $ok = openssl_verify($request['data'], $ss2, $this->publicKey); return $ok === 1; }
/** * Parses callback parameters from query parameters and checks if sign is correct. * Request has parameter "data", which is signed and holds all callback parameters * * @param array $requestData * * @return array Parsed callback parameters * * @throws WebToPayException * @throws WebToPay_Exception_Callback */ public function validateAndParseData(array $requestData) { if (!$this->signer->checkSign($requestData)) { throw new WebToPay_Exception_Callback('Invalid sign parameters, check $_GET length limit'); } if (!isset($requestData['data'])) { throw new WebToPay_Exception_Callback('"data" parameter not found'); } $data = $requestData['data']; $queryString = $this->util->decodeSafeUrlBase64($data); $request = $this->util->parseHttpQuery($queryString); if (!isset($request['projectid'])) { throw new WebToPay_Exception_Callback('Project ID not provided in callback', WebToPayException::E_INVALID); } if ((string) $request['projectid'] !== (string) $this->projectId) { throw new WebToPay_Exception_Callback(sprintf('Bad projectid: %s, should be: %s', $request['projectid'], $this->projectId), WebToPayException::E_INVALID); } if (!isset($request['type']) || !in_array($request['type'], array('micro', 'macro'))) { $micro = isset($request['to']) && isset($request['from']) && isset($request['sms']); $request['type'] = $micro ? 'micro' : 'macro'; } return $request; }