=== CatCode Two-Way Sync with Square for WooCommerce ===
Contributors: catcodestudio
Tags: square, inventory, stock sync, pos, woocommerce
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Keeps stock in step between WooCommerce and Square in both directions, variations included, without losing a sale made on either side.

== Description ==

You sell online with WooCommerce and over the counter with Square. This plugin keeps the stock figure the same on both, for simple products and for each variation.

Square is a third-party product. This is an independent integration, not affiliated with or endorsed by Block, Inc. or Square.

= Why stock does not drift =

Most sync tools copy a number from one side to the other, so whichever side writes last wins and a sale made in between disappears. This plugin passes the change, not the number. Sold 2 at the counter and 1 online while the two sides were apart? Both end up 3 lower.

* **Both directions**, for simple products and each variation.
* **Square is read, not believed.** A notification only says that something changed. The figure itself is read from Square, so a late, repeated or out-of-order notification cannot put an old count into your store.
* **Signed notifications.** Each one is checked against its HMAC-SHA256 signature. A wrong one is refused.
* **Nothing is sent twice.** Every change has a fixed idempotency key, so a retry after a lost answer is not booked again.
* **Nothing is lost.** Changes are written to a queue in the same database transaction that recorded them, and wait there through an outage, a refused token or a rate limit. When Square has been away for over a day, the plugin checks what landed before it sends anything again.
* **Missed notifications are caught.** The store checks with Square on a schedule anyway and compares every linked product once a day. Stock edited by an import or directly in the database is picked up too.
* **Registers that were offline** keep their sales, because the plugin sends adjustments and never overwrites the count.
* **A staging copy stays quiet.** If the site's address changes, sync stops until you confirm that this is the real store, otherwise a copy of the site would count every sale again.
* **An empty answer does not empty your store.** If Square stops returning a count for a variation, the link stops and asks you to look.

= How you start =

1. Paste the access token of your Square application and choose a location.
2. Press **Compare with Square**. Products and variations are matched by SKU and you see both figures and everything left out, with the reason. Nothing changes yet.
3. Choose where to start from: the Square figures, the store figures, or neither, so that only changes from now on pass across.
4. Set up notifications with one button, if the site is on https. Without them the store checks with Square every minute.

The Activity tab shows what happened, what is waiting and what needs you.

= What it does not do =

* It does not take payments. Use any payment method you like.
* Products need a SKU on both sides to match.
* A variable product whose stock is kept on the parent cannot match, because Square counts each variation separately. Turn on stock for each variation.
* Items whose stock Square counts on their components are left out.
* Stores on whole units keep fractions on the Square side until they add up to a unit.

// @pro-begin
= Pro =

Sold on [catcode.com.ua](https://catcode.com.ua/modules/square-two-way-sync-woocommerce/) with a 7-day trial:

* **Product sync in both directions**: name, description, regular price, SKU and variations. New products can be created on either side. Square items arrive in the store as drafts.
* **Conflict rules for each field**: the store wins, Square wins, the latest change wins, or ask me, with a review list. Each side is compared with itself, so tidied HTML is never taken for a change.
* **Orders in both directions**: completed Square sales arrive as WooCommerce orders without touching stock a second time, and paid WooCommerce orders can be recorded in Square. Square charges a 1% fee on orders paid outside Square, so this is off by default, and stock stays in sync without it.
* **Several Square locations** counted as one store figure.
* **E-mail alerts** when Square refuses the token or a job gives up.

Pro does not sync images, categories, taxes, customers or sale prices. Orders sent to Square appear as plain lines, so that Square does not take the stock off a second time.

// @pro-end
== Installation ==

1. Install and activate the plugin. WooCommerce must be active.
2. Open **WooCommerce > Square Sync**.
3. In the [Square Developer Console](https://developer.squareup.com/apps) create an application and copy its Production access token. The token is kept encrypted with your site's keys.
4. Follow the steps on the Connection and Products tabs.

== Frequently Asked Questions ==

= Does this need a CatCode account? =

No. The plugin talks to Square directly, with your own Square application.

= Which permissions does the token need? =

A personal access token of your own application has all it needs. Square's notifications API accepts only this kind of token.

= Why is my stock negative? =

The last unit was sold on both sides at once. Both figures agree on the shortfall, the product shows as out of stock and the Activity tab names it.

= Is the sale a change of stock in Square reports? =

Store sales reach Square as stock adjustments marked sold. They are not orders, so they do not appear as sales in Square.

= What happens when I remove a link? =

Both sides keep their stock and go their separate ways. Nothing is deleted on either side.

== External services ==

This plugin connects to the Square API (connect.squareup.com, or connect.squareupsandbox.com when you choose Sandbox), a service of Block, Inc., which is what it exists for. It sends nothing until you connect a Square account.

* What is sent: your access token with each call; SKUs and stock changes of linked products; requests for your locations, catalog and stock counts; the address of this site's notification endpoint when you set up notifications.
* When: when you connect, compare or link, whenever linked stock changes, and on a schedule while connected.
* Square also calls this site with signed notifications about stock changes.

// @pro-begin
With Pro also: product names, descriptions, prices and SKUs when they change, and order lines, totals and the payment method title of paid orders if you switch that on. No customer details are sent.

The Pro build also connects to catcode.com.ua to check the license key and offer updates, sending the key and the site address when you activate and periodically after that. [Terms](https://catcode.com.ua/terms/), [privacy policy](https://catcode.com.ua/privacy/).

// @pro-end
Square [terms of service](https://squareup.com/us/en/legal/general/ua) and [privacy policy](https://squareup.com/us/en/legal/general/privacy).

== Screenshots ==

1. The comparison: both figures for each SKU, and what was left out and why.
2. The Activity tab: what ran, what is waiting, what needs a look.

== Changelog ==

= 1.0.0 =
* First release.
