# Connector module (`connector`)

What the Business Central connector has relied on since plugin 1.x, rebuilt
inside 2.0 so the update from 1.2.0 changes nothing a store or Business Central
uses (AB#2379). It needs no price list: it loads on WooCommerce 7.9 or later,
whether price lists are switched on or off.

| Class | What it does |
| --- | --- |
| `ConnectorRequest` | The User-Agent test 1.2.0 applied: the header contains `Synfynal`, in any case. |
| `Rest\Endpoints` | `wc/v3/bccentralconnector/ping`, `/user-roles`, `/eligible-roles` as in 1.2.0, and `/version`. |
| `Customers\UserRole` | The `user_role` customer meta: mirrors the customer's role, and lets the connector change it. |
| `Customers\ElexEligibility` | `elex_discount_eligible` on every customer response, and the connector's writes to ELEX's lists. |
| `Products\PolylangSync` | On `should_update`, copies a product's data and categories to its Polylang translations. |
| `Admin\AppSourceLink` | The plugin row's "WooCommerce Connector" link to Microsoft AppSource. |
| `Install\Uninstaller` | Removes both customer meta keys, called by the plugin's `Uninstall` only with the opt-in. |

## Routes

All under `/wp-json/wc/v3/bccentralconnector`, so WooCommerce's key
authentication covers them. Every route needs the connector's User-Agent
(else **403** `rest_forbidden_user_agent`) and a user who can `list_users`
(else **401** `rest_forbidden`).

| Route | Answer |
| --- | --- |
| `GET /ping` | `[]` |
| `GET /user-roles` | `[{ "slug": "customer", "name": "Customer" }, …]`, every registered role |
| `POST /eligible-roles` `{ "roles": [ … ] }` | `{ "eligible_roles": [ … ] }`: known roles merged into ELEX's list, none removed |
| `GET /version` | `{ "version": "2.0.0", "capabilities": [ … ], "pricing": true }` |

`capabilities` lists `user_roles`, `elex_discount_eligibility` and
`polylang_sync` always, and `price_lists` when this store can run the price
lists (WooCommerce 8.0 or later). `pricing` is whether the price list routes are
registered right now, which is false while pricing is switched off.

## Behaviour kept from 1.2.0

- A customer write from another client only refreshes `user_role` to the
  customer's current role; it never changes the role.
- On a connector write, the first `user_role` entry counts. A role that is not
  registered is not applied.
- `elex_discount_eligible` is read from and written to ELEX's own option
  `eh_pricing_discount_product_on_users`; any stored copy of the meta is removed
  from the response so the value shows once.
- Activation gives every user without `user_role` their first role.

## Changed from 1.2.0

- `user_role` never sets a role that grants a privileged capability
  (`manage_options`, `manage_woocommerce`, `promote_users`, `edit_users`,
  `create_users`, `delete_users`, `list_users`, `edit_others_posts`,
  `unfiltered_html`, `activate_plugins`), and never changes a user who holds
  one. 1.2.0 refused only `administrator`, so a shop manager's key could make a
  customer a shop manager or an editor.
- `POST /eligible-roles` also needs `manage_woocommerce`, with the same 401
  refusal as a missing `list_users` (1.2.0 needed `list_users` only). The read
  routes are unchanged.
- Deactivation deletes nothing (1.2.0 deleted `user_role` on every user).
- Uninstall deletes `user_role` and `elex_discount_eligible` only when the store
  turned on **Delete data on uninstall** (1.2.0 always did). ELEX's options stay.
  User meta is shared by a multisite network, so there it goes only when every
  site turned the setting on.

## Tests

`tests/Unit/Connector/` and `tests/Integration/Connector/`, all in the
`connector` group. CI runs that group on WooCommerce 7.9 and next to the real
ELEX and Polylang plugins, and holds this folder to 90% line coverage.
