# Configuration

Environment and plugin settings that affect behaviour.

## Sentry (optional)

Error reporting is optional and controlled by constants, typically set in `wp-config.php`:

| Constant | Description |
|----------|--------------|
| `PARCEL2GO_SENTRY_ENVIRONMENT` | Environment name sent with events (e.g. `staging`, `production`). Defaults to `production` if not set. |

If `PARCEL2GO_SENTRY_ENVIRONMENT` is not defined, the plugin falls back to `WP_ENVIRONMENT_TYPE` when that constant is set. These values are passed to the frontend via `parcel2goShipping.dsn` and `parcel2goShipping.environment` in `includes/Admin/Setup.php` (used when initializing Sentry in the React app).

## Parcel2Go API

Backend calls to the Parcel2Go API use the constants and list in `includes/Constants/P2GApi.php`. The plugin automatically detects the environment and uses production or development API endpoints accordingly.

### Environment Detection

The plugin determines which Parcel2Go API endpoints to use based on a plugin-only constant:

1. Set `P2G_FORCE_DEVELOPMENT` in `wp-config.php` to force development/test endpoints:
   ```php
   define( 'P2G_FORCE_DEVELOPMENT', true );
   ```

2. If `P2G_FORCE_DEVELOPMENT` is not defined (or is `false`), the plugin defaults to **production endpoints**.

The Parcel2Go API environment no longer depends on WordPress globals such as `WP_ENVIRONMENT_TYPE`.

### API Constants

| Constant | Purpose |
|----------|---------|
| `P2GApi::BASE_URL` | Base URL for the P2G API (determined by environment). |
| `P2GApi::TENANT_ID` | Tenant identifier (determined by environment). |
| `P2GApi::CACHE_EXPIRY` | Cache TTL in seconds (e.g. 300). |
| `P2GApi::P2G_SERVICES` | List of P2G service identifiers used for validation or filtering. |

## Store and plugin settings

- **Store address:** Used as origin for quotes and shipping. Configured in WooCommerce (e.g. **WooCommerce → Settings → General**). The plugin exposes it via the REST endpoint `GET /parcel2go-shipping/v1/settings/store` and links to the store address settings from the Settings UI (`storeAddressUrl` in localized config).
- **Plugin settings / default services:** The Settings page in the admin (path `/parcel2go-shipping/settings`) and the REST endpoints under `parcel2go-shipping/v1/settings` and `.../settings/default-services` let you view and update plugin options and default service configuration. The exact fields are defined in the Settings UI and in `includes/Api/SettingsController.php`.
