/**
  * Test if the response is a basic response.
  */
 public function testIsBasicResponse()
 {
     //test success response
     $this->assertFalse(ResponseUtils::isBasicResponse(iResponse::RESULT_CODE_SUCCESS));
     //test 1xx code
     $this->assertFalse(ResponseUtils::isBasicResponse("100"));
     //test 2xx code
     $this->assertFalse(ResponseUtils::isBasicResponse("200"));
     //test 3xx code
     $this->assertTrue(ResponseUtils::isBasicResponse("300"));
     //test 5xx code
     $this->assertTrue(ResponseUtils::isBasicResponse("500"));
 }
Esempio n. 2
0
 /**
  * <p>
  * Sends the request to Realex. Actions:
  *
  * <ol>
  * <li>Generates any defaults on the request e.g. hash, time stamp order ID.</li>
  * <li>Marshals request to XML.</li>
  * <li>Sends request to Realex.</li>
  * <li>Unmarshals response.</li>
  * <li>Checks result code (If response is an error then throws {@link RealexServerException}).</li>
  * <li>Validates response hash (If invalid throws {@link RealexException}).</li>
  * </ol>
  * </p>
  *
  * @param iRequest $request
  *
  * @return iResponse
  */
 public function send(iRequest $request)
 {
     $this->logger->info("Sending XML request to Realex.");
     //generate any required defaults e.g. order ID, time stamp, hash
     $request->generateDefaults($this->secret);
     //convert request to XML
     $this->logger->debug("Marshalling request object to XML.");
     $xmlRequest = $request->toXml();
     //send request to Realex.
     $xmlResult = HttpUtils::sendMessage($xmlRequest, $this->httpClient, $this->httpConfiguration);
     //log the response
     $this->logger->trace("Response XML from server: " . $xmlResult);
     //convert XML to response object
     $this->logger->debug("Unmarshalling XML to response object.");
     $response = $request->responseFromXml($xmlResult);
     //throw exception if short response returned (indicating request could not be processed).
     if (ResponseUtils::isBasicResponse($response->getResult())) {
         $this->logger->error("Error response received from Realex with code " . $response->getResult() . " and message " . $response->getMessage() . ".");
         throw new RealexServerException($response->getTimeStamp(), $response->getOrderId(), $response->getResult(), $response->getMessage());
     }
     //validate response hash
     $this->logger->debug("Verifying response hash.");
     if (!$response->isHashValid($this->secret)) {
         //Hash invalid. Throw exception.
         $this->logger->error("Response hash is invalid. This response's validity cannot be verified.");
         throw new RealexException("Response hash is invalid. This response's validity cannot be verified.");
     }
     return $response;
 }