The method checks if the voucher can be used by the active user and the active basket.
If function returns 0 the you can use the voucher.

@return int
517818
public function AllowUseOfVoucher()
    {
        $bAllowUse = TdbShopVoucher::ALLOW_USE;

        $oBasket = TShopBasket::GetInstance();
        $oExistingVouchers = $oBasket->GetVoucherList();
        if (!is_null($oExistingVouchers)) {
            $oMatchingVoucher = $oExistingVouchers->FindItemWithProperty('id', $this->id);
            if ($oMatchingVoucher) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_OTHER_VOUCHER_USED;
            }
        }

        $oSeries = &$this->GetFieldShopVoucherSeries();
        $oUser = TdbDataExtranetUser::GetInstance();

        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            // check if the series is active
            if (!$oSeries->IsActive()) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_SERIES_INACTIVE;
            }
        }

        // get articles affected by the voucher - we need at least one matching product in order for the voucher
        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            $iNumberOfItemsAffected = $oBasket->GetBasketQuantityForVoucher($this);
            if (0 == $iNumberOfItemsAffected) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CURRENT_BASKET;
            }
        }

        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            // note: we are interested in the total product value (- produts that can not be used for the voucher) - vouchers used
            $dRelevantValue = $oBasket->GetBasketSumForVoucher($this) - $oBasket->dCostVouchers;
            if ($oSeries->fieldRestrictToValue > 0 && ($dRelevantValue < $oSeries->fieldRestrictToValue || $dRelevantValue <= 0)) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_BASKET_VALUE_TO_LOW;
            }
        }

        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            // check if another voucher of the same series is already in use... if this voucher is restricted to one per series per purchase
            $oActiveVoucherList = $oBasket->GetVoucherList();
            if (null !== $oActiveVoucherList && $oActiveVoucherList->Length() > 0) {
                if ($oSeries->fieldAllowNoOtherVouchers) {
                    $bAllowUse = TdbShopVoucher::USE_ERROR_OTHER_VOUCHER_USED;
                } else {
                    // check if other vouchers have that restriction
                    $oActiveVoucherList->GoToStart();

                    while (TdbShopVoucher::ALLOW_USE == $bAllowUse && ($oTmpVoucher = $oActiveVoucherList->Next())) {
                        if ($oTmpVoucher->GetFieldShopVoucherSeries()->fieldAllowNoOtherVouchers) {
                            $bAllowUse = TdbShopVoucher::USE_ERROR_OTHER_VOUCHER_USED;
                        }
                    }
                    $oActiveVoucherList->GoToStart();
                }
            } elseif (null !== $oActiveVoucherList && $oSeries->fieldRestrictToOtherSeries) {
                while ((TdbShopVoucher::ALLOW_USE == $bAllowUse) && ($oTmpVoucher = $oActiveVoucherList->Next())) {
                    $oTmpSeries = $oTmpVoucher->GetFieldShopVoucherSeries();
                    if ($oTmpSeries->IsSameAs($oSeries)) {
                        $bAllowUse = TdbShopVoucher::USE_ERROR_VOUCHER_WITH_SAME_SERIES_USED;
                    }
                }
                $oActiveVoucherList->GoToStart();
            }
        }

        if (TdbShopVoucher::ALLOW_USE == $bAllowUse && $oSeries->fieldRestrictToOnePerUser) {
            // check if the user has used a voucher of this series before
            if (!is_null($oUser->id) && !empty($oUser->id)) {
                $iNumberOfTimesUsed = $oSeries->NumberOfTimesUsedByUser($oUser->id, array($this->id));
                if ($iNumberOfTimesUsed > 0) {
                    $bAllowUse = TdbShopVoucher::USE_ERROR_CUSTOMER_USED_VOUCHER_SERIES_BEFORE;
                }
            }
        }

        // if the voucher may only be used with the first order, check if the user has ordered before
        if (TdbShopVoucher::ALLOW_USE == $bAllowUse && $oSeries->fieldRestrictToFirstOrder) {
            $oUserOrders = TdbShopOrderList::GetListForDataExtranetUserId($oUser->id);
            if ($oUserOrders->Length() > 0) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_FIRST_ORDER;
            }
        }

        $bUserLoggedIn = $oUser->IsLoggedIn();
        // if the voucher is restricted to some user, make sure this user is in that list
        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            $aUserListRestricton = $oSeries->GetMLTIdList('data_extranet_user', 'data_extranet_user_mlt');
            if (count($aUserListRestricton) > 0 && true === $bUserLoggedIn && !in_array($oUser->id, $aUserListRestricton)) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER;
            } elseif (count($aUserListRestricton) > 0 && false === $bUserLoggedIn) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_MISSING_LOGIN;
            }
        }

        // if the voucher is restricted to some user group, make sure this user is in that list
        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            $aUserGroupListRestricton = $oSeries->GetMLTIdList('data_extranet_group', 'data_extranet_group_mlt');
            if (count($aUserGroupListRestricton) > 0 && true === $bUserLoggedIn && !$oUser->InUserGroups($aUserGroupListRestricton)) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_GROUP;
            } elseif (count($aUserGroupListRestricton) > 0 && false === $bUserLoggedIn) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_GROUP_MISSING_LOGIN;
            }
        }

        return $bAllowUse;
    }
1075029
public function isVirtualPayPalBasket()
    {
        $isVirtual = true;

        $products = $this->getBasketArticles();
        foreach ($products as $product) {
            if (!$product->isVirtualPayPalArticle()) {
                $isVirtual = false;
                break;
            }
        }

        return $isVirtual;
    }
1028705
public function IsValidForBasket()
    {
        $bValidForBasket = false;

        $oBasket = TShopBasket::GetInstance();

        if (false === $oBasket->isTotalCostKnown()) {
            // check the total basket value
            if ($this->fieldRestrictToBasketValueFrom > $oBasket->dCostTotal || ($this->fieldRestrictToBasketValueTo > 0 && $this->fieldRestrictToBasketValueTo < $oBasket->dCostTotal)) {
                return false;
            }
        }

        if ($this->fieldRestrictToValueFrom <= $oBasket->dCostArticlesTotalAfterDiscounts && (0 == $this->fieldRestrictToValueTo || $this->fieldRestrictToValueTo >= $oBasket->dCostArticlesTotalAfterDiscounts)) {
            $bValidForBasket = true;
        }

        $paymentMethodDataAccess = $this->getPaymentMethodDataAccess();
        if ($bValidForBasket) {
            // now check basket contents.
            // do all articles, article_groups, or categories match?
            $aArticleIds = $paymentMethodDataAccess->getPermittedArticleIds($this->id);
            $aCategoryIds = $paymentMethodDataAccess->getPermittedCategoryIds($this->id);
            $aArticleGroupIds = $paymentMethodDataAccess->getPermittedArticleGroupIds($this->id);

            $bRestrictToArticles = (count($aArticleIds) > 0);
            $bRestrictToCategories = (count($aCategoryIds) > 0);
            $bRestrictToArticleGroups = (count($aArticleGroupIds) > 0);
            if ($bRestrictToArticles || $bRestrictToCategories || $bRestrictToArticleGroups) {
                $oBasketArticles = $oBasket->GetBasketContents();
                $oBasketArticles->GoToStart();

                if ($this->fieldPositivListLooseMatch) {
                    // if we are using a loose positive match, we allow use of the payment method as long as we have at least one article match for every restriction

                    // set the conditions to false, that we need to check
                    $bMatchArticleIds = (false == $bRestrictToArticles);
                    $bMatchCategoryIds = (false == $bRestrictToCategories);
                    $bMatchArticleGroupIds = (false == $bRestrictToArticleGroups);
                    // now check each basket entry
                    while ((!$bMatchArticleIds || !$bMatchCategoryIds || !$bMatchArticleGroupIds) && ($oBasketArticle = $oBasketArticles->Next())) {
                        // if we have no match for the article restriction, check if this one is a match. if it is, mark as "got one" :)
                        if (!$bMatchArticleIds && in_array($oBasketArticle->id, $aArticleIds)) {
                            $bMatchArticleIds = true;
                        }

                        // if we have no match for the category restriction, check if this one is a match. if it is, mark as "got one" :)
                        if (!$bMatchCategoryIds && $oBasketArticle->IsInCategory($aCategoryIds)) {
                            $bMatchCategoryIds = true;
                        }

                        // if we have no match for the article group restriction, check if this one is a match. if it is, mark as "got one" :)
                        if (!$bMatchArticleGroupIds && $oBasketArticle->IsInArticleGroups($aArticleGroupIds)) {
                            $bMatchArticleGroupIds = true;
                        }
                    }

                    // payment method is valid, if every condition that we needed to check did return a match
                    $bValidForBasket = ($bMatchArticleIds && $bMatchCategoryIds && $bMatchArticleGroupIds);
                } else {
                    $bMatchArticleIds = true;
                    $bMatchCategoryIds = true;
                    $bMatchArticleGroupIds = true;
                    while ($bValidForBasket && ($oBasketArticle = $oBasketArticles->Next())) {
                        if ($bRestrictToArticles && !in_array($oBasketArticle->id, $aArticleIds)) {
                            $bValidForBasket = false;
                        }

                        if ($bValidForBasket && $bRestrictToCategories && !$oBasketArticle->IsInCategory($aCategoryIds)) {
                            $bValidForBasket = false;
                        }

                        if ($bValidForBasket && $bRestrictToArticleGroups && !$oBasketArticle->IsInArticleGroups($aArticleGroupIds)) {
                            $bValidForBasket = false;
                        }
                    }
                }
            }
        }

        // if the payment method is still valid, check the negative list to see if we need to disable it
        if ($bValidForBasket) {
            $aArticleIds = $paymentMethodDataAccess->getInvalidArticleIds($this->id);
            $aCategoryIds = $paymentMethodDataAccess->getInvalidCategoryIds($this->id);
            $aArticleGroupIds = $paymentMethodDataAccess->getInvalidArticleGroupIds($this->id);

            $bRestrictToArticles = (count($aArticleIds) > 0);
            $bRestrictToCategories = (count($aCategoryIds) > 0);
            $bRestrictToArticleGroups = (count($aArticleGroupIds) > 0);

            if ($bRestrictToArticles || $bRestrictToCategories || $bRestrictToArticleGroups) {
                $oBasketArticles = $oBasket->GetBasketContents();
                $oBasketArticles->GoToStart();
                while ($bValidForBasket && ($oBasketArticle = $oBasketArticles->Next())) {
                    if ($bRestrictToArticles && in_array($oBasketArticle->id, $aArticleIds)) {
                        $bValidForBasket = false;
                    }

                    if ($bValidForBasket && $bRestrictToCategories && $oBasketArticle->IsInCategory($aCategoryIds)) {
                        $bValidForBasket = false;
                    }

                    if ($bValidForBasket && $bRestrictToArticleGroups && $oBasketArticle->IsInArticleGroups($aArticleGroupIds)) {
                        $bValidForBasket = false;
                    }
                }
            }
        }

        return $bValidForBasket;
    }
565648
public function checkRequired()
    {
        if (is_array($this->value)) {
            return (bool) $this->value;
        }

        $value = (string) $this->value;

        return $this->value || $value === '0';
    }
250028
public function getPurchasedAt() : ?int 
    {
        if ( ! $this->hasPurchasedAt()) {
            $this->setPurchasedAt($this->getDefaultPurchasedAt());
        }
        return $this->purchasedAt;
    }
832666
public function IsAvailable()
    {
        $bIsValid = $this->isAvailableIgnoreGroupRestriction();

        if ($bIsValid) {
            // check group restrictions
            $aShippingGroupIdList = array();
            $oShippingGroup = TShopBasket::GetInstance()->GetAvailableShippingGroups();
            if (null !== $oShippingGroup) {
                $aShippingGroupIdList = $oShippingGroup->GetIdList();
            }
            $bAllowedForCurrentAvailableShippingGroupList = $this->allowedForShippingGroupList($aShippingGroupIdList);

            $bIsValid = ($bIsValid && $bAllowedForCurrentAvailableShippingGroupList);
        }

        return $bIsValid;
    }
1052034
public function getSwapPercentUsed()
    {
        if ($this->getSwapTotal() !== null) {
            if ($this->getSwapTotal() > 0) {
                return round($this->getSwapUsed() / $this->getSwapTotal() * 100);
            } else {
                return 0;
            }
        } else {
            return null;
        }
    }
818299
public function HasBasketRestrictions()
    {
        $bRestrictedToBasket = (($this->fieldRestrictToArticlesFrom > 0) || ($this->fieldRestrictToArticlesTo > 0) || ($this->fieldRestrictToValueFrom > 0) || ($this->fieldRestrictToValueTo > 0));

        return $bRestrictedToBasket;
    }
1305776
public function getTotalDiscountSum()
    {
        $dPrice = 0;
        // subtracting total discount
        if ($oPrice = $this->getTotalDiscount()) {
            $dPrice += $oPrice->getPrice();
        }

        if ($oVoucherPrice = $this->getVoucherDiscount()) {
            $dPrice += $oVoucherPrice->getPrice();
        }

        return $dPrice;
    }
361220
public function GetBasketSumForVoucher(TShopVoucher &$oVoucher)
    {
        $value = $this->GetBasketArticles()->GetBasketSumForVoucher($oVoucher);
        if (true === $oVoucher->IsSponsored()) {
            $value += $this->dCostShipping;
        }

        return $value;
    }
804583
public function getPayPalGiftCardCosts()
    {
        $amount = 0.0;

        $giftCardCost = $this->getCosts('oxgiftcard');
        if ($giftCardCost) {
            $amount = $this->isCalculationModeNetto() ? $giftCardCost->getNettoPrice() : $giftCardCost->getBruttoPrice();
        }

        return $amount;
    }
424754
public function getSimpleVoucher()
    {
        $oVoucher = new stdClass();
        $oVoucher->sVoucherId = $this->getId();
        $oVoucher->sVoucherNr = null;
        if ($this->oxvouchers__oxvouchernr) {
            $oVoucher->sVoucherNr = $this->oxvouchers__oxvouchernr->value;
        }

        // R. set in oxBasket : $oVoucher->fVoucherdiscount = \OxidEsales\Eshop\Core\Registry::getLang()->formatCurrency( $this->oxvouchers__oxdiscount->value );

        return $oVoucher;
    }
1009508
public function allowedRetries()
  {
    if (isset($this->retryMap[$this->code])) {
      return $this->retryMap[$this->code];
    }

    return 0;
  }
1090985
protected function _calcBasketTotalDiscount()
    {
        if ($this->_oTotalDiscount === null || (!$this->isAdmin())) {
            $this->_oTotalDiscount = $this->_getPriceObject();

            if (is_array($this->_aDiscounts)) {
                foreach ($this->_aDiscounts as $oDiscount) {
                    // skipping bundle discounts
                    if ($oDiscount->sType == 'itm') {
                        continue;
                    }

                    // add discount value to total basket discount
                    $this->_oTotalDiscount->add($oDiscount->dDiscount);
                }
            }
        }
    }
745841
public function usediscount()
    {
        $this->extend("onBeforeUseDiscount");

        $code_to_search = $this->request->param("ID");
        $code = false;

        if (!$code_to_search) {
            return $this->httpError(404, "Page not found");
        }

        // First check if the discount is already added (so we don't
        // query the DB if we don't have to).
        if (!$this->discount || ($this->discount && $this->discount->Code != $code_to_search)) {
            $codes = Discount::get()
                ->filter("Code", $code_to_search)
                ->exclude("Expires:LessThan", date("Y-m-d"));

            if ($codes->exists()) {
                $code = $codes->first();
                $this->discount = $code;
                $this->save();
            }
        } elseif ($this->discount && $this->discount->Code == $code_to_search) {
            $code = $this->discount;
        }

        return $this
            ->customise(array(
                "Discount" => $code
            ))->renderWith(array(
                'ShoppingCart_discount',
                'Checkout',
                'Page'
            ));
    }
283305
public static function ActiveUserSelectedACurrency()
    {
        $bSelected = false;
        $oUser = TdbDataExtranetUser::GetInstance();
        if ($oUser && is_array($oUser->sqlData) && array_key_exists('pkg_shop_currency_id', $oUser->sqlData) && !empty($oUser->sqlData['pkg_shop_currency_id'])) {
            $bSelected = true;
        }

        return $bSelected;
    }
626602
protected function RecalculateNoneSponsoredVouchers()
    {
        if (!is_null($this->GetActiveVouchers())) {
            $this->dCostNoneSponsoredVouchers = 0;
            $this->GetActiveVouchers()->RemoveInvalidVouchers(MTShopBasketCore::MSG_CONSUMER_NAME, $this);

            $this->dCostNoneSponsoredVouchers = $this->GetActiveVouchers()->GetVoucherValue(false);
            if ($this->dCostNoneSponsoredVouchers > $this->dCostArticlesTotalAfterDiscounts) {
                $this->dCostNoneSponsoredVouchers = $this->dCostArticlesTotalAfterDiscounts;
            }
        } else {
            $this->dCostNoneSponsoredVouchers = 0;
        }
    }