=== Card Attack Shield for WooCommerce ===
Contributors: sagesbrain
Tags: woocommerce, card testing, fraud, rate limit, checkout
Requires at least: 6.4
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Stops card-testing bots on every WooCommerce checkout path: classic, block checkout, Store API and PayPal card fields.

== Description ==

Card-testing bots use your checkout to find out which stolen cards still work. You get hundreds of failed orders, a flood of emails, gateway fees for every attempt, and a merchant account at risk.

Most security plugins can't see these attacks, because the bots post straight to WooCommerce's checkout endpoints. WooCommerce's built-in rate limit is off by default, and it only covers the block checkout.

Card Attack Shield puts a limit in front of **every** checkout path:

* **Per-IP limit on checkout attempts.** 5 attempts per 10 minutes by default, counted across the classic checkout (`?wc-ajax=checkout`), the block checkout and Store API, and PayPal Payments' card-field endpoint. Blocked attempts never reach your payment gateway, so they cost you nothing.
* **Checkout token for the classic checkout.** The checkout form carries a signed hidden field and must be at least 3 seconds old. Scripts that post directly to the checkout endpoint are refused. Apple Pay and Google Pay buttons are not affected.
* **Automatic lockdown.** 10 failed orders within 15 minutes locks guest checkout for 30 minutes and emails the site admin. Logged-in customers can still buy.
* **WooCommerce's own Store API rate limiter,** switched on with safe settings.
* **Optional minimum order total,** to stop the $1 test charges bots favor.
* **Logs every block** to WooCommerce > Status > Logs, under "card-attack-shield".

No settings page and nothing to configure: activate it and you're protected. Every default can be changed with one line in wp-config.php (see FAQ).

Under attack right now? The free [Card Attack Emergency Kit](https://www.sagesbrain.com/#kit) walks you through the first 15 minutes, including Cloudflare firewall rules and a script to clean up failed orders.

== Installation ==

1. Install and activate WooCommerce.
2. In WordPress, go to Plugins > Add New, search for "Card Attack Shield", then install and activate it.
3. Place a test order as a guest, from a phone on cellular data, to confirm real customers can still check out.

That's it. Blocks appear in WooCommerce > Status > Logs under "card-attack-shield".

== Frequently Asked Questions ==

= How do I change the limits? =

Add a line to wp-config.php, above "That's all, stop editing". For example:

`define( 'CAS_IP_LIMIT', 3 );`

Available settings and their defaults:

* `CAS_IP_LIMIT` (5) and `CAS_IP_WINDOW` (600 seconds): checkout attempts allowed per IP per window
* `CAS_FAILED_THRESHOLD` (10) and `CAS_FAILED_WINDOW` (900 seconds): failed orders that trigger a lockdown
* `CAS_LOCKDOWN_SECONDS` (1800): lockdown length; 0 turns lockdown off
* `CAS_MIN_ORDER_TOTAL` (0, off): smallest cart total allowed, e.g. 5
* `CAS_REQUIRE_TOKEN` (true): set false if your theme's custom checkout rejects real orders
* `CAS_TRUST_CLOUDFLARE` (false): read the visitor IP from Cloudflare's header (see below)
* `CAS_EXTRA_WC_AJAX` ("ppc-create-order"): extra gateway endpoints to limit, comma-separated

= Real customers see "Please reload the checkout page and try again." =

Some page builders and checkout plugins don't output WooCommerce's standard checkout hooks, so the hidden token never reaches the form. Add `define( 'CAS_REQUIRE_TOKEN', false );` to wp-config.php. The rate limit and lockdown keep working.

= My site uses Cloudflare. Do I need CAS_TRUST_CLOUDFLARE? =

Usually not. Check WooCommerce > Status > Logs after a blocked attempt. If the logged IPs are real visitor addresses, your host already restores them, so leave the setting off.

Only turn it on if the logs show Cloudflare's own IPs **and** your server accepts traffic from Cloudflare alone. If your server can be reached directly, a bot could fake the Cloudflare header and get past the per-IP limit.

= Does it work with the block checkout? =

Yes. The per-IP limit and lockdown apply to the block checkout and every Store API checkout request. The token check applies only to the classic checkout form.

= A customer whose card was declined got "Too many checkout attempts". =

With PayPal Payments, one purchase counts as two attempts. A shopper with two declined cards in a row can reach the default limit of 5. Raise it with `define( 'CAS_IP_LIMIT', 8 );`.

= Will it slow down my store? =

No. It only runs on checkout requests and stores a small counter per IP in a WordPress transient.

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

Yes. Failed orders are counted through WooCommerce's order API, which works with both order storage types.

== Changelog ==

= 1.0.0 =
* First release: per-IP checkout limit across classic, block, Store API and PayPal card-field checkouts; classic checkout token; failed-order lockdown with an admin email; Store API rate limiter; optional minimum order total; logging.

== Upgrade Notice ==

= 1.0.0 =
First release.
