Validates currency code
@return boolean|null
971758
protected function validateCodeCurrency()
    {
        $field = 'code';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('Code');

        if (empty($value)) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        if (preg_match('/^[a-zA-Z]{3}$/', $value) !== 1) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        $code = strtoupper($value);
        $updating = $this->getUpdating();

        if (isset($updating['code']) && $updating['code'] === $code) {
            return true;
        }

        $existing = $this->currency->get($code);

        if (!empty($existing)) {
            $this->setErrorExists($field, $label);
            return false;
        }

        $this->setSubmitted($field, $code);
        return true;
    }
15773
public function _callbackValidCurrency($sCode)
    {
        $oFormValidation = Factory::service('FormValidation');
        $oFormValidation->set_message('_callbackValidCurrency', 'Invalid currency.');

        $oCurrency = Factory::service('Currency', 'nails/module-currency');
        $aEnabled  = $oCurrency->getAllEnabled();

        foreach ($aEnabled as $oCurrency) {
            if ($oCurrency->code === $sCode) {
                return true;
            }
        }

        return false;
    }
1321114
protected function validateComponentPricesOrder()
    {
        $field = 'data.components';
        $components = $this->getSubmitted($field);

        if (empty($components)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('Price');

        if (!is_array($components)) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        foreach ($components as $id => $component) {

            if (!is_numeric($component['price'])) {
                $this->setErrorNumeric("$field.$id", $label);
                continue;
            }

            if (strlen($component['price']) > 10) {
                $this->setErrorLengthRange("$field.$id", $label, 0, 10);
            }
        }

        return !$this->isError('components');
    }
1055542
public static String validate(String code) {
        try {
            toCurrency(code);
        } catch (IllegalArgumentException ex) {
            throw new InvalidValueException(code, "currency");
        }
        return code;
    }
930731
public function isValid()
    {
        $requestPayment = $this->getRequestOrderPayment();
        $orderPayment = $this->getOrderPayment();

        $currencyPayPal = $requestPayment->getCurrency();
        $pricePayPal = $requestPayment->getAmount();

        $currencyPayment = $orderPayment->getCurrency();
        $amountPayment = $orderPayment->getAmount();

        return ($currencyPayPal == $currencyPayment && $pricePayPal == $amountPayment);
    }
806078
public function isPaymentValid()
    {
        $isValid = $this->isPaymentActive();

        if ($isValid && !is_null($this->getPrice())) {
            $isValid = $this->checkPriceRange() && $this->checkMinOrderPrice();
        }

        $user = $this->getUser();
        if ($isValid && $user && $user->hasAccount()) {
            $isValid = $this->checkUserGroup();
        }

        if ($isValid && $user && $this->getCheckCountry()) {
            $isValid = $this->checkUserCountry();
        }

        return $isValid;
    }
674878
protected function validateOptionsCart()
    {
        $product = $this->getSubmitted('product');

        if (empty($product) || $this->isError()) {
            return null;
        }

        $options = array_filter((array) $this->getSubmitted('options'));

        if (empty($options)) {
            $this->setSubmitted('options', array());
            $this->setSubmitted('sku', $product['sku']);
            $this->setSubmitted('stock', $product['stock']);
            return true;
        }

        $combination_id = $this->sku->getCombinationId($options, $product['product_id']);

        if (empty($product['combination'][$combination_id]['status'])) {
            $error = $this->translation->text('Invalid combination');
            $this->setError('options', $error);
            return false;
        }

        $this->setSubmitted('options', $options);
        $this->setSubmitted('combination_id', $combination_id);
        $this->setSubmitted('sku', $product['combination'][$combination_id]['sku']);
        $this->setSubmitted('stock', $product['combination'][$combination_id]['stock']);
        return true;
    }
102978
public static function getISO4217CurrencyCode($currency) {
    return (array_key_exists($currency, Connect2PayCurrencyHelper::$currencies)) ? Connect2PayCurrencyHelper::$currencies[$currency]["code"] : null;
  }
1223398
public function validate()
    {
        if ($this->_amount === null) {
            $this->setValidationError('Payment amount not specified');
            return false;
        }

        $value = $this->_amount->getValue();
        if (empty($value) || $value <= 0.0) {
            $this->setValidationError('Invalid payment amount value: '.$value);
            return false;
        }

        if ($this->_receipt !== null && $this->_receipt->notEmpty()) {
            $email = $this->_receipt->getEmail();
            $phone = $this->_receipt->getPhone();
            if (empty($email) && empty($phone)) {
                $this->setValidationError('Both email and phone values are empty in receipt');
                return false;
            }
        }

        return true;
    }
437693
protected function validateCountry()
    {
        $id = $this->getUpdatingId();

        if ($id === false) {
            return null;
        }

        $data = $this->country->get($id);

        if (empty($data)) {
            $this->setErrorUnavailable('update', $this->translation->text('Country'));
            return false;
        }

        $this->setUpdating($data);
        return true;
    }
751986
public function getCurrencyCode()
    {
        $currency = $this->paymentBridge->getCurrency();

        $constantName = sprintf('%s::%s', Currency::class, strtoupper($currency));

        if (!defined($constantName)) {
            throw new CurrencyNotSupportedException();
        }

        return constant($constantName);
    }
1152693
public function delete($code, $check = true)
    {
        $result = null;
        $this->hook->attach('currency.delete.before', $code, $check, $result, $this);

        if (isset($result)) {
            return (bool) $result;
        }

        if ($check && !$this->canDelete($code)) {
            return false;
        }

        $currencies = $this->config->select('currencies', array());
        unset($currencies[$code]);

        $result = $this->config->set('currencies', $currencies);

        $this->hook->attach('currency.delete.after', $code, $check, $result, $this);
        return (bool) $result;
    }
894488
protected function validate($code)
    {
        $color = str_replace(['rgba', '(', ')', ' '], '', DefinedColor::find($code, 1));
        if (substr_count($color, ',') === 2) {
            $color = "{$color},1.0";
        }
        $color = $this->fixPrecision($color);
        if (preg_match($this->validationRules(), $color, $matches)) {
            if ($matches[1] > 255 || $matches[2] > 255 || $matches[3] > 255 || $matches[4] > 1) {
                return false;
            }
            return $color;
        }
        return false;
    }
901545
public static function find($code)
    {
        $code = strtoupper($code);
        $currencies = static::all();

        if (isset($currencies[$code])) {
            return new static($code, $currencies[$code]['numeric'], $currencies[$code]['decimals']);
        }

        return null;
    }
1163358
protected function validateCodePriceRule()
    {
        $field = 'code';
        $value = $this->getSubmitted($field);

        if (empty($value)) {
            return null;
        }

        $updating = $this->getUpdating();

        if (isset($updating['code']) && $updating['code'] === $value) {
            return true;
        }

        $label = $this->translation->text('Code');

        if (mb_strlen($value) > 255) {
            $this->setErrorLengthRange($field, $label, 0, 255);
            return false;
        }

        $rules = $this->price_rule->getList(array('code' => $value));

        if (empty($rules)) {
            return true;
        }

        foreach ((array) $rules as $rule) {
            if ($rule['code'] === $value) {
                $this->setErrorExists($field, $label);
                return false;
            }
        }

        return true;
    }
1167903
public function validate(&$error = null)
    {
        if (!$this->isCountryCodeValid()) {
            $error = 'IBAN country code not valid or not supported';
        } elseif (!$this->isLengthValid()) {
            $error = 'IBAN length is invalid';
        } elseif (!$this->isFormatValid()) {
            $error = 'IBAN format is invalid';
        } elseif (!$this->isChecksumValid()) {
            $error = 'IBAN checksum is invalid';
        } else {
            $error = '';
            return true;
        }

        return false;
    }
521586
protected function validateCurrency()
    {
        $id = $this->getUpdatingId();

        if ($id === false) {
            return null;
        }

        $data = $this->currency->get($id);

        if (empty($data)) {
            $this->setErrorUnavailable('update', $this->translation->text('Currency'));
            return false;
        }

        $this->setUpdating($data);
        return true;
    }