/**
  * Tests conversion of {@link PaymentResponse} to and from XML.
  */
 public function testPaymentResponseXmlAndDeserializeOverallResults()
 {
     $response = new PaymentResponse();
     $response->setAccount(SampleXmlValidationUtils::ACCOUNT);
     $response->setAcquirerResponse(SampleXmlValidationUtils::ACQUIRER_RESPONSE);
     $response->setAuthCode(SampleXmlValidationUtils::AUTH_CODE);
     $response->setAuthTimeTaken(SampleXmlValidationUtils::AUTH_TIME_TAKEN);
     $response->setBatchId(SampleXmlValidationUtils::BATCH_ID);
     $cardIssuer = new CardIssuer();
     $cardIssuer->setBank(SampleXmlValidationUtils::BANK);
     $cardIssuer->setCountry(SampleXmlValidationUtils::COUNTRY);
     $cardIssuer->setCountryCode(SampleXmlValidationUtils::COUNTRY_CODE);
     $cardIssuer->setRegion(SampleXmlValidationUtils::REGION);
     $response->setCardIssuer($cardIssuer);
     $response->setCvnResult(SampleXmlValidationUtils::CVN_RESULT);
     $response->setMerchantId(SampleXmlValidationUtils::MERCHANT_ID);
     $response->setMessage(SampleXmlValidationUtils::MESSAGE);
     $response->setOrderId(SampleXmlValidationUtils::ORDER_ID);
     $response->setPaymentsReference(SampleXmlValidationUtils::PASREF);
     $response->setResult(SampleXmlValidationUtils::RESULT_SUCCESS);
     $response->setHash(SampleXmlValidationUtils::RESPONSE_HASH);
     $response->setTimeStamp(SampleXmlValidationUtils::TIMESTAMP_RESPONSE);
     $response->setTimeTaken(SampleXmlValidationUtils::TIME_TAKEN);
     $tssResult = new TssResult();
     $tssResult->setResult(SampleXmlValidationUtils::TSS_RESULT);
     $response->setTssResult($tssResult);
     $response->setAvsAddressResponse(SampleXmlValidationUtils::AVS_ADDRESS);
     $response->setAvsPostcodeResponse(SampleXmlValidationUtils::AVS_POSTCODE);
     //marshal to XML
     $xml = $response->toXml();
     //unmarshal back to response
     /* @var PaymentResponse $fromXmlResponse */
     $fromXmlResponse = new PaymentResponse();
     $fromXmlResponse = $fromXmlResponse->fromXml($xml);
     SampleXmlValidationUtils::checkUnmarshalledPaymentResponse($fromXmlResponse, $this, true);
 }
    /**
     *  Check all fields match expected values.
     *
     * @param PaymentResponse $fromXmlResponse
     * @param PHPUnit_Framework_TestCase $testCase
     */
    public static function checkUnmarshalledPaymentResponseWithFraudFilterNoRules(PaymentResponse $fromXmlResponse, PHPUnit_Framework_TestCase $testCase, $ignoreTssChecks = false)
    {
        $fraudFilter = $fromXmlResponse->getFraudFilter();
        $testCase->assertEquals(FraudFilterMode::ACTIVE, $fraudFilter->getMode());
        $testCase->assertEquals(FraudFilterResult::NOT_EXECUTED, $fraudFilter->getResult());
        $testCase->assertEmpty($fraudFilter->getRules());
        $testCase->assertEquals(self::FRAUD_FILTER_TIMESTAMP, $fromXmlResponse->getTimeStamp());
        $testCase->assertEquals(self::FRAUD_FILTER_MERCHANT_ID, $fromXmlResponse->getMerchantId());
        $testCase->assertEquals(self::FRAUD_FILTER_ACCOUNT, $fromXmlResponse->getAccount());
        $testCase->assertEquals(self::FRAUD_FILTER_ORDER_ID, $fromXmlResponse->getOrderId());
        $testCase->assertEquals(self::FRAUD_FILTER_AUTH_CODE, $fromXmlResponse->getAuthCode());
        $testCase->assertEquals(self::FRAUD_FILTER_RESULTT, $fromXmlResponse->getResult());
        $testCase->assertEquals(self::FRAUD_FILTER_CVN_RESULT, $fromXmlResponse->getCvnResult());
        $testCase->assertEquals(self::FRAUD_FILTER_AVS_POST, $fromXmlResponse->getAvsPostcodeResponse());
        $testCase->assertEquals(self::FRAUD_FILTER_AVS_ADD, $fromXmlResponse->getAvsAddressResponse());
        $testCase->assertEquals(self::FRAUD_FILTER_BATCH_ID, $fromXmlResponse->getBatchId());
        $testCase->assertEquals(self::FRAUD_FILTER_MESSAGE, $fromXmlResponse->getMessage());
        $testCase->assertEquals(self::FRAUD_FILTER_PAS_REF, $fromXmlResponse->getPaymentsReference());
        $testCase->assertEquals(self::FRAUD_FILTER_TIME_TAKEN, $fromXmlResponse->getTimeTaken());
        $testCase->assertEquals(self::FRAUD_FILTER_AUTH_TIME, $fromXmlResponse->getAuthTimeTaken());
        $testCase->assertEquals(self::FRAUD_FILTER_HASH, $fromXmlResponse->getHash());
    }
}
SampleXmlValidationUtils::Init();
 /**
  * Test sending a ThreeDSecure Verify Enrolled request and receiving a ThreeDSecure Verify Enrolled response.
  */
 public function testSendThreeDSecureVerifyEnrolled()
 {
     //get sample response XML
     $path = SampleXmlValidationUtils::THREE_D_SECURE_VERIFY_ENROLLED_RESPONSE_XML_PATH;
     $prefix = __DIR__ . '/../../resources';
     $xml = file_get_contents($prefix . $path);
     $fromXMLResponse = new ThreeDSecureResponse();
     $fromXMLResponse = $fromXMLResponse->fromXml($xml);
     //mock HttpResponse
     /** @var HttpResponse $httpResponseMock */
     $httpResponseMock = Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpResponse");
     \Phockito::when($httpResponseMock->getBody())->return($fromXMLResponse->toXML());
     \Phockito::when($httpResponseMock->getResponseCode())->return(200);
     // create empty request
     $request = new ThreeDSecureRequest();
     $httpConfiguration = new HttpConfiguration();
     $httpConfiguration->setOnlyAllowHttps(false);
     // mock HttpClient instance
     $httpClientMock = Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpClient");
     \Phockito::when($httpClientMock->execute(\Hamcrest_Core_IsAnything::anything(), \Hamcrest_Core_IsAnything::anything()))->return($httpResponseMock);
     // execute and send on client
     $realexClient = new RealexClient(SampleXmlValidationUtils::SECRET, $httpConfiguration, $httpClientMock);
     $response = $realexClient->send($request);
     // validate response
     SampleXmlValidationUtils::checkUnmarshalledThreeDSecureEnrolledResponse($response, $this);
 }
 /**
  * Tests conversion of {@link PaymentResponse} from XML file
  */
 public function testPaymentResponseWithFraudFilterNoRulesXmlFromFile()
 {
     $path = SampleXmlValidationUtils::PAYMENT_RESPONSE_WITH_FRAUD_FILTER_NO_RULES_XML_PATH;
     $prefix = __DIR__ . '/../../../resources';
     $xml = file_get_contents($prefix . $path);
     //unmarshal back to response
     /* @var PaymentResponse $fromXmlResponse */
     $fromXmlResponse = new PaymentResponse();
     $fromXmlResponse = $fromXmlResponse->fromXml($xml);
     SampleXmlValidationUtils::checkUnmarshalledPaymentResponseWithFraudFilterNoRules($fromXmlResponse, $this);
 }