=== Auditor Sync ===
Contributors: completin, freemius
Tags: woocommerce, bling, erp, inventory, stock
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 0.1.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Read-only audit of the WooCommerce and Bling ERP sync: finds stock, SKU, price and order divergences and warns you before they cost you sales.

== Description ==

Your WooCommerce store and your Bling ERP are supposed to show the same stock, the same prices and the same orders. When the integration between them fails silently, you sell products you no longer have, charge the wrong price or ship orders that never reached the ERP.

Auditor Sync compares both sides on a schedule and shows you every divergence in one dashboard. It is **read-only**: it never changes anything in Bling and never "fixes" WooCommerce on its own. It detects and reports, so you decide what to correct.

It works alongside the integration you already use (it does not replace it) and is a good neighbor to your Bling API limits: requests are throttled, paginated and backed off when Bling asks for it, with a configurable daily cap.

= What it checks =

* **Stock**: WooCommerce stock vs. the Bling balance (all deposits, available or physical balance), with a configurable tolerance. Products without stock management are compared by stock status.
* **Orphan SKUs**: products that exist on only one side.
* **Duplicate SKUs**: the same SKU used by two or more products on the same side.
* **Missing SKUs**: products without a SKU, which cannot be matched.

= Features =

* Divergence panel with a traffic-light status, search, filters and actions (ignore, mark as resolved, reopen).
* Divergences that disappear in the next audit are resolved automatically; ignored ones stay out of alerts.
* "Audit now" button and automatic audits every 12 or 24 hours.
* Daily e-mail digest with new divergences (never one e-mail per divergence).
* WordPress dashboard widget.
* Audit log screen.
* WP-CLI commands: `wp auditor-sync audit`, `divergences` and `runs`.
* Bling credentials encrypted at rest.
* Simple and variable products (variations with their own SKU).

= Pro =

Auditor Sync Pro adds:

* Audits every 15 or 30 minutes, or every 1, 3 or 6 hours, reading only what changed in Bling since the last audit.
* Price comparison (regular or active WooCommerce price vs. the Bling price, or the price of the Bling store linked to WooCommerce).
* Missing orders: paid WooCommerce orders that never reached Bling.
* Stock from selected Bling deposits only.
* E-mail digest after every audit or at most once per hour, and alerts when the Bling connection is lost or audits keep failing.
* Multiple e-mail recipients.

Pro includes a 14-day free trial, no credit card required.

= Requirements =

* WooCommerce 8.2 or newer.
* A Bling account (Bling API v3) where you can create an app (client ID and client secret).
* PHP 8.1 or newer.

== Installation ==

1. Install and activate Auditor Sync (WooCommerce must be active).
2. In Bling, create a private app (https://bling.com.br/cadastro.aplicativos.php). Set its redirect link to the address shown on the plugin's Connection tab and enable read access to the products, stock, sales orders and company basic data scopes.
3. Go to WooCommerce > Auditor Sync > Connection, paste the app's client ID and client secret and click Connect.
4. Click "Audit now" on the Dashboard tab. Adjust the schedule, stock balance and e-mail alerts on the Settings tab.

== Frequently Asked Questions ==

= Does the plugin change my data in Bling or WooCommerce? =

No. Auditor Sync only reads. It never writes to Bling and never changes products, stock, prices or orders in WooCommerce.

= Will it use up my Bling API limit? =

Bling allows 3 requests per second and 120,000 per day per account, shared with your other integrations. Auditor Sync stays at 2 requests per second at most, waits and retries when Bling answers "too many requests", and stops for the day at the cap you set (20,000 requests by default). The Settings tab shows how many requests it made today.

= Does it replace my WooCommerce–Bling integration? =

No. It audits the result of the integration you already use and tells you when it went wrong.

= How are products matched? =

By SKU, ignoring case and surrounding spaces. Products without a SKU are reported so you can fill it in.

= Why are short audit intervals late on my site? =

WordPress runs scheduled tasks when the site receives visits. On low-traffic sites, call wp-cron.php from a real server cron job so audits run on time.

= Does it support other ERPs? =

Bling only for now. The plugin was built so other ERPs can be added later.

== External services ==

This plugin connects to the following services.

= Bling API =

Auditor Sync reads your catalog, stock balances, stores and orders from Bling, the ERP you connect it to. It is required for the plugin to work.

* Your Bling app's client ID and client secret, the authorization code and the access and refresh tokens are sent to Bling to connect and keep the connection active (`https://www.bling.com.br/Api/v3/oauth/` and `https://api.bling.com.br/Api/v3/oauth/`).
* During audits, read-only requests are sent to `https://api.bling.com.br/Api/v3/`, containing Bling product IDs and, in Pro, WooCommerce order numbers and the chosen Bling store ID.
* Requests happen when you connect or test the connection, on each audit (manual or scheduled) and when the access token is renewed.

Bling terms of use: https://www.bling.com.br/termos-e-condicoes-da-plataforma-bling
Bling privacy policy: https://www.bling.com.br/politicas

= Freemius =

Licensing, the Pro trial, checkout and updates of the Pro version are handled by Freemius. Nothing is sent unless you opt in on the screen shown after activation or activate a Pro license. If you do, Freemius receives the data listed on that screen, such as your site URL, the admin's name and e-mail, and the WordPress, PHP and plugin versions.

Freemius terms of service: https://freemius.com/terms/
Freemius privacy policy: https://freemius.com/privacy/

== Screenshots ==

1. Dashboard: status light and divergence table with ignore, resolve and reopen actions.
2. Connection tab: connect your Bling app.
3. Settings: schedule, stock balance and e-mail alerts.
4. Audit log.
5. WordPress dashboard widget.

== Changelog ==

= 0.1.1 =
* Coding standards fixes from the Plugin Check review.
* Ship composer.json alongside the vendor folder.

= 0.1.0 =
* First release: Bling connection, stock and SKU audit, divergence panel, scheduled audits, e-mail digest, logs, dashboard widget and WP-CLI commands.

== Upgrade Notice ==

= 0.1.1 =
Coding standards fixes; no functional changes.

= 0.1.0 =
First release.
