Checking if PayPal payment is available in user country

@param \OxidEsales\Eshop\Application\Model\User $user User object.

@return boolean
17892
protected function isPaymentValidForUserCountry($user)
    {
        $payment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
        $payment->load("oxidpaypal");
        $paymentCountries = $payment->getCountries();

        if (!is_array($paymentCountries) || empty($paymentCountries)) {
            // not assigned to any country - valid to all countries
            return true;
        }

        return in_array($this->getUserShippingCountryId($user), $paymentCountries);
    }
1311203
public function getUserCart(
        $user = null,
        $locale = null,
        $currency = null,
        $persistEmptyCart = false,
        $updatePrices = false
    ) {
        // cart by session ID
        if (!$user) {
            // TODO: get correct locale
            $locale = 'de';
            $cartsArray = $this->findCartBySessionId();
        } else {
            // TODO: check if cart for this sessionId exists and assign it to user

            // default locale from user
            $locale = $locale ?: $user->getLocale();
            // get carts
            $cartsArray = $this->findCartsByUser($user, $locale);
        }

        // cleanup cart array: remove duplicates and expired carts
        $this->cleanupCartsArray($cartArray);

        // check if cart exists
        if ($cartsArray && count($cartsArray) > 0) {
            // multiple carts found, do a cleanup
            $cart = $cartsArray[0];
        } else {
            // user has no cart - return empty one
            $cart = $this->createEmptyCart($user, $persistEmptyCart);
        }

        // check if all products are still available
        $cartNoRemovedProducts = $this->checkProductsAvailability($cart);

        // create api entity
        $apiOrder = $this->orderFactory->createApiEntity($cart, $locale);

        if (!$cartNoRemovedProducts) {
            $apiOrder->addCartErrorCode(self::CART_STATUS_PRODUCT_REMOVED);
        }

        $this->orderManager->updateApiEntity($apiOrder, $locale);

        // check if prices have changed
        if ($apiOrder->hasChangedPrices()) {
            $apiOrder->addCartErrorCode(self::CART_STATUS_PRICE_CHANGED);
        }

        if ($updatePrices) {
            $this->updateCartPrices($apiOrder->getItems());
        }

        return $apiOrder;
    }
261204
public function isVisibleTo(User $user)
    {
        return (bool) $this->newQuery()->whereVisibleTo($user)->find($this->id);
    }
963543
public function chown($user) {

		if(false !== $this -> file -> getExists()) {
			return @chown($this -> file -> getBasepath(), $user);
		}

		return false;
	}
560305
public function checkCountries($user, $invAddress, $deliveryAddress)
    {
        $billingCountry = isset($invAddress['oxuser__oxcountryid']) ? $invAddress['oxuser__oxcountryid'] : null;
        $deliveryCountry = isset($deliveryAddress['oxaddress__oxcountryid']) ? $deliveryAddress['oxaddress__oxcountryid'] : null;

        if ($billingCountry || $deliveryCountry) {
            $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

            if (($billingCountry == $deliveryCountry) || (!$billingCountry && $deliveryCountry) || ($billingCountry && !$deliveryCountry)) {
                $billingCountry = $billingCountry ? $billingCountry : $deliveryCountry;
                $query = "select oxactive from oxcountry where oxid = " . $database->quote($billingCountry) . " ";
            } else {
                $query = "select ( select oxactive from oxcountry where oxid = " . $database->quote($billingCountry) . " ) and
                              ( select oxactive from oxcountry where oxid = " . $database->quote($deliveryCountry) . " ) ";
            }

            if (!$database->getOne($query)) {
                $exception = oxNew(\OxidEsales\Eshop\Core\Exception\UserException::class);
                $exception->setMessage(\OxidEsales\Eshop\Core\Registry::getLang()->translateString('ERROR_MESSAGE_INPUT_NOTALLFIELDS'));

                $this->addValidationError("oxuser__oxcountryid", $exception);
            }
        }
    }
541110
private function isSecureExpired(User $user)
    {
        // never expired
        if (!$this->expirationPeriod) {
            return false;
        }

        if (!$lastLogin = $user->getLineLastLogin()) {
            return true;
        }

        return (new \DateTime('-'.$this->expirationPeriod)) > $lastLogin;
    }
930036
protected function getCallbackStatus(User $user): bool
    {
        $allCurrentNotificationFilter = $user->getBunqUser()->getNotificationFilters();

        /** @var NotificationFilter $filter */
        foreach ($allCurrentNotificationFilter as $filter) {
            if (
                self::NOTIFICATION_CATEGORY_MUTATION === $filter->getCategory()
                && self::NOTIFICATION_DELIVERY_METHOD_URL === $filter->getNotificationDeliveryMethod()
                && $filter->getNotificationTarget() === $this->getUrl()
            ) {
                return true;
            }
        }

        return false;
    }
1066496
public function hasVoted($user) {
		$votes = elgg_get_annotations(array(
			'guid' => $this->guid,
			'type' => "object",
			'subtype' => "poll",
			'annotation_name' => "vote",
			'annotation_owner_guid' => $user->guid,
			'limit' => 1
		));

		if ($votes) {
			return true;
		} else {
			return false;
		}
	}
1283082
private function cleanRights(User $user)
    {
        foreach ([
            'DELETE FROM `basusr` WHERE usr_id = :usr_id',
            'DELETE FROM `sbasusr` WHERE usr_id = :usr_id',
        ] as $sql) {
            $stmt = $this->appboxConnection->prepare($sql);
            $stmt->execute([':usr_id' => $user->getId()]);
            $stmt->closeCursor();
        }
    }
997562
static function setUserCountry( $user, $country )
    {
        $userObject = $user->attribute( 'contentobject' );
        $requireUserCountry = eZVATManager::isUserCountryRequired();
        $countryAttributeName = eZVATManager::getUserCountryAttributeName( $requireUserCountry );
        if ( $countryAttributeName === null )
        {
            return false;
        }

        $userDataMap = $userObject->attribute( 'data_map' );
        if ( !isset( $userDataMap[$countryAttributeName] ) )
        {
            if ( $requireUserCountry )
            {
                eZDebug::writeError( "Cannot set user country: there is no attribute '$countryAttributeName' in object '" .
                                       $userObject->attribute( 'name' ) .
                                       "' of class '" .
                                       $userObject->attribute( 'class_name' ) . "'.",
                                     __METHOD__ );
            }

            return false;
        }

        eZDebug::writeNotice( sprintf( "Saving country '%s' for user '%s'",
                                       $country, $user->attribute( 'login' ) ) );

        $countryAttribute = $userDataMap[$countryAttributeName];
        $countryAttributeContent = $countryAttribute->content();
        if ( is_array( $countryAttributeContent ) )
            $countryAttributeContent['value'] = $country;
        elseif ( is_object( $countryAttributeContent ) )
            $countryAttributeContent->setAttribute( 'value', $country );
        // not sure that this line is needed since content is returned by reference
        $countryAttribute->setContent( $countryAttributeContent );
        $countryAttribute->store();

        return true;
    }
727845
public function hasGuide(User $user)
    {
        $isGuide = false;

        foreach ($this->getPortfolioGuides() as $portfolioGuide) {
            if ($user->getId() === $portfolioGuide->getUser()->getId()) {
                $isGuide = true;
                break;
            }
        }

        return $isGuide;
    }
298897
public function activate(User $user)
    {
        $user->is_activated = ! $user->is_activated;
        $user->save();

        if ($user->is_activated) {
            return $this->notifySuccess('User ' . $user->name . ' activated!');
        } else {
            return $this->notifySuccess('User ' . $user->name . ' deactivated!');
        }
    }
522222
public function findPlatformRoles(User $user)
    {
        $dql = "
            SELECT r FROM Claroline\CoreBundle\Entity\Role r
            JOIN r.users u
            WHERE u.id = {$user->getId()} AND r.type = ".Role::PLATFORM_ROLE;
        $query = $this->_em->createQuery($dql);

        return $query->getResult();
    }
1048739
public function isCountryAllowedForUser($userId, $country)
    {

        $query = $this->createQueryBuilder('p')
            ->select('p')
            ->where('p.user = :userId')
            ->setParameter('userId', $userId)
            ->getQuery();

        $data = $query->getResult();
        $return = false;

        foreach ($data as $availableCountries) {
            /** @var \PServerCore\Entity\AvailableCountries $availableCountries */
            if ($availableCountries->getCntry() == $country) {
                $return = true;
                break;
            }
        }
        return $return;
    }
741184
public function isGrantedTo($user): bool
    {
        $userModel = config('auth.providers.users.model');

        if (is_int($user) && !$userModel::find($user)) {
            return false;
        }

        return $this->users()->where('user_id', is_int($user) ? $user : $user->id)->exists();
    }
590359
private function userAttemptBruteForceLock(User $user)
    {
        if ($this->userAttemptBruteForceLockHasExceeded($user)) {
            return true;
        }
        
        $this->attempts = $user->login_attempt + 1;
        
        if ($this->attempts >= $this->allowedAttempts) {
            $user->updateAttributes(['login_attempt_lock_expiration' => time() + $this->lockoutTime]);
        }
        
        $user->updateAttributes(['login_attempt' => $this->attempts]);
    }
1304879
protected function _getForeignCountryUserVat(\OxidEsales\Eshop\Application\Model\User $oUser, \OxidEsales\Eshop\Application\Model\Country $oCountry)
    {
        if ($oCountry->isInEU()) {
            if ($oUser->oxuser__oxustid->value) {
                return 0;
            }

            return false;
        }

        return 0;
    }