/**
  * Checks if the passed value is valid.
  *
  * @param HppRequest $hppRequest
  * @param Constraint $constraint
  *
  * @api
  */
 public function validate($hppRequest, Constraint $constraint)
 {
     foreach ($hppRequest->getSupplementaryData() as $supplementaryData) {
         if (!preg_match($constraint->pattern, $supplementaryData)) {
             $this->context->buildViolation($constraint->message)->atPath('supplementaryData')->addViolation();
         }
     }
 }
 /**
  * Checks if the passed value is valid.
  *
  * @param HppRequest $hppRequest
  * @param Constraint $constraint
  *
  * @api
  */
 public function validate($hppRequest, Constraint $constraint)
 {
     foreach ($hppRequest->getSupplementaryData() as $supplementaryData) {
         if (strlen($supplementaryData) > $this->maxLength) {
             $this->context->buildViolation($constraint->message)->atPath('supplementaryData')->addViolation();
         }
     }
 }
 /**
  * Validates OTB
  *
  * @param HppRequest $hppRequest
  * @param Constraint $constraint
  *
  * @api
  */
 public function validate($hppRequest, Constraint $constraint)
 {
     //if validate card only flag is true (1), then ensure the amount is set to 0
     if (Flag::TRUE == $hppRequest->getValidateCardOnly()) {
         if ($hppRequest->getAmount() != "0") {
             $this->context->buildViolation($constraint->message)->atPath('amount')->addViolation();
         }
     }
 }
Пример #4
0
 private static function Initialise()
 {
     if (self::$initialised) {
         return;
     }
     self::$logger = RXPLogger::getLogger(__CLASS__);
     self::$mappers = array();
     self::$mappers[HppRequest::GetClassName()] = new RequestMapper();
     self::$mappers[HppResponse::GetClassName()] = new ResponseMapper();
     self::$initialised = true;
 }
Пример #5
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;
 }
Пример #6
0
 /**
  *
  * Receives a Json string and generates a domain object
  *
  * @param string $value
  *
  * @return HppRequest
  */
 public function ReadValue($value)
 {
     $array = json_decode($value, true);
     $array = new SafeArrayAccess($array, "");
     if ($array) {
         $hppRequest = new HppRequest();
         $hppRequest->setMerchantId($array['MERCHANT_ID']);
         $hppRequest->setAccount($array['ACCOUNT']);
         $hppRequest->setOrderId($array['ORDER_ID']);
         $hppRequest->setAmount($array['AMOUNT']);
         $hppRequest->setCurrency($array['CURRENCY']);
         $hppRequest->setTimeStamp($array['TIMESTAMP']);
         $hppRequest->setHash($array['SHA1HASH']);
         $hppRequest->setAutoSettleFlag($array['AUTO_SETTLE_FLAG']);
         $hppRequest->setCommentOne($array['COMMENT1']);
         $hppRequest->setCommentTwo($array['COMMENT2']);
         $hppRequest->setReturnTss($array['RETURN_TSS']);
         $hppRequest->setShippingCode($array['SHIPPING_CODE']);
         $hppRequest->setShippingCountry($array['SHIPPING_CO']);
         $hppRequest->setBillingCode($array['BILLING_CODE']);
         $hppRequest->setBillingCountry($array['BILLING_CO']);
         $hppRequest->setCustomerNumber($array['CUST_NUM']);
         $hppRequest->setVariableReference($array['VAR_REF']);
         $hppRequest->setProductId($array['PROD_ID']);
         $hppRequest->setLanguage($array['HPP_LANG']);
         $hppRequest->setCardPaymentButtonText($array['CARD_PAYMENT_BUTTON']);
         $hppRequest->setValidateCardOnly($array['VALIDATE_CARD_ONLY']);
         $hppRequest->setDccEnable($array['DCC_ENABLE']);
         $hppRequest->setCardStorageEnable($array['CARD_STORAGE_ENABLE']);
         $hppRequest->setOfferSaveCard($array['OFFER_SAVE_CARD']);
         $hppRequest->setPayerReference($array['PAYER_REF']);
         $hppRequest->setPaymentReference($array['PMT_REF']);
         $hppRequest->setPayerExists($array['PAYER_EXIST']);
         $supplementaryData = array();
         foreach ($array->getUnderLayingArray() as $key => $value) {
             if (!$this->isKnownProperty($key)) {
                 $supplementaryData[$key] = $value;
             }
         }
         $hppRequest->setSupplementaryData($supplementaryData);
         return $hppRequest;
     }
     return $array;
 }
 /**
  * Checks request post dimensions matches expected values.
  *
  * @param HppRequest $hppRequestConverted
  * @param PHPUnit_Framework_TestCase $testCase
  */
 public static function checkValidHppRequestPostDimensions(HppRequest $hppRequestConverted, PHPUnit_Framework_TestCase $testCase)
 {
     $postDimensions = $hppRequestConverted->getPostDimensions();
     $testCase->assertEquals(self::POST_DIMENSIONS, $postDimensions, "Json conversion incorrect ");
     $testCase->assertEquals(sizeof(self::POST_DIMENSIONS), sizeof($postDimensions), "Json conversion incorrect size");
     $hppRequestConverted = $hppRequestConverted->encode(RealexHpp::ENCODING_CHARSET);
     $hppRequestConverted = $hppRequestConverted->decode(RealexHpp::ENCODING_CHARSET);
     $postDimensions = $hppRequestConverted->getPostDimensions();
     $testCase->assertEquals(self::POST_DIMENSIONS, $postDimensions, "Json conversion incorrect ");
 }
Пример #8
0
 /**
  * Checks request supplementary data matches expected values.
  *
  * @param HppRequest $hppRequestConverted
  * @param PHPUnit_Framework_TestCase $testCase
  */
 public static function checkValidHppRequestSupplementaryData(HppRequest $hppRequestConverted, PHPUnit_Framework_TestCase $testCase)
 {
     $supplementaryData = $hppRequestConverted->getSupplementaryData();
     $testCase->assertEquals(self::UNKNOWN_ONE_VALUE, $supplementaryData[self::UNKNOWN_ONE_KEY], "Json conversion incorrect Unknown one");
     $testCase->assertEquals(self::UNKNOWN_TWO_VALUE, $supplementaryData[self::UNKNOWN_TWO_KEY], "Json conversion incorrect Unknown one");
     $testCase->assertEquals(self::UNKNOWN_THREE_VALUE, $supplementaryData[self::UNKNOWN_THREE_KEY], "Json conversion incorrect Unknown one");
     $testCase->assertEquals(self::UNKNOWN_FOUR_VALUE, $supplementaryData[self::UNKNOWN_FOUR_KEY], "Json conversion incorrect Unknown one");
     $testCase->assertEquals(sizeof(self::$SUPPLEMENTARY_DATA), sizeof($supplementaryData), "Json conversion incorrect size");
 }