=== TINXDK WP - Ean Betaling ===
Contributors: tinxdk
Tags: woocommerce, ean, nemhandel, invoice, payment gateway
Requires at least: 6.3
Tested up to: 6.8
Requires PHP: 8.2.35
Requires Plugins: woocommerce
WC requires at least: 8.0
WC tested up to: 11.2
Stable tag: 1.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

EAN (NemHandel) payment method for WooCommerce. Free edition with EAN validation and ALTCHA; a TINXDK license unlocks live EAN/CVR lookup, production units (P-numbers), risk assessment, handling fee, Subscriptions support and automatic updates.

== Description ==

**English**

Let business and public-sector customers pay by invoice with their EAN number. The plugin adds the payment method "EAN-betaling" to WooCommerce (classic checkout and Checkout Blocks):

* Live lookup of the EAN number in NemHandel/Peppol (directory.peppol.eu, with the public NemHandel Register registration.nemhandel.dk as fallback for NemHandel-only participants) and the company in the Danish CVR register (cvrapi.dk), including selectable active production units (P-numbers).
* Validation: 13 digits, GS1 check digit, blocklist, optional rejection of EAN numbers not found in NemHandel.
* Reference person and requisition number (required / optional / hidden).
* Risk assessment per order with severity levels (info / warning / danger): unknown EAN, failed lookup, ended or bankrupt company, ended production unit, shipping postcode mismatch, first use, usage history and locally reported misuse.
* Optional handling fee that only applies when the EAN method is chosen.
* WooCommerce Subscriptions support (EAN data is copied to renewal orders, subscriptions can be kept active on renewal, and customers can change a subscription's payment method to EAN).
* HPOS compatible. EAN data is shown on the order screen, in the orders list, in emails, on the thank-you page and in My Account.
* ALTCHA proof-of-work spam protection, self-hosted (no third-party service). Registry look-ups are cached (24 hours by default).
* If the registries are unreachable the checkout is never blocked; the order is flagged and an optional (throttled) error email is sent.

**Free edition and license**

The free edition is fully usable: the EAN payment method (classic checkout and Checkout Blocks), EAN number validation (13 digits, GS1 check digit, blocklist, test mode), reference person and requisition number, EAN data on orders (HPOS), in the admin, in emails, on the thank-you page and in My Account, and ALTCHA spam protection.

A TINXDK license unlocks: live EAN lookup in NemHandel/Peppol (incl. "Reject unknown EAN numbers" and cache lifetime), CVR company lookup, selectable production units (P-numbers), risk assessment and misuse reports, handling fee, WooCommerce Subscriptions support, API error emails and automatic updates from the TINXDK license server. Licensed settings stay visible but disabled without a license and your saved values are kept. Enter the key under WooCommerce > Settings > Payments > EAN payment > License. The license check sends only the license key, site URL and plugin/WordPress/PHP versions to licens.tinxdkcloud.dk.

External services: directory.peppol.eu and registration.nemhandel.dk (EAN lookup) and cvrapi.dk (company lookup). The EAN or CVR number entered at checkout is sent to these services.

**Dansk**

Lad erhvervs- og offentlige kunder betale via faktura med deres EAN-nummer. Pluginet tilføjer betalingsmetoden "EAN-betaling" til WooCommerce (klassisk kasse og Checkout Blocks) med live-opslag i NemHandel/Peppol og CVR-registeret, valg af produktionsenhed (P-nummer), validering af EAN-nummer (13 cifre + kontrolciffer), referenceperson og rekvisitionsnummer, risikovurdering, håndteringsgebyr, understøttelse af WooCommerce Subscriptions og selvhostet ALTCHA-spambeskyttelse. Dansk oversættelse er inkluderet.

Gratis udgave: betalingsmetoden, validering af EAN-nummer (kontrolciffer), referenceperson, rekvisitionsnummer, visning på ordrer/mails og ALTCHA virker uden licens. En TINXDK-licens låser op for live-opslag (NemHandel/CVR), produktionsenheder, risikovurdering, håndteringsgebyr, Subscriptions-understøttelse og automatiske opdateringer. Indtast licensnøglen under WooCommerce > Indstillinger > Betalinger > EAN-betaling > Licens.

Testnummer til testkøb (kræver testtilstand): 9999888877778.

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/` and activate it (WooCommerce must be active).
2. Go to WooCommerce > Settings > Payments > EAN payment and configure the method.

== Frequently Asked Questions ==

= The checkout shows no EAN fields in Checkout Blocks =
Make sure the payment method is enabled. The block script needs no build step; clear any script-optimisation caches.

= Which hooks can I use? =
See README.md in the plugin folder (filters `tinxdk_ean_risk_flags`, `tinxdk_ean_blocked_numbers`, `tinxdk_ean_ean_registry`, `tinxdk_ean_company_registry` and more).

== Changelog ==

= 1.1.0 =
* New: License system with a free edition and a licensed edition. Free: EAN payment method, EAN validation (check digit), reference person, requisition number, order data display (admin, emails, thank-you, My Account), ALTCHA. Licensed: live EAN lookup, CVR company lookup, production units, risk assessment, handling fee, Subscriptions support.
* New: Automatic updates through the TINXDK license server (needs an active license). License section in the EAN payment settings.
* Changed: Licensed settings are shown disabled with a "Requires license" label without a license; saved values are kept and apply again when a license is active.

= 1.0.3 =
* Changed: Requires PHP 8.2.35 or newer. On older PHP the plugin stays inactive and shows an admin notice.

= 1.0.2 =
* Fix: Checkout Blocks no longer clears the billing address typed just before choosing or leaving the EAN payment method (the fee refresh no longer X =
* Security: ALTCHA challenges can no longer be forged by moving digits between salt and number (strict salt/number format); replay protection is now atomic (options table, daily cleanup); ALTCHA is verified before any registry lookup.
* Fix: Checkout Blocks now actually passes the EAN fields to the server (the payment context was read with isset, which is always false).
* Fix: The handling fee is decided from the real payment method of the order (Store API request) and can no longer be avoided or leak to other gateways through the client-controlled flag.
* Fix: EAN is no longer hidden for subscription carts in Checkout Blocks.
* Fix: Stock is reduced through wc_maybe_reduce_stock_levels() so it is restored when the order is cancelled.
* Fix: Re-fetching EAN data no longer overwrites existing data when the registry lookup fails; admin notices after re-fetch and misuse report; misuse reports need the manage_woocommerce capability; admin CSS only on order screens.
* Fix: Previous-usage risk only counts earlier orders and no longer silences WooCommerce notices.
* Fix: Availability uses the order's billing country on the order-pay page.
* Fix: Plain-text emails no longer show HTML entities.
* Fix: The classic checkout script is no longer loaded on the block checkout page.
* New: NemHandel Register fallback when the Peppol Directory does not know the EAN number (an unreachable register never rejects an order).
* New: Registry lookups are memoised per request, time out after 5 seconds (filter tinxdk_ean_http_timeout), failures are cached for 5 minutes and "not found" for at most 1 hour; company lookup uses the exact CVR and rejects mismatching companies.
* New: Subscriptions: "Keep subscription active on renewal" setting, EAN data synced for all subscription order types and when a failing payment method is replaced, change of payment method to EAN.
* New: Client IP filter for the rate limiter (IPv6 grouped per /64); uninstall removes transients, replay rows, user meta and works on multisite.
* Improved: Checkout Blocks keeps the entered values when switching payment method, translated and expiring ALTCHA widget, accessibility attributes, description rendered as plain-text paragraphs, message when the EAN is found without company name.

= 1.0.0 =
* Initial release.
