/** * Test converting {@link HppResponse} to JSON. */ public function testToJsonHppResponse() { $hppResponseExpected = SampleJsonData::generateValidHppResponse(); $json = JsonUtils::toJson($hppResponseExpected); $hppResponseConverted = JsonUtils::fromJsonHppResponse($json); SampleJsonData::checkValidHppResponse($hppResponseExpected, $hppResponseConverted, $this); }
/** * <p> * Method produces JSON from <code>HppResponse</code> object. * Carries out the following actions: * <ul> * <li>Validates inputs</li> * <li>Generates defaults for security hash, order ID and time stamp (if required)</li> * <li>Base64 encodes inputs</li> * <li>Serialises response object to JSON</li> * </ul> * </p> * * @param HppResponse $hppResponse * @return string */ public function responseToJson(HppResponse $hppResponse) { $this->logger->info("Converting HppResponse to JSON."); $json = null; //generate hash $this->logger->debug("Generating hash."); $hppResponse->hash($this->secret); //encode $this->logger->debug("Encoding object."); try { $hppResponse = $hppResponse->encode(self::ENCODING_CHARSET); } catch (Exception $e) { $this->logger->error("Exception encoding HPP response.", $e); throw new RealexException("Exception encoding HPP response.", $e); } //convert to JSON $this->logger->debug("Converting to JSON."); $json = JsonUtils::toJson($hppResponse); return $json; }