# magefan/module-geoip

> Allows to get country code by IP

`composer require magefan/module-geoip`

Canonical URL: https://packagento.com/magefan/module-geoip

## At a glance

- **Vendor**: magefan (https://packagento.com/magefan.md)
- **Latest version**: 2.3.5 — released 2025-09-29
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/magefan/module-geoip and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require magefan/module-geoip:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

Allows to get country code by IP

## README

[![Total Downloads](https://poser.pugx.org/magefan/module-geoip/downloads)](https://packagist.org/packages/magefan/module-geoip)
[![Latest Stable Version](https://poser.pugx.org/magefan/module-geoip/v/stable)](https://packagist.org/packages/magefan/module-geoip)

<img  align="right" width="120" height="70" src="https://magefan.com/media/wysiwyg/made_in_ukraine.jpg">

This Magento 2 GeoIP module provides you PHP methods for getting customer country by IP, without any additional plugin for PHP.

It is used for [Magento 2 Currency Auto Switcher](https://magefan.com/magento-2-currency-switcher-auto-currency-by-country) and [Magento 2 Auto Language Switcher](https://magefan.com/magento-2-auto-language-switcher) by Magefan

### 🇺🇦 Stand with Ukraine! [How can you help?](https://magefan.com/blog/join-our-donations)

### Requirements
  * Magento Community Edition 2.0.x-2.4.x or Magento Enterprise Edition 2.0.x-2.4.x

### Installation Method 1 - Installing via composer
  * Open command line
  * Using command "cd" navigate to your magento2 root directory
  * Run command: composer require magefan/module-geoip
```
composer require magefan/module-geoip
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
```


### Installation Method 2 - Installing using archive
  * Install GeoIP2 PHP API (https://github.com/maxmind/GeoIP2-php).
  * Download [ZIP Archive](https://github.com/magefan/module-geoip/archive/master.zip)
  * Extract files
  * In your Magento 2 root directory create folder app/code/Magefan/GeoIp
  * Copy files and folders from archive to that folder
  * In command line, using "cd", navigate to your Magento 2 root directory
  * Run commands:
```
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
```

### How To Use
```
protected $ipToCountryRepository;

public function __construct(
    \Magefan\GeoIp\Model\IpToCountryRepository $ipToCountryRepository,
    ....//other code
) {
    $this->ipToCountryRepository = $ipToCountryRepository;
    ...//other code
}

public function example() {
    $visitorCountyCode = $this->ipToCountryRepository->getVisitorCountryCode();
    $someCountryCodeByIp = $this->ipToCountryRepository->getCountryCode('104.27.164.57');
    ...//other code
}
```

### Support
If you have any issues, please [contact us](mailto:support@magefan.com)
then if you still need help, open a bug report in GitHub's
[issue tracker](https://github.com/magefan/module-geoip/issues).

### Need More Features?
Please contact us to get a quote
https://magefan.com/contact

### License
The code is licensed under [Open Software License ("OSL") v. 3.0](http://opensource.org/licenses/osl-3.0.php).

This product includes GeoLite2 data created by MaxMind, available from
<a href="https://www.maxmind.com">https://www.maxmind.com</a>.

### Originally use these databases:
https://www.maxmind.com

http://software77.net/geo-ip/

### [Magento 2 Extensions](https://magefan.com/magento-2-extensions) by Magefan

#### [Magento 2 Google Extensions](https://magefan.com/magento-2-extensions/google-extensions)

  * [Magento 2 Google Indexing](https://magefan.com/magento-2-google-indexing-api)
  * [Magento 2 Google Analytics 4](https://magefan.com/magento-2-google-analytics-4)
  * [Magento 2 Google Tag Manager](https://magefan.com/magento-2-google-tag-manager)
  * [Magento 2 Google Shopping Feed](https://magefan.com/magento-2-google-shopping-feed-extension)
  * [Magento 2 Google Customer Reviews](https://magefan.com/magento-2-google-customer-reviews)

#### Magento 2 SEO Extensions

  * [Magento 2 SEO Extension](https://magefan.com/magento-2-seo-extension)
  * [Magento 2 Rich Snippets](https://magefan.com/magento-2-rich-snippets)
  * [Magento 2 HTML Sitemap](https://magefan.com/magento-2-html-sitemap-extension)
  * [Magento 2 XML Sitemap](https://magefan.com/magento-2-xml-sitemap-extension)
  * [Magento 2 Facebook Open Graph](https://magefan.com/magento-2-open-graph-extension-og-tags)
  * [Magento 2 Twitter Cards](https://magefan.com/magento-2-twitter-cards-extension)


#### [Magento 2 Speed Optimization Extensions](https://magefan.com/magento-2-extensions/speed-optimization)

  * [Magento 2 Google Page Speed Optimizer](https://magefan.com/magento-2-google-page-speed-optimizer)
  * [Magento 2 Full Page Cache Warmer](https://magefan.com/magento-2-full-page-cache-warmer)
  * [Magento 2 Image Lazy Load](https://magefan.com/magento-2-image-lazy-load-extension)
  * [Magento 2 WebP Images](https://magefan.com/magento-2-webp-optimized-images)
  * [Magento 2 Rocket JavaScript](https://magefan.com/rocket-javascript-deferred-javascript)

  ### [Magento 2 Admin Panel Extensions](https://magefan.com/magento-2-extensions/admin-extensions)

  * [Magento 2 Size Chart Extension](https://magefan.com/magento-2-size-chart)
  * [Magento 2 Security Extension](https://magefan.com/magento-2-security-extension)
  * [Magento 2 Admin Action Log](https://magefan.com/magento-2-admin-action-log)
  * [Magento 2 Order Editor](https://magefan.com/magento-2-edit-order-extension)
  * [Magento 2 Better Order Grid](https://magefan.com/magento-2-better-order-grid-extension)
  * [Magento 2 Extended Product Grid](https://magefan.com/magento-2-product-grid-inline-editor)
  * [Magento 2 Product Tabs](https://magefan.com/magento-2/extensions/product-tabs)
  * [Magento 2 Facebook Pixel](https://magefan.com/magento-2-facebook-pixel-extension)
  * [Magento 2 Email Attachments](https://magefan.com/magento-2-email-attachments)
  * [Magento 2 Admin View](https://magefan.com/magento-2-admin-view-extension)
  * [Magento 2 Admin Email Notifications](https://magefan.com/magento-2-admin-email-notifications)
  * [Magento 2 Login As Customer](https://magefan.com/login-as-customer-magento-2-extension)

#### Magento 2 Blog Extensions

_(README truncated for .md surface. Full README on https://packagento.com/magefan/module-geoip.)_

## Recent Versions

| Version | Released |
|---|---|
| 2.3.5 | 2025-09-29 |
| 2.3.4 | 2025-09-22 |
| 2.3.3 | 2025-09-08 |
| 2.3.2 | 2025-05-08 |
| 2.3.1 | 2024-05-24 |
| 2.3.0 | 2024-05-03 |
| 2.2.3 | 2023-09-06 |
| 2.2.2 | 2023-03-13 |
| 2.2.1 | 2023-02-17 |
| 2.2.0 | 2022-09-05 |

Showing 10 of 26 versions. Full release history on https://packagento.com/magefan/module-geoip.

## Dependencies

### Require

| Package | Constraint |
|---|---|
| geoip2/geoip2 | ^2.9.0 |
| magefan/module-community | >=2.2.17 |

### Suggest

| Package | Constraint |
|---|---|
| magefan/module-auto-currency-switcher | Install GeoIP Auto Currency Switcher Extension for Magento 2 (https://magefan.com/magento-2-currency-switcher-auto-currency-by-country). Use coupon code COMPOSER-FAN to get a 10% discount on magefan.com. |
| magefan/module-auto-language-switcher | Install GeoIP Auto Language/Store Switcher Extension for Magento 2 (https://magefan.com/magento-2-auto-language-switcher). Use coupon code COMPOSER-FAN to get a 10% discount on magefan.com. |

## Quality

Latest release (2.3.5) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | Pass | Pass |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 81 | 1 error, 80 warnings (ruleset: Magento2) — 31 auto-fixable with phpcbf |
| PHPMD | Warning | 18 | 18 rule violations (MissingImport:9, UnusedFormalParameter:4, EmptyCatchBlock:3, CyclomaticComplexity:1, NPathComplexity:1) |
| Cpd | Pass | 0 |  |
| Composer validate | Info | 3 | valid; 3 advisory notes (composer validate --strict) |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | 50 | 50 | – | – |
| 2.4.8 | – | 59 | 59 | – |
| 2.4.9 | – | – | 59 | 59 |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["magefan/module-geoip"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

magefan is a Magento 2 vendor on Packagento. See https://packagento.com/magefan.md for their full catalogue.

