/**
  * Test supplementary data second field
  */
 public function testCardSupplementaryData2()
 {
     $hppRequest = SampleJsonData::generateValidHppRequest(false);
     $hppRequest->generateDefaults(SampleJsonData::SECRET);
     $supplementaryData1 = "";
     $supplementaryData2 = "";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should have no validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = " azAZ09'\",+“”._- & ";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "\\/@!?%()*:£\$&€#[]|";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "=ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒ";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "ÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæ";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "çèéêëìíîïðñòóôõö÷ø¤ù";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "úûüýþÿŒŽšœžŸ¥";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $charsAtMax = str_repeat("1", 255);
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $charsAtMax;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $charsOverMax = str_repeat("a", 256);
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $charsOverMax;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
         $this->fail("This HppRequest should have validation errors.");
     } catch (RealexValidationException $e) {
         $validationMessages = $e->getValidationMessages();
         $this->assertEquals(ValidationMessages::hppRequest_supplementary_data_size, $validationMessages[0]);
     }
 }
 /**
  * Test validation post dimensions fails
  */
 public function testValidationPassedSuccess()
 {
     $path = SampleJsonData::VALID_HPP_REQUEST_HPP_POST_BOTH_JSON_PATH;
     $prefix = __DIR__ . '/../../../resources';
     $json = file_get_contents($prefix . $path);
     $hppRequestConverted = JsonUtils::fromJsonHppRequest($json);
     $hppRequestConverted->generateDefaults(SampleJsonData::SECRET);
     try {
         ValidationUtils::validate($hppRequestConverted);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest shouldn't have validation errors.");
     }
 }
Exemplo n.º 3
0
 /**
  * <p>
  * Method produces <code>HppRequest</code> object from JSON.
  * Carries out the following actions:
  * <ul>
  * <li>Deserialises JSON to request object</li>
  * <li>Decodes Base64 inputs</li>
  * <li>Validates inputs</li>
  * </ul>
  * </p>
  *
  * @param string $json
  * @param bool $encoded <code>true</code> if the JSON values have been encoded.
  * @return HppRequest
  */
 public function requestFromJson($json, $encoded = true)
 {
     $this->logger->info("Converting JSON to HppRequest.");
     //convert to HppRequest from JSON
     $hppRequest = JsonUtils::fromJsonHppRequest($json);
     //decode if necessary
     if ($encoded) {
         $this->logger->debug("Decoding object.");
         try {
             $hppRequest = $hppRequest->decode(self::ENCODING_CHARSET);
         } catch (Exception $e) {
             $this->logger->error("Exception encoding HPP request.", $e);
             throw new RealexException("Exception decoding HPP request.", $e);
         }
     }
     //validate HPP request
     $this->logger->debug("Validating request.");
     ValidationUtils::validate($hppRequest);
     return $hppRequest;
 }