=== Lindyship ===
Contributors: aurefau
Tags: surecart, shipping, sendcloud, shippo, fulfillment
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 8.1
Requires Plugins: surecart
Stable tag: 1.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Connect SureCart to Sendcloud, Shippo, ShipStation or Packlink. Manually push orders and sync tracking numbers back via webhooks.

== Description ==

**Lindyship** is the bridge between your SureCart store and your shipping platform. Push orders manually from the Orders tab to your platform's incoming queue. When you ship the parcel, the tracking number comes straight back to SureCart and the built-in fulfillment email fires with no copy-pasting tracking numbers.

= Supported platforms =

* **Sendcloud**: push to parcel queue, HMAC webhook, tracking writeback
* **Shippo**: push to orders queue, HMAC webhook, tracking writeback
* **ShipStation**: push to orders queue, HMAC webhook, tracking writeback
* **Packlink PRO**: push to shipment queue, secret-token webhook, tracking writeback

= How it works =

1. A customer completes a paid order in your SureCart store.
2. You push the order manually from the Orders tab to your chosen shipping platform.
3. You process the shipment inside that platform's dashboard. Lindyship does not generate labels or compare rates.
4. The platform sends a tracking webhook back to your site.
5. The plugin writes the tracking number to SureCart and marks the order as fulfilled.

= Key features =

* **Single platform selection**: choose one shipping platform to connect with.
* **Manual push**: push orders individually from the Orders tab when you're ready to ship.
* **Automatic retry**: failed pushes are retried up to 3 times over 24 hours before being marked permanently failed.
* **Sync log**: every push attempt, webhook delivery, and tracking writeback is recorded with full HTTP request/response capture available for debugging.
* **Diagnostics tab**: one-click health checks for PHP, OpenSSL, SureCart connection, DB table, cron schedule, sender address, and webhook reachability.
* **Test push**: send a synthetic order end-to-end to verify your credentials and webhook without a real customer.
* **Credentials encrypted at rest**: all API keys and secrets are AES-256 encrypted in the database.

= What this plugin does NOT do =

It does not generate shipping labels, compare carrier rates, or provide a checkout rate widget. All of that lives inside your shipping platform's dashboard. This plugin is purely the data bridge.

== Installation ==

1. Install and activate the [SureCart](https://wordpress.org/plugins/surecart/) plugin first.
2. Upload **Lindyship** via **Plugins -> Add New -> Upload Plugin**, or search for it in the plugin directory.
3. Activate the plugin.
4. Go to **Settings -> Lindyship**.
5. On the **Connection** tab, select your shipping platform from the dropdown and enter your API credentials.
6. Fill in your **Sender Address** on the Advanced tab; this is the "from" address sent to the shipping platform.
7. Optionally visit the **Diagnostics** tab and run the health checks to confirm everything is wired up.

== Frequently Asked Questions ==

= Does this plugin work without SureCart? =

No. It is purpose-built for SureCart and has no standalone functionality.

= Which shipping platforms are supported? =

Sendcloud, Shippo, ShipStation, and Packlink PRO. Select one platform to connect with.

= Does it generate shipping labels? =

No. Labels, rates, and carrier selection all happen inside your shipping platform's own dashboard. This plugin only sends the order data there and brings the tracking number back.

= Can I push orders manually? =

Yes. Go to the Orders tab to push individual orders manually. You can also push any order by ID from the same tab.

= What happens if a push fails? =

The plugin logs the failure and automatically retries up to 3 times over the next 24 hours. After 3 failed attempts the entry is marked permanently failed and an admin notice appears so you can investigate.

= Is there an auto-sync feature? =

No. This free version requires manual push from the Orders tab. This ensures you have full control over which orders are sent to your shipping platform.

= Where do I find my API credentials? =

* **Sendcloud**: Settings -> Integrations -> API in your Sendcloud account.
* **Shippo**: API -> API Keys in your Shippo dashboard.
* **ShipStation**: Account Settings -> Account -> API Settings.
* **Packlink PRO**: Settings -> Integrations -> API Key.

= What does the webhook URL look like? =

`https://yoursite.com/wp-json/lindyship/v1/webhook/{platform}`, for example `/webhook/sendcloud`. The Connection tab has a **Register webhook** button that configures this automatically on platforms that support it via API.

= Does it handle subscription renewal orders? =

There is no automatic syncing in the free version; nothing is sent until you choose to. You can push any order, including subscription renewals, manually from the Orders tab.

= Is it compatible with multisite? =

The plugin has not been tested on multisite installs.

== External services ==

This plugin connects to external shipping platform APIs in order to push order data and receive tracking updates. All communication happens server-to-server; no customer data is sent to the plugin author's servers.

**Sendcloud** - https://sendcloud.com/
* Used for: pushing orders to the Sendcloud parcel queue and receiving tracking webhooks.
* Data sent: order number, customer shipping address, line items, weight, dimensions.
* When: each time you manually push an order to Sendcloud from the Orders tab.
* Terms of service: https://www.sendcloud.com/terms-conditions/
* Privacy policy: https://www.sendcloud.com/privacy-policy/

**Shippo** - https://goshippo.com/
* Used for: pushing orders to the Shippo orders queue and receiving tracking webhooks.
* Data sent: order number, customer shipping address, line items, weight, dimensions.
* When: each time you manually push an order to Shippo from the Orders tab.
* Terms of service: https://privacy.goshippo.com/policies?name=terms-of-use
* Privacy policy: https://privacy.goshippo.com/policies?name=privacy-notice

**ShipStation** - https://www.shipstation.com/
* Used for: pushing orders to the ShipStation orders queue and receiving tracking webhooks.
* Data sent: order number, customer shipping address, line items, weight, dimensions.
* When: each time you manually push an order to ShipStation from the Orders tab.
* Terms of service: https://www.shipstation.com/terms-of-service/
* Privacy policy: https://www.shipstation.com/privacy-policy/

**Packlink PRO** - https://pro.packlink.com/
* Used for: pushing orders to the Packlink PRO shipment queue and receiving tracking webhooks.
* Data sent: order number, customer shipping address, line items, weight, dimensions.
* When: each time you manually push an order to Packlink PRO from the Orders tab.
* Terms of service: https://support-pro.packlink.com/hc/en-gb/articles/360010011480-Terms-and-Conditions-of-pro-packlink-com-site
* Privacy policy: https://support-pro.packlink.com/hc/en-gb/articles/360010011560-Privacy-Policy

**SureCart** - https://surecart.com/
* Used for: reading order details and writing back tracking numbers/fulfillment status.
* Data sent: order ID (for retrieval), tracking number and carrier (for writeback).
* When: each time you manually push an order (read), and when a tracking webhook is received (writeback).
* Terms of service: https://surecart.com/terms-and-conditions/
* Privacy policy: https://surecart.com/privacy-policy/

== Changelog ==

= 1.2.0 =
* New: Select one shipping platform (Sendcloud, Shippo, ShipStation, or Packlink PRO) and push paid orders to it manually from the Orders tab.
* New: Push an order by its SureCart order ID from the Orders tab.
* New: Packlink PRO integration - push orders, register webhook, receive tracking events.
* New: ShipStation integration - push orders, register webhook, receive tracking events.
* Fix: Packlink error responses now show the actual field-level message instead of "Array".
* Fix: Packlink orders no longer fail with a 400 error when no sender address is saved; a clear validation message is shown instead.
* Fix: Orders tab "Push by order ID" form was hidden when the order list was empty. Now always visible.
* Improvement: Admin menu icon changed to a superhero icon (dashicons-superhero).
* Improvement: "Carrier / Aggregator" column renamed to "Platform" throughout the UI.
* Improvement: Default weight and dimension labels clarified - "Fallback item weight" and "Parcel box dimensions" with explanatory notes.
* Improvement: Plugin renamed to "Lindyship".

= 1.1.0 =
* Fix: Encryption key derivation no longer depends on `wp_salt('auth')`. Salt rotation was silently invalidating all stored credentials; a legacy-key fallback preserves existing installs on upgrade.
* Fix: Order declared value fallback chain now consistently treats amounts as integer minor units (cents) at every step.
* Fix: Sender country normalisation - free-text country names (e.g. "Ireland", "Mexico") now map to the correct ISO code instead of silently using the wrong one.
* Fix: Webhook signature verification handles all provider-specific header formats and prefix variants (sha256=, hmac-sha256=, v1=, Stripe-style timestamped scheme).
* Fix: Retry runner no longer creates an exponential queue of failure rows; failed retries now update the original log row in place.
* Fix: Shippo line-item weight no longer double-counted (Shippo multiplies by quantity server-side).
* Performance: OrderReader caches the raw SureCart payload per request to avoid redundant API calls in the observer chain.
* UX: Settings tabs warn before navigating away with unsaved changes.

= 1.0.0 =
* New: Diagnostics tab with health checks (PHP, OpenSSL, SureCart, DB, cron, sender address, webhook reachability).
* New: Test push button - sends a synthetic order end-to-end without a real customer.
* New: File-based debug log with auto-rotation and downloadable from the admin.
* New: Full HTTP request/response capture in the sync log (optional, for debugging).
* New: Automatic retry runner - failed pushes retried up to 3 times over 24 hours.
* New: Shippo integration - connect, push orders, register webhook, receive tracking events.

== Upgrade Notice ==

= 1.2.0 =
After upgrading, visit Settings -> Lindyship -> Connection to select your shipping platform and confirm your credentials.
