=== incert Voucher Management System ===
Contributors: incertapps
Donate link: https://www.incert.at
Tags: woocommerce, vouchers, coupons, gutschein, incert
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 2.0.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Connects WooCommerce to the incert voucher platform — redeem, recharge, and cancel incert vouchers from your shop.

== Description ==

The incert Voucher Management System integrates your WooCommerce shop with the [incert](https://www.incert.at) voucher platform so customers can pay with incert vouchers at checkout and your shop stays in sync with incert when refunds or cancellations happen.

**What it does**

* Apply incert vouchers as a discount in the WooCommerce cart, with live validation against the incert API
* Support partly-redeemable and non-partly-redeemable vouchers, sponsoring vouchers, and package vouchers (Paketgutscheine)
* Redeem the voucher at incert when the order is set to Completed (idempotent — re-completing an order does not double-redeem)
* Recharge the voucher at incert on refund or partial refund, with a remainder storno when an order is cancelled after partial refunds
* Cancel the voucher at incert on full cancellation
* Show redeem / recharge / cancel status, IDs, and any API errors in the order sidebar
* Export a CSV / HTML preview of voucher-paid orders, filterable by purchase or booking date, including storno rows for cancellations and refunds
* All API calls are logged via **WooCommerce > Status > Logs** with correlation IDs

**Requirements**

* WooCommerce installed and active
* An active incert account with API access (API URL, auth token, booking partner ID)

== Installation ==

1. Install and activate the plugin.
2. Open **WooCommerce > Settings > incert Voucher Management** and enter your incert API URL, auth token, and booking partner ID.
3. Optional: configure whether vouchers apply to shipping, set the voucher discount type, and enable export columns.

== Frequently Asked Questions ==

= Does this plugin require WooCommerce? =

Yes. It hooks into the WooCommerce cart, order, and refund lifecycle.

= Do I need an incert account? =

Yes. The plugin talks to the incert API to validate, redeem, recharge, and cancel vouchers. Contact incert (https://www.incert.at) to get credentials.

= Where are API errors and logs? =

Detailed request logs go to **WooCommerce > Status > Logs** (look for the `incert-coupons` source). User-facing errors are shown in the order sidebar.

= What happens if I partially refund an order paid with an incert voucher? =

The plugin recharges the voucher at incert first, before any pro-rata split. If the order is later fully cancelled, a remainder storno row is emitted so the export sums to zero.

= Can I partially cancel an order paid with an incert voucher? =

No. incert is only updated on a full Cancel or Refund. The admin order sidebar warns about this.

== Screenshots ==

1. Order detail sidebar showing voucher status, redeem/recharge IDs, and API errors.
2. Cart and checkout with an incert voucher applied as a discount.
3. CSV / HTML export preview with status, date, and storno rows.
4. Plugin settings page (incert API URL, auth token, booking partner ID).

== Changelog ==

= 2.0.2 =
* **recharge:** send bookingID so recharge IDs reconcile with redemptions ([41f9a31](https://github.com/multysite/incert-woo-coupon/commit/41f9a3194648fd02f3fa2faa60ef55c4db734e57))

= 2.0.1 =
* Maintenance release — no functional changes (release and deploy pipeline fixes only)

= 2.0.0 =
* New major version
* Incert coupons can no longer be opened for editing from the coupon list ([#10](https://github.com/multysite/incert-woo-coupon/issues/10))
* Export preview and CSV now list the newest entries first ([#10](https://github.com/multysite/incert-woo-coupon/issues/10))
* Confirmed compatibility with WordPress 7.0 ([#10](https://github.com/multysite/incert-woo-coupon/issues/10))
* Redemption IDs in the export are no longer truncated to the WordPress order number — the full Incert redemption ID is shown ([#10](https://github.com/multysite/incert-woo-coupon/issues/10)) ([7c60e56](https://github.com/multysite/incert-woo-coupon/commit/7c60e562aca5d65efef9d8d1597fb5e32d215442))

= 1.4.3 =
* **deploy:** pin 10up action to 2.3.0 and gate at the job level ([#7](https://github.com/multysite/incert-woo-coupon/issues/7)) ([c7a2fae](https://github.com/multysite/incert-woo-coupon/commit/c7a2fae4caa5ca3bdd557c44cf4f445816f6cd39))

= 1.4.2 =
* **release:** chain build and deploy from release-please outputs ([#5](https://github.com/multysite/incert-woo-coupon/issues/5)) ([90d89d0](https://github.com/multysite/incert-woo-coupon/commit/90d89d02a7efe3750c467b196d79bd01b6823c0f))

= 1.4.1 =
* **public:** drop empty public CSS enqueue from frontend ([#2](https://github.com/multysite/incert-woo-coupon/issues/2)) ([f9fa87b](https://github.com/multysite/incert-woo-coupon/commit/f9fa87b6b7582b5c987201727a05adf9a91fd362))
* **redeem:** send pre-Incert gross total as bookingTotalAmount ([b46553f](https://github.com/multysite/incert-woo-coupon/commit/b46553f28d6f7864b791e532afbc80d390b8c4f4))
* **release:** unblock release-please by syncing version in build workflow ([#3](https://github.com/multysite/incert-woo-coupon/issues/3)) ([a4f753f](https://github.com/multysite/incert-woo-coupon/commit/a4f753f0a0a1d4a9704b002a839ac801330da985))

= 1.4.0 =
* Feature: prevent duplicate incert vouchers when an order is set back to "Completed" multiple times — submission is now idempotent and short-circuits with an order note when the order has already been transferred
* Feature: send the WooCommerce order number as `bookingID` and `comment`, the configured Booking Partner ID, and the order total to incert on every redeem; send the order number as `comment` on every order POST so incert can reconcile with the originating WooCommerce order
* Feature: capture cancel and recharge API failures with HTTP code and a 1KB response body excerpt, surface them in the order sidebar with an expandable details panel
* Feature: order sidebar now warns admins that purchased incert vouchers cannot be partially cancelled — incert is only updated on full Cancel or Refund
* Feature: log successful incert order cancellations so the audit trail is symmetric with redeem/recharge logs
* Fix: CSV export skips storno rows whose cancel or recharge failed at incert; the HTML preview keeps them and visually flags them as needing manual reconciliation
* Fix: orders cancelled after one or more partial refunds now emit a remainder storno row so the order's row group sums to zero in the export
* Fix: `bookingID` and `comment` always carry a non-empty value, falling back to the WC order ID when a third-party filter returns an empty `get_order_number()`
* Fix: stop writing `incert-coupons.log` into the WordPress root directory — all logging now goes through `WC > Status > Logs`

= 1.3.2 =
* Fix: deploy no longer breaks when copy-pasting the plugin folder; the bundled Incert PHP SDK is now copied into `vendor/` instead of symlinked, fixing the `Class "Incert\Client\Configuration" not found` fatal on production
* Fix: non-partly-redeemable vouchers now check against the remaining cart amount after previously-applied vouchers, not the full cart total — so a Paketgutschein can no longer be applied on top of vouchers that already cover the cart
* Fix: re-validating an already-applied voucher no longer drops it just because another voucher was added afterwards
* Fix: refunds on orders paid (in part) by Incert vouchers can now exceed the cash-paid portion, so the voucher-covered amount can be recharged via the existing partial-refund flow
* Fix: stale "Incert Gutscheinwert hat sich geändert" confirm flag is now cleared on the next page load when the snapshot is back in sync, so a reload is enough to unblock checkout

= 1.3.1 =
* Fix: vouchers that cannot be partially redeemed are now correctly blocked when the coupon value exceeds the cart total
* Fix: zero-amount sponsoring vouchers are now blocked with a clear error message
* Fix: improved error messages when a voucher cannot be applied
* Fix: export now shows the coupon face value (not the discounted price) in the sold column
* Feature: export now includes storno rows with negative values for cancelled and refunded orders
* Feature: export has a new status column (Abgeschlossen / In Bearbeitung / Storniert / Rückerstattet / Teilrückerstattung)
* Feature: export has a new date mode filter (purchase date vs. booking date), defaulting to booking date
* Feature: export now splits into separate ID, Reference, Purchase Date, and Booking Date columns
* Feature: partial refund storno rows are matched to the correct refund record

= 1.2.0 =
* Fix: partial refunds recharge Incert first (no pro-rata split)
* Fix: Woo coupons apply first; Incert overrides on matching code
* Feature: apply-to-shipping option rename and exclusion of shipping when disabled
* Feature: admin columns for redeemed amount and original total
* Feature: export preview with date filter, totals, refunds, and redemption/recharge IDs

= 1.1.0 =
* Apply Incert vouchers as store credit in cart totals.
* Set Incert voucher discount type.
* Cache Incert voucher lookups (request + short session).
* Throttle Incert voucher lookups to apply-coupon requests.
* Validate voucher value against totals including taxes, shipping, and fees.
* Include fees in Incert redeem amount.
* Add Incert redeem/recharge logging with correlation IDs.
* Preserve non-Incert coupon totals in cart.
* Simplify order tax normalization to coupon item totals only.

= 1.0.5 =
