=== Preset Bridge for WooCommerce ===
Contributors: dwayne
Tags: woocommerce, quad cortex, neural dsp, digital products, webhooks
Requires at least: 6.7
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Send paid orders to Preset Bridge and apply signed delivery results to WooCommerce.

== Description ==

Preset Bridge for WooCommerce connects a WooCommerce store to an existing Preset Bridge store integration.

The plugin adds a Cortex Cloud username field to classic checkout and Checkout Blocks. When an eligible order reaches a configured paid status, it sends a signed webhook to Preset Bridge in the background. Preset Bridge then matches the purchased SKU or product ID to the preset or capture configured in the merchant's account.

Preset Bridge sends signed delivery events back to the plugin. A successful delivery can mark a paid order Completed. Waiting, action-required and failed results are stored on the order for the store manager. Repeated and out-of-order callbacks do not apply the same result twice or overwrite a newer result.

The plugin sends one stable event per order. A later status change does not create a second delivery. Temporary network and server failures are retried after 1 minute, 5 minutes, 15 minutes, 1 hour, 6 hours and 24 hours.

= Preset Bridge service =

This plugin connects a WooCommerce store to the Preset Bridge service at https://presetbridge.com/. Preset Bridge performs the Cortex Cloud sign-in, friendship check, preset or capture share, retry handling and delivery logging. A Preset Bridge account is required, and paid service credits may be required for successful preset and capture shares. The plugin itself does not restrict or sell features.

No order data is sent when the plugin is first installed. A store manager must create a Preset Bridge integration, enter its webhook URL and signing secret, select the order statuses used for delivery, and enable the integration.

When an eligible order reaches a selected status, the plugin sends Preset Bridge the order ID, order key, order status, billing email address, Cortex Cloud username and the SKU, product ID, variation ID, name and quantity for each line item. Preset Bridge sends the order ID, stable event ID and delivery result back to the store. This information is used to match the purchase, deliver the selected preset or capture, prevent duplicate work, update the order and show the result in each system's delivery log.

* Service: https://presetbridge.com/
* Terms of Use: https://presetbridge.com/terms
* Privacy Policy: https://presetbridge.com/privacy

= Compatibility =

* WooCommerce 9.9 or newer
* WordPress 6.7 or newer
* PHP 7.4 or newer
* Classic checkout and Checkout Blocks
* High-Performance Order Storage (HPOS)
* Action Scheduler, supplied by WooCommerce, with WP-Cron as a fallback

== Installation ==

1. In Preset Bridge, open App > Integrations and create a WooCommerce integration.
2. Select the API token used for delivery billing. Add the WooCommerce SKU, product ID or variation ID mappings for the presets and captures sold by the store.
3. Copy the integration webhook URL and signing secret. Preset Bridge shows the full secret once.
4. In WordPress, open Plugins > Add New Plugin > Upload Plugin. Upload the Preset Bridge plugin ZIP and activate it.
5. Open WooCommerce > Settings > Integrations > Preset Bridge.
6. Paste the integration webhook URL and signing secret.
7. Copy the Resolution webhook URL shown in the plugin settings. In Preset Bridge, create an outbound webhook subscription for `delivery.completed`, `delivery.action_required`, `delivery.retry_scheduled`, `delivery.failed`, `delivery.ignored`, `delivery.invalidated` and `delivery.reopened`. Limit it to this WooCommerce integration and use the copied URL as its target.
8. Copy the outbound subscription secret into Resolution webhook secret. Leave Mark paid orders Completed enabled unless another order workflow owns that status change.
9. Select the order statuses that should start delivery. The defaults are Processing and Completed. Select the same accepted statuses in Preset Bridge.
10. If the store also sells unrelated products, enter the eligible product SKUs. Leave the list blank only when every order should be sent.
11. Enable the integration and save changes.

Do not create a second webhook under WooCommerce > Settings > Advanced > Webhooks. This plugin sends and signs the order event itself.

== Frequently Asked Questions ==

= Which order status should I use? =

Processing and Completed are safe defaults for paid orders. The plugin sends the first selected status reached by an order. It ignores later selected statuses for the same order.

The accepted statuses in Preset Bridge must match this setting. A mismatch leaves the delivery ignored in Preset Bridge.

= How do I limit the username field to preset products? =

Enter those product SKUs under Eligible product SKUs. The classic checkout inspects the cart. Checkout Blocks uses WooCommerce's conditional additional-field schema, available from WooCommerce 9.9.

Variation SKUs are supported. If a variation does not have its own SKU, the plugin also checks the parent product SKU.

= What happens if Preset Bridge is temporarily unavailable? =

The order is retried in the background for network errors, timeouts, rate limits and server errors. Open WooCommerce > Status > Scheduled Actions and search for the preset-bridge group to inspect queued work.

= How does WooCommerce learn that delivery finished? =

Create an outbound webhook subscription in Preset Bridge and paste its secret into the plugin settings. Preset Bridge signs the exact callback body with HMAC-SHA256. The plugin checks the signature and stable order event ID before changing any order.

Successful delivery completes a paid order when Mark paid orders Completed is enabled. The plugin never completes an unpaid, cancelled, refunded or failed order.

= How do I fix a failed order? =

Open the order in WooCommerce. Correct the Cortex Cloud username if needed, choose Retry Preset Bridge delivery from Order actions, then update the order.

Authentication failures and invalid webhook URLs are not retried automatically. Fix the settings first, then use the order action.

= Where are the logs? =

Enable Debug logging in the plugin settings. Open WooCommerce > Status > Logs and select the preset-bridge source. Secrets and full webhook bodies are not logged.

= What data leaves the store? =

The webhook contains the order ID, order key, order status, billing email address, Cortex Cloud username and the SKU, product ID, variation ID, name and quantity for each line item. It does not include billing addresses, payment details, prices or order totals.

Suggested privacy-policy wording is added to Settings > Privacy > Policy guide.

Preset Bridge sends the order ID, stable event ID, delivery status and delivery message back to the store. It does not send the customer's Cortex Cloud credentials.

= Where is the signing secret stored? =

WooCommerce stores the secret in the WordPress options table with the other integration settings. Treat database and backup access as sensitive. The secret is never shown in logs or order notes.

== Changelog ==

= 1.2.0 =

* Added signed callbacks when a merchant marks a delivery invalid or reopens it.
* Kept invalidated and reopened orders out of automatic WooCommerce completion.
* Stored invalidation and reopen results in the order delivery metadata and notes.

= 1.1.0 =

* Added a signed REST endpoint for Preset Bridge delivery events.
* Added duplicate and out-of-order callback protection.
* Added optional automatic completion for paid orders after successful delivery.
* Added delivery-result metadata, order notes and WordPress action and filter hooks.
* Stopped retrying outbound callbacks after permanent HTTP 4xx responses.

= 1.0.0 =

* Added classic checkout and Checkout Blocks username collection.
* Added signed, minimal WooCommerce order webhooks.
* Added stable event IDs, duplicate prevention and background retries.
* Added HPOS compatibility, order status details and manual retry controls.
* Added unit, coding-standard, Plugin Check and WordPress runtime test tooling.
