/** * Tests validateAndParseData method */ public function testValidateAndParseData() { $request = array('data' => 'abcdef', 'sign' => 'qwerty'); $parsed = array('projectid' => 123, 'someparam' => 'qwerty123', 'type' => 'micro'); $this->signer->expects($this->once())->method('checkSign')->with($request)->will($this->returnValue(true)); $this->util->expects($this->at(0))->method('decodeSafeUrlBase64')->with('abcdef')->will($this->returnValue('zxc')); $this->util->expects($this->at(1))->method('parseHttpQuery')->with('zxc')->will($this->returnValue($parsed)); $this->assertEquals($parsed, $this->validator->validateAndParseData($request)); }
/** * 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; }