=== Xcash for WooCommerce ===
Contributors: xcash
Donate link: https://xca.sh
Tags: woocommerce, payments, crypto, blockchain, USDT
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.7
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Accept crypto payments via the Xcash payment gateway directly in WooCommerce with full checkout blocks support.

== Description ==

= Overview =
Xcash for WooCommerce enables merchants to accept crypto payments through the Xcash payment gateway. Customers complete payments on Xcash’s hosted checkout while WooCommerce stays in sync via secure webhooks. The gateway works with both classic shortcodes and WooCommerce Checkout Blocks, supports fiat-denominated invoices, and offers bilingual (English/Chinese) strings out of the box.

= Features =
* Seamless Xcash gateway integration for WooCommerce orders with automatic redirect to the hosted pay_url.
* Fiat-denominated invoices (USD, CNY, EUR, JPY, HKD) with Xcash-managed crypto conversion.
* Optional JSON-based `methods` filter to limit coin-chain combinations presented to shoppers.
* Built-in “Test Configuration” button to validate credentials without placing a live order.
* Hardened webhook handler with nonce and per-invoice idempotency plus HMAC-SHA256 signature verification.
* Compatible with WooCommerce Checkout Blocks, High-Performance Order Storage (HPOS), and PHP 7.4–8+.
* Includes English and Simplified Chinese translations for admin and frontend strings.

= Requirements =
* WordPress 5.8 or higher.
* WooCommerce 5.0 or higher (tested up to WooCommerce 8.0).
* PHP 7.4 or higher.
* Active Xcash merchant account with App ID and HMAC key.

= How It Works =
1. Shopper chooses “Xcash” during checkout.
2. The plugin creates an invoice through the Xcash API using a bounded unique WooCommerce order reference as `out_no` and the order's WooCommerce currency as the pricing currency.
3. Customer is redirected to the Xcash-hosted payment page (`pay_url`) to finalize the crypto transfer.
4. Xcash notifies the store via webhook once the payment is detected and confirmed.
5. The order is automatically marked as paid and annotated with invoice/transaction details.

= External Service =
This plugin connects to Xcash, a cryptocurrency payment gateway, to create hosted crypto checkout invoices and receive payment status notifications. Xcash service information is available at https://xca.sh, developer documentation is available at https://docs.xca.sh, the Xcash Terms of Service are available at https://xca.sh/terms/, and the Xcash Privacy Policy is available at https://xca.sh/privacy/.

The merchant must create an Xcash account at https://dash.xca.sh and enter the project App ID and HMAC key in the WooCommerce gateway settings. The gateway URL defaults to https://pay.xca.sh and can be changed if the merchant runs their own compatible Xcash gateway.

When a shopper places an order with this payment method, or when an administrator uses the “Test Configuration” button, the plugin sends a signed HTTP(S) request to the configured Xcash gateway invoice API (`https://pay.xca.sh/v1/invoice` by default). The request includes authentication headers (`XC-Appid`, `XC-Nonce`, `XC-Timestamp`, and `XC-Signature`) and an invoice JSON body containing the WooCommerce order reference (`out_no`), order title, order total amount, pricing currency, invoice duration, the store return URL, the store webhook notification URL, and optional merchant-configured payment method restrictions.

After the invoice is created, the shopper is redirected to the hosted Xcash payment URL returned by the service. When Xcash detects and confirms payment, Xcash sends a signed webhook request back to the store. The plugin validates the signature and stores invoice/payment identifiers and transaction details from the webhook, such as Xcash invoice ID (`sys_no`), merchant order reference (`out_no`), confirmation flag, cryptocurrency, payment amount, pay address, transaction hash, chain, and block number, as WooCommerce order metadata and displays the core fields on the admin order screen.

= Gateway Configuration =
* Navigate to WooCommerce → Settings → Payments → Xcash and enable the gateway.
* Set the title/description displayed to customers.
* Enter your Xcash **App ID** and **HMAC Key** from the Xcash console.
* Keep the default gateway URL (`https://pay.xca.sh`) or change it to your own compatible gateway.
* The invoice pricing currency is taken automatically from your WooCommerce store currency, so make sure it is a fiat currency supported by Xcash.
* Optionally specify allowed payment methods as JSON — e.g. `{"USDT":["ethereum","tron"]}`.
* Adjust the payment duration (5–30 minutes, default: 20 minutes) if needed.
* Use the “Test Configuration” button to confirm the credentials before going live.

= Webhook & Security =
* Webhook endpoint: `https://your-site.com/?wc-api=xcash_webhook`.
* The plugin sends this endpoint automatically as the invoice-level `notify_url` when creating invoices.
* Every webhook is validated by checking the `XC-Appid`, `XC-Nonce`, `XC-Timestamp`, and `XC-Signature` headers.
* Nonces are stored as transients and each paid invoice is marked as processed to block replay attempts; the request timestamp is covered by the HMAC signature rather than checked against a fixed time window.
* Detailed debug logs are written through WooCommerce’s logging system (`wc_get_logger`).

= Localization =
* Text Domain: `xcash-for-woocommerce`.
* Domain Path: `/languages`.
* Bundled translations: English (default) and Simplified Chinese.

= Compatibility =
* WooCommerce Checkout Blocks integration via `Xcash_WC_Gateway_Blocks_Support`.
* Declares compatibility with WooCommerce High-Performance Order Storage (custom order tables).
* Supports both shortcode-based and block-based checkout flows.

== Installation ==

1. Download the plugin ZIP or clone the repository.
2. Upload the `xcash-for-woocommerce` folder to `/wp-content/plugins/`.
3. Activate *Xcash for WooCommerce* via **Plugins → Installed Plugins**.
4. Go to **WooCommerce → Settings → Payments**, enable “Xcash”, fill in your credentials, and save.

== Frequently Asked Questions ==

= Where do I find my App ID and HMAC key? =
Log in to your Xcash merchant dashboard (https://dash.xca.sh), open your project, and copy the App ID and HMAC key from the project settings.

= Why does the “Test Configuration” button fail? =
Ensure App ID and HMAC key are filled, and that your WooCommerce store currency is a fiat currency supported by Xcash. If you restrict `methods`, confirm the JSON is valid and that the configured payment methods exist in your Xcash project. Check WooCommerce → Status → Logs for `xcash-for-woocommerce` entries.

= How do I verify webhook delivery? =
The plugin sends the store webhook endpoint as invoice-level `notify_url` for each new invoice. Keep Xcash project notifications enabled. Payments will trigger a POST request with the same signature scheme as the API. Successful processing returns `ok`. You can resend failed notifications from the Xcash console.

= Does the plugin support WooCommerce HPOS? =
Yes, the gateway declares compatibility with HPOS/custom order tables and works on both legacy and HPOS-enabled stores.

= Is there Chinese language support? =
All strings ship with Simplified Chinese translations (`xcash-for-woocommerce-zh_CN.po` source and `xcash-for-woocommerce-zh_CN.mo` runtime file). WordPress will load the locale automatically when the site language is set to Simplified Chinese; English remains the default for other locales.

== Changelog ==

= 1.0.7 =
* Added core Xcash payment details to the WooCommerce admin order screen.

= 1.0.6 =
* Removed the read-only webhook URL display from the WooCommerce gateway settings because invoices now send the store callback endpoint as `notify_url` automatically.
* Changed the default invoice payment duration to 20 minutes.

= 1.0.5 =
* Added a configurable Xcash gateway URL setting, defaulting to `https://pay.xca.sh`.
* Refreshed bundled Simplified Chinese translations and included the runtime `.mo` language pack.

= 1.0.4 =
* Fixed invoice creation failing when the Xcash API returns HTTP 201; both 200 and 201 are now treated as a successful response.
* The invoice pricing currency now follows the WooCommerce store currency instead of a separate setting, so the amount and currency always match.
* Webhook notifications delivered after a delay (retries) are no longer rejected by a timestamp window; replay protection is preserved via the signed nonce.

= 1.0.3 =
* Initial release with WooCommerce payment gateway integration for Xcash, webhook handler, credential testing, block-based checkout support, and bilingual strings.

== Upgrade Notice ==

= 1.0.7 =
Shows core Xcash payment details on admin orders.

= 1.0.6 =
Removes the obsolete webhook URL display from the gateway settings and changes the default payment duration to 20 minutes.

= 1.0.5 =
Adds the configurable gateway URL setting and refreshed Simplified Chinese language files.

= 1.0.4 =
Fixes invoice creation against the current Xcash API and aligns the pricing currency with your store currency. Recommended for all users.

= 1.0.3 =
Initial release submitted to the WordPress.org plugin directory.
