=== Vouchie for WooCommerce ===
Contributors: vouchie
Tags: vouchers, gift cards, woocommerce, vouchie, e-commerce
Requires at least: 6.8
Tested up to: 7.1
Stable tag: 0.4.1
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Sell and manage digital vouchers in your WooCommerce store, powered by the Vouchie platform.

== Description ==

**Vouchie for WooCommerce** connects your WordPress store to the [Vouchie](https://vouchie.pl) voucher management platform. When a customer purchases a voucher product, the plugin automatically creates the voucher via the Vouchie API and delivers it by email — no manual steps required.

= Key Features =

* **Automatic voucher issuance** — vouchers are created and sent as soon as the order has a recorded payment, using Action Scheduler for reliable async processing. Pay-later methods (cash on delivery, bank transfer) deliver the voucher once the order is marked paid or completed.
* **Idempotent API calls** — retries after network errors never create duplicate vouchers.
* **Flexible delivery** — send vouchers by email with optional PDF attachment, QR code, and Apple/Google Wallet links.
* **Webhook receiver** — receive real-time redemption and void events from Vouchie and add order notes automatically.
* **Refund handling** — automatically voids unused vouchers when an order is refunded (partially redeemed vouchers require manual handling).
* **HPOS compatible** — fully compatible with WooCommerce High-Performance Order Storage.
* **My Account integration** — customers can view their vouchers in the WooCommerce My Account area.
* **Pay with a gift card** (optional, off by default) — customers enter a Vouchie gift card code in the cart or at checkout (classic and block checkout). The card is a means of payment: its amount is deducted from the order total after tax and shipping, the balance is taken from the card when the order is placed, and any remainder is paid with the usual payment method.
* **Balance check shortcode and block** (optional, off by default) — `[vouchie_balance_check]` or the "Vouchie: gift card balance check" block (block editor, Widgets category, with a live preview) shows a card's status, remaining balance and expiry.

= Requirements =

* PHP 7.4 or higher
* WordPress 6.8 or higher
* WooCommerce 8.2 or higher
* An active Vouchie account (the Pro plan is recommended for online stores)
* A Vouchie API key with scopes: `vouchers:read`, `vouchers:write`, `customers:write`, `projects:read`, `vouchers:validate`, `vouchers:redeem`

= Plan Notice =

The plugin works within the limit of active vouchers of your Vouchie plan. The Pro plan is recommended for online stores. On the Free, Starter and Plus plans the plugin shows a warning in WooCommerce → Settings → Vouchie. When the limit is reached, Vouchie answers `402 Payment Required`. The plugin logs the error and adds an order note requesting manual handling.

== Installation ==

1. Download the plugin ZIP file from [https://vouchie.pl/integracje/woocommerce](https://vouchie.pl/integracje/woocommerce).
2. In your WordPress admin, go to **Plugins → Add New → Upload Plugin**.
3. Select the ZIP file and click **Install Now**.
4. After installation, click **Activate Plugin**.
5. Go to **WooCommerce → Settings → Vouchie** and enter your API key.
6. Click **Test Connection** to verify the connection.
7. Create a product with type **Vouchie Voucher** and configure the voucher settings in the **Vouchie** tab.

For detailed setup instructions, see the [Vouchie WooCommerce Integration Guide](https://pomoc.vouchie.pl/hc/baza-wiedzy/articles/vd-integracje-woocommerce-wtyczka).

== FAQ ==

= Does this plugin work without a Vouchie account? =

No. You need an active Vouchie account and an API key. Sign up at [vouchie.pl](https://vouchie.pl).

= Which Vouchie plan do I need? =

Any plan works, within its limit of active vouchers. The Pro plan is recommended for online stores. On the Free, Starter and Plus plans the plugin shows a warning in WooCommerce → Settings → Vouchie, with the limit and the number of active vouchers in use. When the limit is reached, Vouchie answers `402 Payment Required`, and the plugin adds an order note that explains it. The order does not get a voucher until you change the plan or deactivate unused vouchers.

= How do updates work? =

From 0.4.0 the plugin updates through the **Plugins** screen of WordPress, like any other plugin. WordPress checks vouchie.pl for new releases, and the plugin verifies the SHA-256 checksum of the downloaded package before it installs it. Automatic updates are optional: turn them on with the **Enable auto-updates** toggle next to the plugin. A site that blocks external requests must add `vouchie.pl` to `WP_ACCESSIBLE_HOSTS` in `wp-config.php`. Versions 0.3.5 and older do not receive this update: install 0.4.0 once by uploading the ZIP (**Plugins → Add New → Upload Plugin**), and later releases arrive through the Plugins screen.

= When is the voucher issued for cash on delivery or bank transfer orders? =

Only once WooCommerce has recorded a payment for the order. A voucher code is money, so reaching the "Processing" status is not enough: a cash-on-delivery order sits in "Processing" without a payment, and its voucher is created and sent when you mark the order "Completed". A bank transfer or cheque order is issued when you move it from "On hold" to "Processing" (or "Completed"). Online payments (cards, PayPal, etc.) and orders with a total of 0 (for example fully paid with a gift card) are issued immediately. While an order waits for payment it gets one order note, and you can still issue the voucher at once with **Generate voucher** in the Vouchie box on the order screen. Test and demo stores can turn on **Issue vouchers before payment is recorded** (WooCommerce → Settings → Vouchie → Advanced) to issue on "Processing" as before; keep it off on a live store.

= How do I put a voucher on sale? =

Like any WooCommerce product. A voucher without variations has a **Regular price** and a **Sale price** in the **General** tab, with an optional sale schedule; the shop then shows the regular price struck through next to the sale price. A voucher with variations has the same two fields on each variation. The voucher keeps its regular price as its value: a 200 voucher sold for 150 is issued for 200. A store that wants vouchers issued for the price paid can return `$product->get_price()` from the `vfw_voucher_face_value` filter.

= What happens if the API call fails? =

The plugin uses Action Scheduler to queue voucher creation. If the API call fails (e.g. due to a network error or rate limiting), Action Scheduler retries automatically with exponential backoff. No vouchers are lost.

= Does the plugin support partial refunds? =

The plugin voids a voucher on refund only if it has not been redeemed yet (`current_uses === 0`). Partially or fully redeemed vouchers require manual handling — the plugin adds an order note to alert you.

= How is VAT handled — single-purpose vs multi-purpose vouchers (SPV/MPV)? =

Under EU VAT rules the tax point depends on the voucher type, and you control it with the WooCommerce **Tax status / Tax class** on each voucher product:

* **Single-purpose voucher (SPV)** — the place of supply and the VAT rate are known when the voucher is issued (for example, an **Item** voucher for a specific service). VAT is accounted for **at the time of sale**. Set the product **Tax status / Tax class** to the service's rate.
* **Multi-purpose voucher (MPV)** — redeemable for a range of goods or services where the final VAT rate is not yet known (for example, an **Amount** voucher or a **Blank** voucher). VAT is accounted for **at redemption**, so the sale of the voucher itself is typically **not taxed**. Set the product **Tax status** to *None* (or a zero-rate tax class) accordingly.

The plugin performs no tax calculation of its own — WooCommerce derives tax from the product's tax class. Match each voucher product's **Voucher type** (in the Vouchie tab) to its **Tax status / class** so the tax point is correct.

= Is the plugin compatible with HPOS? =

Yes. The plugin uses WooCommerce order methods (`$order->update_meta_data()`, `$order->save()`) for all order data and is fully compatible with High-Performance Order Storage.

= What currencies are supported? =

PLN, EUR, USD, GBP, CHF, SEK, NOK, DKK, CZK, CAD, AUD, JPY. The store currency must match the currency configured in the plugin settings.

= How do I set up the webhook? =

In the Vouchie dashboard, go to **Settings → Webhooks** and add your store URL with the path `/wp-json/vouchie/v1/webhook`. The plugin handles signature verification automatically.

= WP-Cron is disabled on my server. Will the plugin still work? =

The plugin uses Action Scheduler, which requires WP-Cron or a system cron. If `DISABLE_WP_CRON` is set to `true`, configure a system cron job to call `wp-cron.php` every minute. The plugin displays a warning in the admin if it detects that WP-Cron is disabled.

== Screenshots ==

1. Plugin settings page — API key configuration and connection test.
2. Vouchie product tab — voucher type, denomination, and delivery options.
3. Order notes — automatic notes added after voucher issuance and redemption.
4. My Account — customer voucher list.

== Changelog ==

= 0.4.1 =
* Changed: internal changes only. The plugin works and looks the same as in 0.4.0.

= 0.4.0 =
* Added: updates through the WordPress Plugins screen. The plugin declares `Update URI: https://vouchie.pl/integracje/woocommerce`, WordPress checks vouchie.pl for new releases (at most one anonymous request per hour), and the downloaded package is verified with its SHA-256 checksum before it is installed. Auto-updates stay optional (the WordPress toggle).
* Added: a warning in WooCommerce → Settings → Vouchie when the account is on the Free, Starter or Plus plan, with the limit of active vouchers and the number in use. The Pro plan is recommended for online stores; lower plans are not blocked.
* Added: the connection test and the API key save read the plan of the account from the Vouchie API (`ApiClient::ping`).
* Changed: documentation links point to the Vouchie help center, and the plugin ZIP is downloaded from https://vouchie.pl/integracje/woocommerce.
* Upgrade: 0.3.5 and older do not update by themselves. Install 0.4.0 once by uploading the ZIP; later releases arrive through the Plugins screen.
* i18n: new strings translated to Polish.

= 0.3.5 =
* Fixed: error messages from Vouchie reach the store. Before, most failures showed only "Vouchie API error: HTTP" and a status code.
* Fixed: order notes, the admin email, the refund notes and the settings page (connection test, template refresh) explain an API failure in plain words: what happened, why and what to do next, for example the plan limit with "10 of 10 active vouchers" or a key without the permission it needs. Each voucher generation note also says whether the plugin retries.
* Fixed: a voucher creation error that retrying cannot fix (plan limit, rejected key, missing permission, invalid data) is reported at once instead of being retried four more times over 15 minutes.
* Changed: webhook events are deduplicated for 7 days instead of 1, so a late retry from Vouchie is not handled twice.
* Changed: when the Webhook Secret changes in the settings, the old secret moves to Previous Webhook Secret automatically, so deliveries signed with it keep being accepted during the rotation.
* Changed: unlimited vouchers ("Number of uses" 0) are created with an explicit unlimited number of uses. Vouchie now treats a voucher without a number of uses as single-use, so stores that sell unlimited vouchers must update to this version.
* Compatibility: new optional API fields and webhook events, the additional Standard Webhooks headers and webhook secret rotation in Vouchie need no change in the plugin.
* i18n: new strings translated to Polish.

= 0.3.4 =
* Fixed: the product editor of a Vouchie voucher opens on the General tab, where its price is, instead of Linked products.
* Fixed: uninstalling the plugin also removes the progress options of the 0.3.3 price upgrade.

= 0.3.3 =
* Changed: a voucher without variations (Item, Percentage, Blank, or Amount with "Predefined denominations only") is priced like any product, with the Regular price, Sale price and sale schedule in the General tab. A sale shows the regular price struck through, the sale badge and the sale in the shop, cart and block themes. The "Voucher price" field in the Vouchie tab is removed.
* Changed: an Amount voucher bought on sale keeps its regular price as its value (a 200 voucher sold for 150 is issued for 200). This applies to variations and to vouchers without variations. The `vfw_voucher_face_value` filter can switch it back to the price paid.
* Changed: a voucher priced by its variations or by the buyer's amount no longer keeps a price or sale schedule of its own (for example one left over from a simple product); they are removed when it is saved, as for a variable product.
* Fixed: a simple product switched to the Vouchie voucher type lost its price and showed as unavailable. It now keeps its Regular and Sale price.
* Changed: the Item description of an Item voucher is filled in with the product name by default; change it if the voucher should say something else.
* Fixed: an Item voucher bought while its product had no Item description was not issued, and retrying the order did not help. Retrying now issues it.
* Fixed: vouchers where the buyer enters the amount were hidden from the shop when "Hide out of stock items" was on.
* Fixed: an Item voucher without a price could be added to the cart for 0.
* Fixed: stock managed at product level now applies to a voucher sold at its own price. The manual stock status field, which had no effect on vouchers, is hidden.
* Fixed: the General tab (tax status, tax class) was hidden for voucher products.
* Upgrade: prices from the 0.3.2 "Voucher price" field keep working right after the update and become the Regular price when the product is saved. The plugin saves every voucher product once in the background of admin and cron requests (in batches, errors are logged), which also refreshes the stored price and stock status. Nothing needs to be done by hand.
* i18n: new strings translated to Polish.

= 0.3.2 =
* Added: "Voucher price" in the product's Vouchie tab for Item, Percentage and Blank vouchers. A voucher with a price and no variations is sold at that price with a plain "Add to cart" button, so a voucher for one specific service no longer needs a one-option variation.
* Fixed: an Item (or Percentage / Blank) voucher without variations showed "This product is currently out of stock and unavailable" and could not be bought.
* Fixed: the Variations tab and the "Used for variations" checkbox disappeared when an existing voucher product was opened in the editor.
* Fixed: a custom amount sent with the add-to-cart request is ignored for vouchers that do not offer a custom amount (predefined denominations, Item vouchers, fixed-price vouchers).
* i18n: new strings translated to Polish.

= 0.3.1 =
* Added: "Vouchie: gift card balance check" block (`vouchie/balance-check`) for the block editor, next to the `[vouchie_balance_check]` shortcode. It renders the same form and result as the shortcode, supports wide/full alignment, margin, padding, an HTML anchor and extra CSS classes, and shows a live, non-interactive preview in the editor. While "Public balance check" is off the block shows nothing on the site and a notice in the editor.
* i18n: new strings translated to Polish.

= 0.3.0 =
* Added: pay with a Vouchie gift card code in the classic and block cart/checkout (WooCommerce → Settings → Vouchie → Gift card payments, off by default). The card amount is deducted from the final order total (after tax and shipping), redeemed in Vouchie when the order is placed, shown in order totals, e-mails, My Account and the order admin.
* Added: cancelling an order paid by gift card flags the redemption "needs manual release" with an order note (the public API has no automatic reversal).
* Added: optional `[vouchie_balance_check]` shortcode with per-visitor rate limiting.
* Added: "Number of uses" 0 = no limit (balance cards), globally and per product.
* Changed: the API key now needs the `vouchers:validate` and `vouchers:redeem` scopes for gift card payments (six scopes in total).
* Changed (behaviour change for stores using cash on delivery or other pay-later methods): vouchers are issued only once the order has a recorded payment. A cash-on-delivery order in "Processing" no longer gets its voucher right away; it is issued when the order is marked "Completed". The new setting "Issue vouchers before payment is recorded" (Advanced, off by default) restores the old behaviour for test and demo stores.
* Fixed: "My Vouchers" showed only the currency (" PLN") in the Value column for vouchers bought as a predefined denomination; it now shows the voucher's value.
* Fixed: the `[vouchie_balance_check]` shortcode shows the balance in the store's price format (e.g. "115,01 zł") instead of "115.01 PLN".
* Fixed: redemption order notes from the webhook showed an empty amount ("partially redeemed for  PLN"); they now show the redeemed amount, or leave the amount out when Vouchie does not send one.
* Fixed: on WooCommerce 11 the block checkout rejected every order with "Please select a valid option" because the voucher selects were required. They are now optional, an untouched select gets the store default (as on the classic checkout), and on WooCommerce 9.9+ the voucher fields are hidden when the cart contains no voucher.
* i18n: new strings translated to Polish.

= 0.2.6 =
* Fixed: partial redemption of a multi-use voucher no longer shows as "Wykorzystany" in admin / My Vouchers — status reflects fully_redeemed (or is derived from remaining balance/uses when the flag is absent).
* Fixed: My Vouchers balance updates immediately after each redemption (customer transient cache invalidated on every webhook).
* Fixed: PDF download in My Vouchers renders with the product's voucher template, not the account default.

= 0.2.5 =
* Fixed: voucher limit reached (HTTP 402) and other terminal errors (auth / validation / not-found) no longer burn 5 retry attempts - they fail immediately with a clear, translated order note and an admin alert.
* Added: failure order notes are now localizable (PL + EN) via the Translator adapter.

= 0.2.4 =
* Fixed: signed voucher URLs (PDF/QR/Wallet) now use VOUCHIE_SIGNED_URL_SECRET (WALLET_PASS_URL_SECRET kept as legacy alias); the production error message names the real variable. Backend logs the specific signing/render failure cause instead of a bare 500. Plugin wc-logs now include HTTP status + error code + message when a PDF/QR URL fails. resolvePublicApiBaseUrl no longer hard-throws when app.url is a valid public host.

= 0.2.3 =
* Fixed: block checkout now requires the recipient name (when \"enter recipient\" is chosen) and the gift email (when \"send to recipient\" is chosen), and pre-selects the merchant default modes from plugin settings - the selects no longer show \"(optional)\".

= 0.2.2 =
* Fixed: block checkout now hides conditional fields (recipient name until \"enter recipient\" is chosen, gift email until \"send to recipient\" is chosen) - same logic as the classic checkout.

= 0.2.1 =
* Added: required API key scopes are documented under the API Key setting (vouchers:read, vouchers:write, customers:write, projects:read).

= 0.2.0 =
* Added: gift fields at checkout — "Who is this voucher for?" (blank / my details / enter recipient) and "Where should we send the voucher?" (don't send / my email / recipient's email) on both classic and block checkout.
* Added: recipient name is passed to the Vouchie API and rendered on the voucher PDF.
* Added: merchant setting for the default recipient mode at checkout.
* Added: "Checkout fields" settings section — show/hide each checkout field (delivery method, recipient, delivery email, gift message, scheduling).
* Added: configurable "Add to cart" button label for voucher products (product page + listing).
* Changed: email content options (PDF / QR / Wallet links) moved from checkout to merchant settings (product panel + global defaults) — customers no longer decide email contents.
* Changed: delivery-method labels no longer include emoji.
* Added: self-hosting runbook and external-host dev parameters.
* i18n: complete Polish translations for all settings.

= 0.1.1 =
* Added: "My Vouchers" page master toggle (off by default) to hide the page completely — no menu item, no endpoint, no trace.
* Fixed: webhooks now unwrap the data.object envelope so real deliveries sync voucher state.
* Fixed: redemptions use the authoritative fully_redeemed flag and the typed remaining union (monetary/uses/unlimited).
* Fixed: redemption order notes render the remaining balance; status labels match the Vouchie panel wording.

= 0.1.0 =
* Initial release.
* Plugin bootstrap, autoloader, and constants.
* Settings page with API key, currency, delivery method, and webhook configuration.
* Vouchie Voucher product type extending WC_Product_Variable.
* Per-product Vouchie panel with delivery method, content flags, and template ID.
* Order hooks for payment complete and order status completed events.
* Action Scheduler integration for async voucher issuance with exponential backoff.
* Idempotent voucher creation via Vouchie API v2.
* Voucher email with optional PDF, QR code, and Apple/Google Wallet links.
* Webhook receiver REST endpoint with HMAC signature verification and deduplication.
* Refund hook — automatic void for unused vouchers.
* HPOS compatibility audit.
* My Account endpoint for customer voucher list.
* Checkout delivery method picker.
* Pro plan warning banner with per-session dismissal.
* Admin order meta box with voucher details.
* Cron notice for disabled WP-Cron and stuck Action Scheduler actions.
* Logger with redaction of API keys and signatures.
* Polish and English translations.

== Upgrade Notice ==

= 0.4.1 =
Internal changes only. The plugin works and looks the same as in 0.4.0.

= 0.4.0 =
From this version the plugin updates through the Plugins screen. Versions 0.3.5 and older install 0.4.0 once by uploading the ZIP from https://vouchie.pl/integracje/woocommerce. The Vouchie settings tab now warns when the account is on the Free, Starter or Plus plan.

= 0.3.5 =
Clearer error messages with the cause and the next step, no automatic retries for errors that retrying cannot fix, and webhook events deduplicated for 7 days. When you change the Webhook Secret, the old one is kept as the previous secret until you clear it.

= 0.3.4 =
The voucher product editor opens on the General tab with the price. If you update from 0.3.2, the 0.3.3 notes below apply as well.

= 0.3.3 =
Vouchers without variations are now priced in the General tab (Regular price, Sale price, sale schedule), like any product, so a sale shows the regular price struck through. Prices set in the Vouchie tab in 0.3.2 keep working and are moved there automatically after the update. An Amount voucher bought on sale now keeps its regular price as its value.

= 0.3.0 =
Behaviour change: vouchers are now issued only after the order has a recorded payment. Cash-on-delivery orders get their voucher when you mark them "Completed". Test/demo stores can restore the old behaviour under WooCommerce → Settings → Vouchie → Advanced.

= 0.1.0 =
Initial release. No upgrade path from previous versions.
