=== Tellbill for WooCommerce ===
Contributors: tellbill
Tags: invoice, billing, qr-bill, switzerland
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.4.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Automatically creates a Swiss QR-bill invoice in Tellbill for every WooCommerce order, and marks the order paid once the invoice is settled.

== Description ==

[Tellbill](https://tellbill.ch) is a Swiss invoicing service: QR-bill invoices (ISO 20022), automatic payment reminders, bank reconciliation and credit notes. This plugin connects your WooCommerce shop to your Tellbill account.

**What it does**

* When an order reaches the trigger status you choose (default: "Processing"), the plugin calls the Tellbill API and creates the matching invoice — with a Swiss QR code — then (optionally) emails it to your customer.
* The Tellbill invoice number is displayed in the orders list and in the order notes.
* **Payment sync (optional):** when the customer pays the QR-bill, Tellbill notifies WooCommerce through a signed webhook and the order is automatically marked as paid (stock, downloads, etc.).
* **Refunds:** a WooCommerce refund automatically creates the matching credit note in Tellbill (VAT included; full refund = full credit note).
* **Duplicate-safe:** each order is sent with a unique identifier (`external_id = "wc_<order id>"`). If the same order is sent twice (double status change, network retry), Tellbill returns the existing invoice instead of creating a duplicate.

**Requirements:** a Tellbill account (https://tellbill.ch) and an API key.

**Which trigger status should you choose?**

* **Invoice-based selling** (very common in Switzerland: the customer receives the goods, then pays within X days): trigger "Processing" or "Completed". The invoice carries your payment term; if the customer is late, Tellbill sends reminders automatically.
* **Prepayment by QR-bill** (the customer pays *before* you ship): enable the "Direct bank transfer" gateway so the order lands in "On hold", and set the trigger to "On hold". The customer receives the QR-bill, pays, then you ship.
* **Paid online** (card at checkout): trigger "Processing" — the Tellbill invoice then serves as a receipt and accounting record.

== Installation ==

1. Upload the plugin through Plugins → Add New → Upload Plugin (or copy the folder to `wp-content/plugins/`), then activate it.
2. Go to WooCommerce → Settings → "Tellbill" tab.
3. Paste your Tellbill API key (Tellbill panel → Settings → API & integrations).
4. Pick the trigger status, the payment term and the default VAT rate, then use the "Test connection" button.

**Payment sync (optional):** in your Tellbill panel → Webhooks, create an endpoint pointing to the URL shown in the plugin settings (`https://your-site/wp-json/tellbill/v1/webhook`), subscribed to the `invoice.paid` event. Then paste the signing secret shown by Tellbill into the plugin settings. Requests are verified with an HMAC-SHA256 signature and a 5-minute anti-replay window; while no secret is configured, the endpoint rejects all requests.

== External services ==

This plugin communicates with the Tellbill API (https://tellbill.ch) — the invoicing service it connects to; that is its sole purpose. No data is sent until you configure your API key.

Data transmitted to the Tellbill API (https://tellbill.ch/api/v1, or the URL you configure):

* When an invoice is created (order reaching the trigger status): the customer's billing details (name, email, address), the order lines (item names, quantities, prices) and the order number.
* When a refund is issued: the refunded amount and the refund reason.
* When you click "Test connection": only your API key is transmitted (as a header).

This data is required to issue the invoices. It is processed by Tellbill according to its terms of service and privacy policy:

* Terms of service: https://tellbill.ch/cgu
* Privacy policy: https://tellbill.ch/confidentialite

== Frequently Asked Questions ==

= Do I need a Tellbill account? =

Yes. The plugin is a connector: invoices are created, sent and reconciled by Tellbill. You can create an account on https://tellbill.ch.

= In which languages are the invoices sent? =

Tellbill issues the invoice PDF and the email in the customer's language (French, German, Italian or English), configurable per customer in your Tellbill panel.

= What happens if the API is unreachable when an order comes in? =

The plugin adds a note to the order with the error message. You can re-trigger the invoice by setting the order status again — thanks to the `external_id`, no duplicate will ever be created.

== Translations ==

The plugin ships with German (de_DE, de_CH), Italian (it_IT) and English (en_US, en_GB) translations — the four Swiss business languages are covered out of the box. Source strings are in French (built for the Swiss market). A `.pot` template is bundled in `/languages` for any additional language.

== Screenshots ==

1. The settings tab: API key, trigger status, payment term, VAT rate and payment sync.
2. The Tellbill invoice number in the WooCommerce orders list.
3. Order notes: invoice created, marked as paid, credit note issued on refund.

== Changelog ==

= 1.4.2 =
* Review fix: the admin JavaScript and CSS are now loaded via the standard `wp_enqueue_script` / `wp_enqueue_style` functions (with `wp_localize_script` for the nonce and labels) instead of being printed inline.
* Translations are now delivered through WordPress.org language packs (translate.wordpress.org) and loaded automatically; the plugin no longer ships or manually loads bundled translation files.

= 1.4.1 =
* Security: the payment-sync endpoint now rejects ALL requests until a signing secret is configured (previously, an empty secret meant requests were accepted unverified).
* WordPress.org compliance: plugin renamed "Tellbill for WooCommerce" (trademark rules), English readme, Requires Plugins / License URI headers, admin notice when WooCommerce is inactive, "External services" disclosure, translators comments, bundled .pot file.
* Bundled translations: German (de_DE, de_CH), Italian (it_IT) and English (en_US, en_GB).

= 1.4.0 =
* WooCommerce refund → Tellbill credit note, created automatically, VAT included (full refund = full credit note; partial refunds grossed up by the VAT rate when WooCommerce does not handle tax). One credit note per refund (duplicate-safe).

= 1.3.0 =
* "Test connection" button in the settings (validates the API key).
* Plugin internationalized (i18n): all strings are translatable.

= 1.2.0 =
* Payment sync: Tellbill webhook (invoice.paid) → the WooCommerce order is automatically marked as paid. Signed REST endpoint (HMAC), mapped via external_id.

= 1.1.0 =
* Configurable payment term (payment_term_days).
* Default trigger status = "Processing"; guidance for the 3 selling models in the settings.

= 1.0.0 =
* Initial release: invoice created on order, duplicate-safe (external_id), orders-list column + order notes, HPOS compatible.
