src/main/php/com-realexpayments-hpp-sdk/RealexHpp.php
public function requestToJson(HppRequest $hppRequest, $encoded = true)
    {

        $this->logger->info("Converting HppRequest to JSON.");

        $json = null;

        //generate defaults
        $this->logger->debug("Generating defaults.");
        $hppRequest->generateDefaults($this->secret);

        //validate request
        $this->logger->debug("Validating request.");
        ValidationUtils::validate($hppRequest);

        // build request
        $this->logger->debug("Encoding object.");
        try {
            if ($encoded === true) {
                $hppRequest = $hppRequest->encode(self::ENCODING_CHARSET);              
            }
            else {
                $hppRequest = $hppRequest->formatRequest(self::ENCODING_CHARSET);
            }
        } catch (Exception $e) {
            $this->logger->error("Exception encoding HPP request.", $e);
            throw new RealexException("Exception encoding HPP request.", $e);
        }

        //convert to JSON
        $this->logger->debug("Converting to JSON.");
        $json = JsonUtils::toJson($hppRequest);

        return $json;
    }
public function requestToJson(HppRequest $hppRequest, $encoded = true)
    {

        $this->logger->info("Converting HppRequest to JSON.");

        $json = null;

        //generate defaults
        $this->logger->debug("Generating defaults.");
        $hppRequest->generateDefaults($this->secret);

        //validate request
        $this->logger->debug("Validating request.");
        ValidationUtils::validate($hppRequest);

        // build request
        $this->logger->debug("Encoding object.");
        try {
            if ($encoded === true) {
                $hppRequest = $hppRequest->encode(self::ENCODING_CHARSET);              
            }
            else {
                $hppRequest = $hppRequest->formatRequest(self::ENCODING_CHARSET);
            }
        } catch (Exception $e) {
            $this->logger->error("Exception encoding HPP request.", $e);
            throw new RealexException("Exception encoding HPP request.", $e);
        }

        //convert to JSON
        $this->logger->debug("Converting to JSON.");
        $json = JsonUtils::toJson($hppRequest);

        return $json;
    }
<p>
Method produces JSON from <code>HppRequest</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 request object to JSON</li>
</ul>
</p>

@param HppRequest $hppRequest
@param bool $encoded <code>true</code> if the JSON values will be encoded.
@return HppRequest