=== Velo Connector ===
Contributors: veloitay
Tags: shipping, sync, tracking
Requires at least: 5.2
Requires PHP: 7.2
Tested up to: 6.9
Stable tag: 1.0.9
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Requires Plugins: woocommerce

Synchronize your deliveries and utilize MazeAI with the Velo dynamic shipping method.

== Description ==

The official Velo WooCommerce plugin for synchronizing your deliveries and utilizing the Velo dynamic shipping method.
To use the plugin you will need to provide your Velo credentials, which can be obtained in your Velo store's app center.
After finishing setup, you will be able to synchronize your deliveries with Velo and utilize the Velo dynamic shipping method.

To synchronize your deliveries with Velo:
    1. Go to the WooCommerce > Orders page
    2. send orders to Velo by clicking the "Send to Velo" button, or checking them and using the "Send to Velo" bulk action.
    3. You can track deliveries and get shipping labels by clicking the "Track Order" and "Print Label" buttons
    4. To print labels for several orders at once, select them and use the bulk action "Velo: Print shipping labels" (orders must already have a Velo order name).
    5. Your deliveries statuses will update automatically

To utilize the Velo dynamic shipping method:
    *** WARNING ****
    THE VELO SHIPPING METHOD MIGHT CAUSE ISSUES WITH OTHER SHIPPING METHODS.

    1. Go to the WooCommerce > Settings > Shipping > Shipping Zones
    2. Edit the zone you want to use Velo dynamic shipping method
    3. Click the "Add shipping method" button
    4. Select "Velo" from the list and click "continue"


== Installation ==

1. Upload the `velo-connector` folder to the `/wp-content/plugins/` directory, or install the plugin through the WordPress plugins screen directly
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Ensure WooCommerce is installed and activated (required)
4. Go to WooCommerce > Settings > Shipping > Shipping Zones
5. Edit a shipping zone and add the "Velo" shipping method
6. Configure your Velo credentials (API Key, API Secret, Email, and Password) in the shipping method settings
7. Your credentials can be obtained from your Velo store's app center

== External services ==

This plugin connects to external services provided by Velo to obtain shipping service information and send order information. These connections are required for the plugin to function properly.

**Main API Endpoint:**
- **Service URL**: https://api.veloapp.io
- **Purpose**: This is the primary API endpoint used to:
  - Authenticate with Velo services (login and token refresh)
  - Get shipping options during checkout
  - Send order information to Velo for processing
  - Track delivery status
  - Generate shipping labels
  - Import/export orders in bulk

**WordPress REST API Routes:**
The plugin creates dynamic REST API routes on your WordPress site:
- **Route Pattern**: `/wp-json/velo-connector/{api_key}/v1/*`
- **Route Pattern**: `/wp-json/velo-owleye/{api_key}/v1/*`
- **Purpose**: These routes allow Velo services to:
  - Poll order status updates from your WordPress site
  - Receive webhook notifications about order changes
  - Retrieve order information including IP addresses and payment details

**What data is sent and when:**

**To https://api.veloapp.io:**
- **During checkout** (when customer selects shipping method): Customer shipping address, store address, order weight and dimensions
- **When sending orders**: Complete order information including:
  - Order items (product names, SKUs, quantities, prices, weights)
  - Order shipping address
  - Order billing address
  - Customer contact information (name, email, phone)
  - Store address information
  - Order notes
- **When tracking orders**: Order name/identifier to retrieve delivery status
- **When generating labels**: Order name/identifier to retrieve shipping label
- **When printing bulk shipping labels (admin bulk action)**: Velo order names for the selected WooCommerce orders are sent in one request; Velo returns combined label markup for printing in the browser
- **Authentication**: API credentials (email, password, API key, API secret) are sent during login and token refresh

**From your WordPress site (REST API routes):**
- **When polled by Velo services**: Order IDs, order status, order metadata
- **When receiving webhooks**: Order information including IP addresses, payment details, and risk assessment data

**Data transmission conditions:**
- Data is sent only when you actively use plugin features (sending orders, tracking, generating labels, bulk print labels in admin)
- Shipping options are retrieved during checkout when the Velo shipping method is available
- REST API routes are only accessible with valid authentication (nonce verification)
- All data transmission uses secure HTTPS connections

This service is provided by [Velo](https://veloapp.io/).
    - [Velo's Terms of use](https://veloapp.io/terms-of-service/)
    - [Velo's Privacy Policy](https://veloapp.io/privacy/)

== Changelog ==

= 1.0.9 =
* Bulk "Velo: Print shipping labels": store combined markup on disk; serve a one-shot print URL; load with fetch and print in a new window (blob iframe fallback) so large HTML and browser print rules work reliably.
* Velo `/labels` response: accept markup in `stickers`, `labels`, `html`, or `markup` fields.
* After any Velo column toast, refresh the column from the poll_orders endpoint so meta and buttons stay current.

= 1.0.8 =
* Add WooCommerce orders bulk action "Velo: Print shipping labels" — POSTs Velo order names to the Velo `/labels` endpoint and opens the returned markup in a print dialog.

= 1.0.7 =
* Fix orders list column UI after a failed Confirm order: do not show Send to Velo alongside Velo status until reload (AJAX updates buttons only on success; polling now keeps Send hidden when a Velo order name exists).
* Include structured debug details on failed Confirm order AJAX responses (same shape as Send to Velo failures).

= 1.0.6 =
* Better product name resolution for exported line items.

= 1.0.5 =
* Harden order product payload building (guard invalid item lists).
* Include structured debug details on failed Send to Velo AJAX responses.

= 1.0.4 =
* Unify runtime and admin credentials reads to WooCommerce shipping settings option.
* Make Plugins > Velo Settings read and write the same credentials option as WooCommerce.

= 1.0.3 =
* Fix credentials settings key consistency across API and REST routes.
* Update missing-credentials messaging to include API secret.

= 1.0.2 =
* Improve error reporting
* Improve credentials consistency

v.1.0.0 - Initial release