/** * Test converting {@link HppRequest} to JSON. * Testing import from json, decode and encode */ public function testToJsonHppRequestWithHppVersion() { $path = SampleJsonData::VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH; $prefix = __DIR__ . '/../../../resources'; $json = file_get_contents($prefix . $path); /** * @var HppRequest $hppRequestConverted */ $hppRequestConverted = JsonUtils::fromJsonHppRequest($json); $this->assertEquals(SampleJsonData::HPP_VERSION, $hppRequestConverted->getHppVersion()); $this->assertEquals(SampleJsonData::HPP_SELECT_STORED_CARD, $hppRequestConverted->getHppSelectStoredCard()); $hppRequestConverted = $hppRequestConverted->encode(RealexHpp::ENCODING_CHARSET); $hppRequestConverted = $hppRequestConverted->decode(RealexHpp::ENCODING_CHARSET); $this->assertEquals(SampleJsonData::HPP_VERSION, $hppRequestConverted->getHppVersion()); $this->assertEquals(SampleJsonData::HPP_SELECT_STORED_CARD, $hppRequestConverted->getHppSelectStoredCard()); }
/** * Test validation post dimensions fails */ public function testValidationPassedSuccess() { $path = SampleJsonData::VALID_HPP_REQUEST_HPP_POST_BOTH_JSON_PATH; $prefix = __DIR__ . '/../../../resources'; $json = file_get_contents($prefix . $path); $hppRequestConverted = JsonUtils::fromJsonHppRequest($json); $hppRequestConverted->generateDefaults(SampleJsonData::SECRET); try { ValidationUtils::validate($hppRequestConverted); } catch (RealexValidationException $e) { $this->fail("This HppRequest shouldn't have validation errors."); } }
/** * Test converting JSON with no TSS Information to {@link HppResponse}. */ public function testFromJsonHppResponseNoTSSEncoded() { $path = SampleJsonData::VALID_HPP_RESPONSE_NO_TSS_JSON_PATH; $prefix = __DIR__ . '/../../../resources'; $json = file_get_contents($prefix . $path); $hppResponseConverted = JsonUtils::fromJsonHppResponse($json); $hppResponseConverted = $hppResponseConverted->decode(RealexHpp::ENCODING_CHARSET); $this->assertEquals("", $hppResponseConverted->getTss()); }
/** * <p> * Method produces <code>HppResponse</code> object from JSON. * Carries out the following actions: * <ul> * <li>Deserialises JSON to response object</li> * <li>Decodes Base64 inputs</li> * <li>Validates hash</li> * </ul> * </p> * * @param string $json * @param bool $encoded * @return HppResponse */ public function responseFromJson($json, $encoded = true) { $this->logger->info("Converting JSON to HppResponse."); //convert to HppResponse from JSON $hppResponse = JsonUtils::fromJsonHppResponse($json); //decode if necessary if ($encoded) { $this->logger->debug("Decoding object."); try { $hppResponse = $hppResponse->decode(self::ENCODING_CHARSET); } catch (Exception $e) { $this->logger->error("Exception decoding HPP response.", $e); throw new RealexException("Exception decoding HPP response.", $e); } } //validate HPP response hash $this->logger->debug("Validating response hash."); ValidationUtils::validateResponse($hppResponse, $this->secret); return $hppResponse; }