=== PackAm ===
Contributors: surgentlabs
Tags: woocommerce, fulfilment, packing, order sync, barcode
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.3.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Connects WooCommerce to PackAm, the scan-to-pack app that checks every order is packed right before it ships.

== Description ==

PackAm links your WooCommerce store to [PackAm](https://packam.ng), the
scan-to-pack verification app for Nigerian merchants. It:

* Generates a one-time **connection key** and a private **store secret**, and
  exposes a handshake endpoint so PackAm can complete the connection.
* Signs every request in both directions with **HMAC-SHA256**, with a 5-minute
  timestamp window and nonce replay protection.
* Serves **order** and **product** reads through the WooCommerce CRUD layer, so
  it behaves identically on **HPOS** and legacy postmeta storage. HPOS
  compatibility is declared.
* Includes **product variations** and reports where variation SKUs are missing.
* Registers **webhooks** for order.created, order.updated and product.updated,
  with PackAm's reconciliation poller (a `modified_after` cursor on the read
  endpoints) as a backstop.
* Writes fulfilment back to WooCommerce: sets status, attaches tracking number
  and courier, adds an order note, and supports **partial fulfilment**.

This plugin does not collect or transmit any data until you connect it to a
PackAm account and complete the handshake.

Learn more and create a free PackAm store at [packam.ng](https://packam.ng).

== External services ==

This plugin connects your store to PackAm, a hosted service run by PackAm
([packam.ng](https://packam.ng)) that your packing team uses to scan and check orders. It is
needed for the plugin to do anything: without a PackAm account the plugin stays
idle and sends nothing.

Nothing is sent until a store manager generates a connection key under
WooCommerce → PackAm and enters it in PackAm. After that:

* **When an order is created or updated**, the plugin sends that order to
  api.packam.ng: order number, status, currency, total, payment method, the
  date created and last changed, the customer's billing name, phone number and
  email address, and each line item's product ID, name, SKU and quantity.
  Unfinished checkouts (draft orders) are never sent.
* **When a product is updated**, the plugin sends that product to
  api.packam.ng: its ID, type, name, SKU and image URL, and each variation's
  ID, SKU, attributes and image URL.
* **When PackAm asks for them**, over signed requests to this site's REST API,
  the plugin returns the same order and product details; the store's name,
  address (WooCommerce → Settings → General), currency, timezone and
  WooCommerce version; and the connection's health (last sync times and last
  error).
* **When an order is packed in PackAm**, PackAm calls this site to mark it
  completed (or partly packed), add the tracking number and courier, and leave
  an order note. Orders that are pending, on hold, cancelled, refunded,
  failed or already completed keep their status; only the tracking and note are added.

Each message includes this site's URL. Delivery addresses, payment details and
passwords are never sent. Disconnecting under WooCommerce → PackAm stops all
of the above.

* PackAm terms of service: [packam.ng/terms](https://packam.ng/terms)
* PackAm privacy policy: [packam.ng/privacy](https://packam.ng/privacy)

== Installation ==

1. Upload the `packam` folder to `/wp-content/plugins/`, or install the zip via
   Plugins → Add New → Upload.
2. Activate **PackAm** through the Plugins screen. WooCommerce must be active.
3. Go to **WooCommerce → PackAm** and click **Generate connection key**.
4. Copy the key (shown once) into PackAm to complete the connection.

== Frequently Asked Questions ==

= Does it work with High-Performance Order Storage (HPOS)? =

Yes. All reads and writes go through the WooCommerce CRUD layer, and the plugin
declares HPOS compatibility, so it works the same on custom-tables and legacy
storage.

= What happens if a webhook fails to deliver? =

Nothing is lost. PackAm polls your store on a schedule using a `modified_after`
cursor and reconciles anything a webhook missed.

= Can I rotate the secret? =

Yes. Rotation keeps the previous secret valid for 24 hours so nothing breaks
mid-rotation, but only the current secret can rotate it again. You can also
regenerate the connection key or disconnect at any time from WooCommerce →
PackAm. If you think a secret has leaked, disconnect or regenerate: that ends
access for every old secret at once.

== Screenshots ==

1. WooCommerce → PackAm shows the connection status and sync health.
2. A one-time connection key connects the store to PackAm.
3. When an order is packed, PackAm completes it in WooCommerce and adds the courier and waybill as an order note.
4. The packing phone: the order queue, scanning an item, a correct scan, and a wrong item caught before the box is sealed.
5. The PackAm dashboard shows each order's history, packed items and scan log.

== Changelog ==

= 0.3.2 =
* Security: PackAm no longer changes the status of an order that is pending,
  on hold, cancelled, refunded, failed, completed or still a draft. If such an order is
  sent from PackAm, the tracking number and a private note are added, but the
  status stays as it is and no customer email goes out.
* Security: unfinished checkouts (draft orders) are no longer sent to PackAm,
  so the contact details of shoppers who never placed an order stay on your
  site.
* Security: a fulfilment update from PackAm is read from the signed message
  itself. An empty or unreadable update is refused, and an item PackAm did not
  mention is no longer counted as packed.
* Security: after you rotate the store secret, the old secret can no longer be
  used to rotate it again. Order updates are only sent to an https address and
  never follow redirects. Failed sign-ins get one plain "Unauthorized" reply.
* Uninstalling on a multisite network now removes PackAm's settings from every
  site.

= 0.3.1 =
* Security: request signatures now cover the query string as well, so no
  parameter can be added to or changed in a signed request's URL. The order
  fulfilment endpoint reads the order ID from the signed route only.
  Requires PackAm's current API, which already sends the new signature.

= 0.3.0 =
* Security: request signatures are now bound to their direction, HTTP method
  and route, so a signed reply from the plugin can no longer be replayed as a
  request to it. Replies to requests that fail verification are no longer
  signed. Requires PackAm's current API, which already sends the new
  signature.
* Security: each request's nonce is claimed in one atomic database statement,
  so two copies of the same request arriving together can't both pass replay
  protection.

= 0.2.2 =
* Ready for the WordPress.org directory: tested with WordPress 7.1 and
  WooCommerce 11.3, declares WooCommerce as a required plugin, and suggests
  privacy policy text under Settings → Privacy.
* Removed the optional Sentry error reporting, which the distributed plugin
  could not load.

= 0.2.1 =
* A corrected waybill from the PackAm app now replaces PackAm's Shipment
  Tracking entry instead of adding a second one, and leaves the order status
  alone. A retried write-back no longer duplicates the entry either. Tracking
  added by staff or other plugins is untouched.

= 0.2.0 =
* Expose the store name + address (WooCommerce Settings → General) to PackAm for
  tax invoices: new signed GET /store endpoint, and the address is included in
  the handshake response. No new permissions; read-only.

= 0.1.0 =
* Initial release: handshake, signed sync, webhooks, fulfilment write-back,
  admin connection panel.
