=== COD Anti-Fraud for WooCommerce ===
Contributors: beralabs
Donate link: https://beralabs.it
Tags: woocommerce, cash on delivery, anti fraud, otp, whatsapp
Requires at least: 6.0
Tested up to: 7.1
WC requires at least: 5.0
WC tested up to: 11.1
Requires PHP: 7.4
Stable tag: 2.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Protect WooCommerce Cash on Delivery (COD) orders against fraud by requiring WhatsApp OTP verification and calculating dynamic risk scores.

== Description ==

**COD Anti-Fraud for WooCommerce** protects WooCommerce online stores from non-delivered or fraudulent Cash on Delivery (COD) orders by combining dynamic risk evaluation with mandatory WhatsApp OTP verification.

### Key Features
* **Dynamic Risk Engine:** Calculates a 0-100 risk score based on guest checkout status, cart total, and past failed/cancelled COD history.
* **WhatsApp OTP Verification Gateway:** Automatically sends a 6-digit verification code to the customer's phone via WhatsApp before confirming COD orders.
* **Anti-Bypass Protection (Server-Side & Client-Side):** Strict pre-checkout verification enforcement ensuring no unverified COD orders can be submitted.
* **Optimized Checkout UI/UX:** Dedicated `#wc-cod-otp-wrapper` container with smooth real-time states, responsive design, and compatibility with Classic and Blocks checkout.
* **Smart Thresholds & Gateways:** Configure minimum/maximum cart amounts for COD, blacklist fraudulent phone numbers or emails, and whitelist trusted VIP customers.
* **Rate Limiting & Anti-Brute-Force:** Built-in rate limiter by phone number and IP address to prevent SMS/WhatsApp flooding.
* **Multiple Gateway Support:** Native integration with UltraMsg, BeraLab Baileys Gateway, and extensible for Twilio / custom WhatsApp providers.
* **Order Meta & Admin Details:** Transparent risk scores and verification timestamps displayed directly inside WooCommerce order details.
* **PHP 8.x & HPOS Certified:** Fully compatible and tested with PHP 8.0-8.3 and WooCommerce High-Performance Order Storage (HPOS).

== External services ==

This plugin connects to external WhatsApp API services (such as **UltraMsg WhatsApp API** or the **BeraLab WhatsApp Gateway**) to send One-Time Password (OTP) verification messages via WhatsApp to customers choosing the Cash on Delivery (COD) payment method.

* **UltraMsg Provider:** UltraMsg Inc. ([https://ultramsg.com/](https://ultramsg.com/))
  * Terms of Service: [https://ultramsg.com/terms-conditions.php](https://ultramsg.com/terms-conditions.php)
  * Privacy Policy: [https://ultramsg.com/privacy-policy.php](https://ultramsg.com/privacy-policy.php)
* **BeraLab Gateway Provider:** BeraLab Cloud Gateway ([https://beralabs.it/whatsapp-gateway.html](https://beralabs.it/whatsapp-gateway.html))
  * Terms & Privacy: [https://beralabs.it/privacy-policy.html](https://beralabs.it/privacy-policy.html)

**What data is sent to the WhatsApp service?**
* The customer's mobile telephone number entered during checkout.
* The dynamically generated 6-digit OTP verification code text.

No customer passwords, credit card numbers, billing addresses, or purchase history details are shared with external messaging gateways. API requests are triggered exclusively when a customer requests an OTP code to verify a Cash on Delivery order.

== Installation ==

1. Upload the `woo-cod-antifraud` directory to your `/wp-content/plugins/` directory.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. Go to **WooCommerce > Settings > COD Anti-Fraud** to configure settings and your WhatsApp API credentials.

== Frequently Asked Questions ==

= Is this plugin compatible with High-Performance Order Storage (HPOS)? =
Yes, COD Anti-Fraud for WooCommerce is fully compatible and certified with HPOS (Custom Order Tables).

= Is PHP 8.x supported? =
Yes, fully compatible and tested with PHP 7.4 through PHP 8.3.

= What WhatsApp gateways are supported? =
The plugin natively supports UltraMsg, BeraLab Baileys Cloud Gateway, and can be extended for Twilio and custom API endpoints.

= What happens if the customer does not verify the OTP? =
If OTP verification is required based on settings or risk score, checkout submission is strictly blocked on both client-side and server-side until valid verification is completed.

= Does this plugin work with guest checkout? =
Yes, guest checkout is fully supported and analyzed with higher risk evaluation weights.

== Screenshots ==

1. Plugin settings page in WooCommerce Admin (`/assets/screenshot-1.png`).
2. WhatsApp OTP verification box in WooCommerce checkout (`/assets/screenshot-2.png`).
3. Anti-Fraud Risk Engine meta box in WooCommerce order details (`/assets/screenshot-3.png`).

== Changelog ==

= 2.0.1 =
* WhatsApp OTP Checkout Flow: Integrazione completa del flow di verifica OTP WhatsApp (UltraMsg e BeraLab Baileys Gateway) prima della conferma d'ordine COD.
* Validazione Rigorosa Anti-Bypass: Protezione hardened client-side e server-side per impedire sottomissioni fraudolente, manomissioni o bypass del lock di verifica.
* Ottimizzazioni UX: Restyling del container interattivo `#wc-cod-otp-wrapper` con feedback visuale reattivo, gestione degli errori e compatibilità checkout.
* Compatibilità HPOS & PHP 8.x: Certificazione completa per High-Performance Order Storage (Custom Order Tables) e runtime PHP 7.4-8.3.
* Test E2E Convalidati: Esecuzione con successo dei test end-to-end e piena aderenza agli standard di codifica e sicurezza WordPress.org (sanitizzazione, nonces, escaping).

= 1.1.0-beta =
* WordPress.org standards compliance: sanitized superglobals, nonces validation, and output escaping.
* Enforced pre-checkout mandatory OTP verification before placing Cash on Delivery orders.
* Unified settings option keys across all modules.

= 1.1.0 =
* Added HPOS compatibility.
* Added customizable message templates for WhatsApp OTP.
* Enhanced risk engine algorithms and order history lookup.
* Added rate limiting and IP abuse protection.
* Added whitelist and blacklist management.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 2.0.1 =
Recommended upgrade for all users: adds WhatsApp OTP checkout flow, strict anti-bypass validation, UX optimizations, certified HPOS compatibility, and passed E2E test validations.
