Checks if payment used for current order is available and active.
Throws exception if not available

@param \OxidEsales\Eshop\Application\Model\Basket $oBasket basket object

@return null
1160
public function validatePayment($oBasket)
    {
        $paymentId = $oBasket->getPaymentId();

        if (!$this->isValidPaymentId($paymentId) || !$this->isValidPayment($oBasket)) {
            return self::ORDER_STATE_INVALIDPAYMENT;
        }
    }
841309
private function isValidPayment($basket)
    {
        $paymentId = $basket->getPaymentId();
        $paymentModel = oxNew(EshopPayment::class);
        $paymentModel->load($paymentId);

        $dynamicValues = $this->getDynamicValues();
        $shopId = \OxidEsales\Eshop\Core\Registry::getConfig()->getShopId();

        return $paymentModel->isValidPayment(
            $dynamicValues,
            $shopId,
            $this->getUser(),
            $basket->getPriceForPayment(),
            $basket->getShippingId()
        );
    }
231548
public function validateDelivery($oBasket)
    {
        // proceed with no delivery
        // used for other countries
        if ($oBasket->getPaymentId() == 'oxempty') {
            return;
        }
        // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804).
        $masterDb = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster();

        $oDelSet = oxNew(\OxidEsales\Eshop\Application\Model\DeliverySet::class);
        $sTable = $oDelSet->getViewName();

        $sQ = "select 1 from {$sTable} where {$sTable}.oxid=" .
              $masterDb->quote($oBasket->getShippingId()) . " and " . $oDelSet->getSqlActiveSnippet();

        // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804).
        if (!$masterDb->getOne($sQ)) {
            // throwing exception
            return self::ORDER_STATE_INVALIDDELIVERY;
        }
    }
799058
public static function getCurrentBasket()
    {
        $settings = SuperCMSSession::singleton();

        try {
            $user = SCmsLoginProvider::getLoggedInUser();
            try {
                $basket = Basket::findLast(new AndGroup(
                    [
                        new Equals('UserID', $user->UniqueIdentifier),
                        new Not(new Equals('Status', self::STATUS_COMPLETED))
                    ]
                ));
            } catch (RecordNotFoundException $ex) {
                $basket = new Basket();
                $basket->UserID = $user->UniqueIdentifier;
                $basket->save();
            }

            if ($settings->basketId != $basket->UniqueIdentifier) {
                self::joinAnonymousBasketItemsToUserBasket($basket);
                self::updateSession($basket);
            }
        } catch (NotLoggedInException $ex) {
            try {
                $basket = new Basket($settings->basketId);
            } catch (RecordNotFoundException $ex) {
                $basket = new Basket();
                $basket->save();
                self::updateSession($basket);
            }
        }

        return $basket;
    }
5665
public function OnBasketItemDeleteEvent($oBasketItemRemoved)
    {
        $event = new \ChameleonSystem\ShopBundle\objects\TShopBasket\BasketItemEvent(
            TdbDataExtranetUser::GetInstance(),
            $this,
            $oBasketItemRemoved
        );
        $this->getEventDispatcher()->dispatch(\ChameleonSystem\ShopBundle\ShopEvents::BASKET_DELETE_ITEM, $event);
    }
1122337
protected function _getItemBundles($oBasketItem, $aBundles = [])
    {
        if ($oBasketItem->isBundle()) {
            return [];
        }

        // does this object still exists ?
        if ($oArticle = $oBasketItem->getArticle()) {
            $aDiscounts = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\DiscountList::class)->getBasketItemBundleDiscounts($oArticle, $this, $this->getBasketUser());

            foreach ($aDiscounts as $oDiscount) {
                $iAmnt = $oDiscount->getBundleAmount($oBasketItem->getAmount());
                if ($iAmnt) {
                    //init array element
                    if (!isset($aBundles[$oDiscount->oxdiscount__oxitmartid->value])) {
                        $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
                    }

                    if ($oDiscount->oxdiscount__oxitmmultiple->value) {
                        $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $iAmnt;
                    } else {
                        $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = $iAmnt;
                    }
                }
            }
        }

        return $aBundles;
    }
1231605
public function getBasket()
    {
        if (!$this->basket) {
            try {
                $this->basket = $this->basketFactory->load($this->customerSelector->get());
            } catch (\Exception $e) {
                // something went wrong while loading the basket
                throw $e;
            }
        }

        return $this->basket;
    }
753072
public function executePayment($dAmount, &$oOrder)
    {
        $this->_iLastErrorNo = null;
        $this->_sLastError = null;

        if (!$this->_isActive()) {
            return true; // fake yes
        }

        // proceed with no payment
        // used for other countries
        if (@$this->_oPaymentInfo->oxuserpayments__oxpaymentsid->value == 'oxempty') {
            return true;
        }

        return false;
    }
486289
public function isForBasketAmount($oBasket)
    {
        $dAmount = 0;
        $aBasketItems = $oBasket->getContents();
        foreach ($aBasketItems as $oBasketItem) {
            $oBasketArticle = $oBasketItem->getArticle(false);

            if ($this->oxdiscount__oxaddsumtype->value != 'itm') {
                $blForBasketItem = $this->isForBasketItem($oBasketArticle);
            } else {
                $blForBasketItem = $this->isForBundleItem($oBasketArticle);
            }

            if ($blForBasketItem) {
                $dRate = $oBasket->getBasketCurrency()->rate;
                if ($this->oxdiscount__oxprice->value) {
                    if (($oPrice = $oBasketArticle->getPrice())) {
                        $dAmount += ($oPrice->getPrice() * $oBasketItem->getAmount()) / $dRate;
                    }
                } elseif ($this->oxdiscount__oxamount->value) {
                    $dAmount += $oBasketItem->getAmount();
                }
            }
        }

        return $this->isForAmount($dAmount);
    }
1205638
public function getPayment()
    {
        if (!$this->isPayPal()) {
            // removing PayPal payment type from session
            $this->getSession()->deleteVariable('oepaypal');
            $this->getSession()->deleteVariable('oepaypal-basketAmount');

            return parent::getPayment();
        }

        if ($this->payment === null) {
            // payment is set ?
            $payment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
            if ($payment->load('oxidpaypal')) {
                $this->payment = $payment;
            }
        }

        return $this->payment;
    }
252122
public function validatePayment( $oBasket )
    {
        $mReturn = $this->_OxpsPaymorrowOxOrder_validatePayment_parent( $oBasket );

        if ( is_null( $mReturn ) ) {

            /** @var oxPayment|OxpsPaymorrowOxPayment $oPayment */
            $oPayment = oxNew( 'oxPayment' );
            $sPaymentId = (string) $oBasket->getPaymentId();

            if ( !$oPayment->load( $sPaymentId ) or !$oPayment->isPaymorrowActiveAndMapped() ) {
                return $mReturn;
            }

            /** @var OxpsPaymorrowRequestControllerProxy $pmGateWay */
            $pmGateWay = oxNew( 'OxpsPaymorrowRequestControllerProxy');

            if ( !$pmGateWay->validatePendingOrder() ) {

                return self::ORDER_STATE_INVALIDPAYMENT;
            }
        }

        return $mReturn;
    }
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;
    }
1299790
protected function CheckBasketContents()
    {
        if ('basket' !== $this->fieldSystemname) {
            $oBasket = $this->getShopService()->getActiveBasket();
            if ($oBasket->dTotalNumberOfArticles <= 0) {
                $oBasketStep = TdbShopOrderStep::GetStep('basket');
                $this->JumpToStep($oBasketStep);
            }
        }
    }
941915
protected function _markVouchers($oBasket, $oUser)
    {
        $this->_aVoucherList = $oBasket->getVouchers();

        if (is_array($this->_aVoucherList)) {
            foreach ($this->_aVoucherList as $sVoucherId => $oSimpleVoucher) {
                $oVoucher = oxNew(\OxidEsales\Eshop\Application\Model\Voucher::class);
                $oVoucher->load($sVoucherId);
                $oVoucher->markAsUsed($this->oxorder__oxid->value, $oUser->oxuser__oxid->value, $oSimpleVoucher->dVoucherdiscount);

                $this->_aVoucherList[$sVoucherId] = $oVoucher;
            }
        }
    }
73596
public function SetActivePaymentMethod($oShopPayment)
    {
        $oldActivePaymentMethod = $this->GetActivePaymentMethod();
        $isPaymentSet = parent::SetActivePaymentMethod($oShopPayment);
        $newActivePaymentMethod = $this->GetActivePaymentMethod();
        if (null === $oldActivePaymentMethod || null === $newActivePaymentMethod) {
            return $isPaymentSet;
        }
        if (false === $oldActivePaymentMethod->IsSameAs($newActivePaymentMethod)) {
            return $isPaymentSet;
        }
        $activeCurrency = $this->getCurrencyService()->getObject();

        if (null === $newActivePaymentMethod->fieldValueOriginal && true == $activeCurrency->fieldIsBaseCurrency) {
            return $isPaymentSet;
        }

        if (null !== $newActivePaymentMethod->fieldValueOriginal) {
            $convertedValue = \TdbPkgShopCurrency::ConvertToActiveCurrency($newActivePaymentMethod->fieldValueOriginal);
            if ($convertedValue === $newActivePaymentMethod->GetPrice()) {
                return $isPaymentSet;
            }
        }

        $reloadedPayment = \TdbShopPaymentMethod::GetNewInstance($newActivePaymentMethod->id);
        parent::SetActivePaymentMethod($reloadedPayment);

        return $isPaymentSet;
    }
233946
public function onCheckout($cart)
    {
        if (!isset($this->creditCard))
            throw new CheckoutException('Credit Card is not set.', 0);

        if (!in_array($this->creditCard->getType(), $this->validTypes))
            throw new CheckoutException('Credit Card is not supported.', 1);

        if ($this->getPatternType($this->creditCard->getNumber()) != $this->creditCard->getType())
            throw new CheckoutException('Credit Card is invalid.', 2);
    }
353144
public function getBasketPrice($dAmount, $aSelList, $oBasket)
    {
        $oUser = $oBasket->getBasketUser();
        $this->setArticleUser($oUser);

        $oBasketPrice = $this->_getPriceObject($oBasket->isCalculationModeNetto());

        // get base price
        $dBasePrice = $this->getBasePrice($dAmount);

        $dBasePrice = $this->_modifySelectListPrice($dBasePrice, $aSelList);
        $dBasePrice = $this->_preparePrice($dBasePrice, $this->getArticleVat(), $oBasket->isCalculationModeNetto());

        // applying select list price

        // setting price
        $oBasketPrice->setPrice($dBasePrice);

        $dVat = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\VatSelector::class)->getBasketItemVat($this, $oBasket);
        $this->_calculatePrice($oBasketPrice, $dVat);

        // returning final price object
        return $oBasketPrice;
    }