# 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).
- **Live courier rates:** **Settings > Checkout rates** (switch on, services, names customers see, price change
  (add to or take off the label price), rounding, rates shown), then add
  the **Live courier rates** method to WooCommerce shipping zones that also have a method every customer can use (Free
  shipping that needs a coupon or minimum spend does not count). Needs a linked
  account, a GBP store and a UK sending address. Logs: WooCommerce > Status > Logs, source `parcel2go-live-rates`.
  See [Live courier rates](designs/checkout-live-rates.md).
- **Locker and shop services:** pick a pickup point service, such as **InPost - Locker to Locker** or **Evri -
  ParcelShop to ParcelShop**, in **Settings > Checkout rates** (shown as "(pickup point)"). Customers then choose where to collect at checkout. Set
  the checkout phone field to **Required** (the checkout page editor for the checkout block, or **Appearance >
  Customize > WooCommerce > Checkout** for the classic checkout): the couriers need the customer's phone, and the
  settings screen warns until it is.
- **Tracking in the customer email:** **WooCommerce → Settings → Emails → Completed order → Parcel2Go tracking**
  (ticked by default). Unticked, the Completed order email has no Parcel2Go tracking section. Developers can also
  turn it off with `add_filter( 'parcel2go_shipping_email_tracking', '__return_false' );`.
- **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`.
