Example #1
0
 /**
  * <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
  * @return string
  */
 public function requestToJson(HppRequest $hppRequest)
 {
     $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);
     //encode
     $this->logger->debug("Encoding object.");
     try {
         $hppRequest = $hppRequest->encode(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;
 }