/**
  * Test if the full response is successful.
  */
 public function testIsSuccess()
 {
     $response = new PaymentResponse();
     // test success
     $response->setResult(iResponse::RESULT_CODE_SUCCESS);
     $this->assertTrue(ResponseUtils::isSuccess($response));
     // test failure
     $response->setResult("101");
     $this->assertFalse(ResponseUtils::isSuccess($response));
 }
 /**
  * {@inheritDoc}
  *
  * @return bool
  */
 public function isSuccess()
 {
     return ResponseUtils::isSuccess($this);
 }
Example #3
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;
 }