Пример #1
0
 /**
  * Model validation ensures that any data that is present in the model is
  * formatted correctly. No business logic validation is performed at this
  * level.
  *
  * @throws InvalidRequestException if validation fails.
  */
 public function validate()
 {
     if (strlen($this['TransactionID']) && !preg_match('/^.{1,10}$/', $this['TransactionID'])) {
         throw new InvalidRequestException('TransactionID should have 10 or fewer characters');
     }
     if (strlen($this['TransactionAmount'])) {
         if (!is_numeric($this['TransactionAmount'])) {
             throw new InvalidRequestException('TransactionAmount should be numeric');
         }
         if (0 >= $this['TransactionAmount']) {
             throw new InvalidRequestException('TransactionAmount should be non-zero and positive');
         }
         if (!preg_match('/^.{1,10}$/', $this['TransactionAmount'])) {
             throw new InvalidRequestException('TransactionAmount should have 10 or fewer characters');
         }
     }
     if (strlen($this['ReferenceNumber']) && !preg_match('/^.{1,50}$/', $this['ReferenceNumber'])) {
         throw new InvalidRequestException('ReferenceNumber should have 50 or fewer characters');
     }
     if (isset($this['ReversalType'])) {
         try {
             ReversalType::memberByValue($this['ReversalType']);
         } catch (\Exception $e) {
             throw new InvalidRequestException('Invalid value for ReversalType');
         }
     }
     if (isset($this['MarketCode'])) {
         try {
             MarketCode::memberByValue($this['MarketCode']);
         } catch (\Exception $e) {
             throw new InvalidRequestException('Invalid value for MarketCode');
         }
     }
     if (strlen($this['DuplicateCheckDisableFlag'])) {
         if (!preg_match('/^(0|1)$/', $this['DuplicateCheckDisableFlag'])) {
             throw new InvalidRequestException('DuplicateCheckDisableFlag should be "0" or "1"');
         }
     }
     if (strlen($this['DuplicateOverrideFlag']) && !preg_match('/^(0|1)$/', $this['DuplicateOverrideFlag'])) {
         throw new InvalidRequestException('DuplicateOverrideFlag should be "0" or "1"');
     }
     if (strlen($this['TicketNumber']) && !preg_match('/^.{1,50}$/', $this['TicketNumber'])) {
         throw new InvalidRequestException('TicketNumber should have 50 or fewer characters');
     }
     if (strlen($this['PartialApprovedFlag']) && !preg_match('/^(0|1)$/', $this['PartialApprovedFlag'])) {
         throw new InvalidRequestException('PartialApprovedFlag should be "0" or "1"');
     }
 }
 public function setMarketCode($value)
 {
     $value = MarketCode::memberByValue($value)->value();
     return $this->setParameter('MarketCode', $value);
 }