/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { require_once drupal_get_path('module', 'uc_icepay') . '/api/ParameterValidation.php'; if (!\Icepay_ParameterValidation::merchantID($form_state->getValue('uc_icepay_merchant_id'))) { $form_state->setErrorByName('uc_icepay_merchant_id', t('You have specified an invalid Icepay Merchant ID.')); } if (!\Icepay_ParameterValidation::secretCode($form_state->getValue('uc_icepay_secret_code'))) { $form_state->setErrorByName('uc_icepay_secret_code', t('You have specified an invalid Icepay Secret Code.')); } }
/** * Validate the postback data * @since version 1.0.0 * @access public * @return boolean */ public function validate() { if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->_logger->log("Invalid request method", Icepay_Api_Logger::ERROR); return false; } $this->_logger->log(sprintf("Postback: %s", serialize($_POST)), Icepay_Api_Logger::TRANSACTION); /* @since version 1.0.2 */ foreach ($this->getPostbackResponseFields() as $obj => $param) { $this->data->{$obj} = isset($_POST[$param]) ? $_POST[$param] : ""; } if ($this->isVersionCheck()) { return false; } if ($this->_doIPCheck) { $check = false; foreach ($this->_whiteList as $ip) { $start = $ip['start']; $end = $ip['end']; if ($this->ip_in_range($_SERVER['REMOTE_ADDR'], "{$start}-{$end}")) { $check = true; break; } } if (!$check) { $this->_logger->log("IP Address not in range: {$_SERVER['REMOTE_ADDR']}", Icepay_Api_Logger::ERROR); return false; } } if (!Icepay_ParameterValidation::merchantID($this->data->merchant)) { $this->_logger->log("Merchant ID is not numeric: {$this->data->merchant}", Icepay_Api_Logger::ERROR); return false; } if (!Icepay_ParameterValidation::amount($this->data->amount)) { $this->_logger->log("Amount is not numeric: {$this->data->amount}", Icepay_Api_Logger::ERROR); return false; } if ($this->_merchantID != $this->data->merchant) { $this->_logger->log("Invalid Merchant ID: {$this->data->merchant}", Icepay_Api_Logger::ERROR); return false; } if (!in_array(strtoupper($this->data->status), array(Icepay_StatusCode::OPEN, Icepay_StatusCode::AUTHORIZED, Icepay_StatusCode::SUCCESS, Icepay_StatusCode::ERROR, Icepay_StatusCode::REFUND, Icepay_StatusCode::CHARGEBACK))) { $this->_logger->log("Unknown status: {$this->data->status}", Icepay_Api_Logger::ERROR); return false; } if ($this->generateChecksumForPostback() != $this->data->checksum) { $this->_logger->log("Checksum does not match", Icepay_Api_Logger::ERROR); return false; } return true; }
/** * Validate the merchant settings * * @since 1.0.0 * @throws Exception */ private function validateSettings() { // Validate Merchant ID if (!Icepay_ParameterValidation::merchantID($this->getMerchantID())) { throw new Exception('Merchant ID not set, use the setMerchantID() method', 1001); } // Validate SecretCode if (!Icepay_ParameterValidation::secretCode($this->getSecretCode())) { throw new Exception('Secretcode ID not set, use the setSecretCode() method', 1002); } }
/** * Set the Merchant ID field * @since 1.0.0 * @access public * @param (int) $merchantID */ public function setMerchantID($merchantID) { if (!Icepay_ParameterValidation::merchantID($merchantID)) { throw new Exception('MerchantID not valid'); } $this->_merchantID = (int) $merchantID; return $this; }