=== Batchly for WooCommerce ===
Contributors: batchly
Tags: woocommerce, pos, inventory, sync, orders, delivery, batchly
Requires at least: 6.0
Tested up to: 6.6
Requires PHP: 7.4
WC requires at least: 7.0
Stable tag: 0.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

One inventory for your counter and your website. Stock and prices change in Batchly and show up in WooCommerce within a minute; online orders take stock down by exactly what sold and land in your Batchly Orders queue.

== Description ==

Batchly for WooCommerce keeps your online store on the same inventory as your Batchly register.

* **Real-time, two-way.** Every quantity change in Batchly (a register sale, an inventory edit, a CSV import, an online cart, an API write) is pushed to your WooCommerce store, signed, within about a minute. Price and name changes ride the same rail.
* **Online orders move stock by exactly what sold.** A paid WooCommerce order takes Batchly stock down by the quantity on each line, once, through an idempotent ledger. Cancellations and refunds with restock put back only what was taken.
* **Orders in one queue.** Each WooCommerce order becomes a Batchly ticket, marked paid on the website. When the shipping method means delivery, it goes on the driver route with the customer's requested date, address and window.
* **Reconcile before you trust it.** Reconcile now compares both sides by SKU (quantity and regular price), shows every difference, and lets you apply one side to the other. Real-time sync can only be switched on after a clean reconcile less than 24 hours old.
* **Batchly is the count of record.** Manual stock edits in WordPress admin are ignored unless you turn on the push setting. Products are never created in Batchly from WooCommerce.

Payments stay in your WooCommerce payment gateway. This plugin never sees card data and never holds a gateway key; it talks only to the Batchly API with a per-store key, over https, to a pinned host.

== Installation ==

1. In Batchly, open **Developers** and create an API key with the scopes `read`, `inventory:write`, `orders:write` and `sync:manage`. Copy it once.
2. In WordPress: **WooCommerce > Batchly**, paste the API key, save, and press **Test connection**.
3. Press **Connect real-time sync**. Your site must be reachable over public https.
4. Pick the shipping methods that mean delivery and, if you use a delivery-date plugin, enter its order meta key. Save sync settings.
5. Press **Reconcile now**. Resolve any differences (Apply Batchly to WooCommerce is the usual choice), then reconcile again.
6. Press **Turn on real-time sync**.

A `bly_test_` key lets you rehearse the whole flow: tickets land in Batchly's Test view, stock is never changed, and real-time stays off until you reconnect with a live key.

Upgrading from 0.2.0: after the update, press **Connect real-time sync** once (orders are not sent to Batchly until you do), then **Reconcile now**. Orders paid before the upgrade already moved Batchly's stock and are not sent again.

Deleting the plugin removes its settings, the saved API key and signing secret, and its two tables.

== Frequently Asked Questions ==

= A customer pays cash on delivery. Is the order marked paid? =

No. Orders paid with a method listed under "Payment methods collected at the door" (default: Cash on delivery) reach Batchly with the amount due, and the driver collects it.

= What happens if my site goes down? =

Batchly keeps retrying each push for about six hours, then parks it. When the site is back, press Reconcile now to catch up. Orders placed while Batchly was unreachable wait in the plugin's outbox and are sent when it is reachable again.

= I edit stock in WordPress. Does Batchly see it? =

Not by default. Batchly is the count of record. If you need WordPress edits to move Batchly, turn on "Push manual stock edits made in WordPress to Batchly" under Real-time sync.

= A product is on sale in WooCommerce. What does a Batchly price change do? =

It updates the regular price only. The WooCommerce sale price is left alone.

= Do variations sync? =

Yes, when each variation carries its own SKU that matches Batchly.

== Changelog ==

= 0.3.0 =
* Real-time, two-way sync: Batchly pushes signed inventory.changed and product.updated events to a new HMAC-verified receiver at /wp-json/batchly/v1/events; applied within about a minute.
* Online orders move Batchly stock by delta through an idempotent ledger (processing or completed, once); cancellations and refunds with restock reverse only what was applied.
* Orders are mirrored into the Batchly Orders queue as paid tickets; delivery shipping methods and a delivery-date meta key put them on the driver route.
* Reconcile now: per-SKU comparison, Apply Batchly to WooCommerce, Push WooCommerce to Batchly, optional creation of missing products in WooCommerce. Real-time is gated on a clean reconcile.
* Outbox with retry and backoff; Needs attention list with Retry and Discard; Activity log of received pushes.
* API base URL pinned to an exact host allowlist; manual stock edits in WordPress are no longer pushed unless the setting is on.
* Settings page rebuilt: Connection, Real-time sync, Reconcile, Activity.

= 0.2.0 =
* Hardened for install: API base URL restricted to Batchly hosts, API key masked in the settings page (blank submit keeps the saved key), catalog pull paginated for stores over 200 SKUs.
* Test mode: a bly_test_ key records orders in Batchly's Test view without touching live stock.
* Idempotent order recording (wc-{order}-{item} references) so a re-fired order never double-counts.

= 0.1.0 =
* Initial release: catalog and inventory sync, order recording, settings page.
