=== PD.Cash Payment Gateway ===
Contributors: pdcash
Tags: payments, payment gateway, woocommerce, pd.cash
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 8.1
Stable tag: 1.3.2
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Accept PD.Cash payments: securely link your account, watch your live balance, take payments at WooCommerce checkout.

== Description ==

PD.Cash Payment Gateway connects your WordPress site to your PD.Cash account.

* **Secure account linking** — sign in at PD.Cash, review the requested permissions and approve your WordPress site. Your PD.Cash password is never shared with WordPress.
* **Manual connection available** — API key and secret fields remain available as a fallback, including free sandbox keys for testing.
* **Live balance in your dashboard** — a WordPress dashboard widget and the PD.Cash admin page show your current balance against your API key, with one-click refresh.
* **Package and gateway visibility** — see your current package, available payment gateways and each gateway's supported amounts when the PD.Cash account-capabilities API is available.
* **Free Plan upgrade guidance** — when PD.Cash provides an eligible paid-package offer, Free Plan accounts can see its currently active public payment methods and supported amounts before upgrading.
* **WooCommerce checkout** — customers are redirected to a secure PD.Cash hosted payment page. Orders complete automatically via webhooks with an API-side verification step, plus a 5-minute polling fallback for sites webhooks can't reach.
* **Sandbox mode** — use pk_sandbox_ keys to test the full flow without real money; sandbox and live data never mix.
* **Everything else on PD.Cash** — payouts, transaction history, disputes, branding and the rest of the toolkit live in your PD.Cash dashboard; the plugin links you straight there.

== Installation ==

1. Upload the plugin to `/wp-content/plugins/` and activate it.
2. Open **PD.Cash** in the WordPress admin menu.
3. Click **Connect PD.Cash**, sign in on pd.cash and approve the connection. Secure account linking requires an HTTPS WordPress site with a working REST API.
4. If account linking is unavailable, use the manual API key and secret fields. Sandbox keys remain supported.
5. With WooCommerce active, enable **PD.Cash** under WooCommerce → Settings → Payments.

== External services ==

This plugin connects to PD.Cash (`https://pd.cash`) to link the merchant account, retrieve account balance and payment capabilities, create hosted payment invoices, and verify invoice and transaction status.

When a customer checks out with PD.Cash, the plugin sends the payment amount, an opaque WooCommerce order reference, customer name and email address, site URL, webhook URL, and plugin version to PD.Cash. OAuth account linking sends the WordPress site URL, callback URL, installation identifier, and a short-lived ownership proof. PD.Cash returns account, invoice, and transaction information required to display the dashboard and complete the order.

PD.Cash Privacy Policy: https://pd.cash/privacy
PD.Cash Terms of Service: https://pd.cash/terms

== Frequently Asked Questions ==

= Do I need WooCommerce? =
The live balance widget works with plain WordPress. Checkout payments require WooCommerce.

= Which currencies are supported? =
USD only. The current minimum, maximum and supported gateway amounts come from the authenticated PD.Cash API response and are shown on the plugin dashboard.

= How are payments confirmed? =
PD.Cash sends a webhook to your site when a payment completes. The plugin never trusts the webhook alone: it re-verifies every payment against the PD.Cash API with your credentials before marking the order paid. A cron poller also checks pending orders every 5 minutes as a fallback.

= Is there a test mode? =
Yes. Generate free sandbox keys (pk_sandbox_/sk_sandbox_) on the PD.Cash API Access page and paste them into the plugin. Sandbox payments never touch real money.

= Is connecting through PD.Cash secure? =
The plugin uses OAuth 2.0 Authorization Code with PKCE S256, a single-use state value and explicit consent on pd.cash. Access and rotating refresh tokens are encrypted before WordPress stores them. Disconnecting asks PD.Cash to revoke the grant before the local token copy is removed. The plugin never receives your PD.Cash password or an OAuth client secret.

== Changelog ==

= 1.3.1 =
* Only pending or on-hold orders with an exact current whole-dollar USD total can settle automatically; changed, cancelled, failed, or mismatched payments require merchant reconciliation.
* Validated returned invoice amounts and opaque order references before storing a payment link, and rotate expired retry links while keeping historic invoices reconcilable.
* Made unsigned webhook verification reservations atomic, aligned pending-connection protection with the reconciliation window, and fail closed if disconnect credential removal cannot be saved.
* Added immutable signed-update fixtures and a reproducible production-package build check.

= 1.3.0 =
* Hardened credential storage, hosted payment URL validation, webhook handling, and signed update verification.
* Replaced externally shared WooCommerce order keys with opaque payment references.
* Reused pending payment links and retained invoice history so existing payments remain reconcilable.
* PD.Cash now accepts only exact whole-dollar USD order totals; fractional totals are not converted into a higher charge.

= 1.2.7 =
* Display withdrawal totals as positive outflow amounts in the WordPress dashboard while retaining the signed API value for accounting.

= 1.2.6 =
* Made the current package's available payment methods and API-supported amounts explicit for paid accounts.
* Improved Google Pay and Chime mark sizing across the dashboard and both WooCommerce checkout types.
* Updated the Crypto mark to a neutral network symbol that does not imply a specific digital asset.

= 1.2.5 =
* Free Plan accounts can now see an API-driven upgrade view of payment methods currently active for the recommended paid package, including their supported amounts.
* Upgrade availability is fail-closed and keeps provider, routing and other internal payment metadata out of WordPress.

= 1.2.4 =
* Updated the Crypto artwork and versioned payment-method image URLs so refreshed assets appear immediately after an update.

= 1.2.3 =
* Refined the PD.Cash admin screen with payment-method filtering, collapsible long amount lists and clearer mobile labels.
* Improved filter accessibility with a live no-results announcement.

= 1.2.2 =
* New "Payment pipeline" health card on the settings page: last webhook received, poller schedule (with a warning when WP-Cron is disabled), and how many orders are awaiting payment.
* Payment events (invoice created, webhook results, confirmations, failures) are now logged under WooCommerce > Status > Logs, source "pdcash".

= 1.2.1 =
* Order-received page now watches for payment confirmation live and updates automatically once PD.Cash confirms — no manual reload.
* Failed or cancelled PD.Cash orders now explain what happened and offer a one-click payment retry.
* The pending-payment box shows the exact amount due and invoice ID, and inherits the theme's colors instead of hardcoded greys.

= 1.2.0 =
* New PD.Cash panel on the order edit screen (classic and HPOS): invoice ID, environment, exact charge, PD.Cash fee and net once paid, payment page link, and a "Check payment status now" button for on-demand confirmation.
* Webhook verification now records the PD.Cash fee on the order.

= 1.1.9 =
* Improved whole-dollar checkout validation across classic and block checkout.

= 1.1.8 =
* Refund guidance: attempting an API refund now explains the manual PD.Cash dashboard flow instead of failing silently, and a new "PD.Cash: mark as manually refunded" order action records dashboard refunds in WooCommerce.

= 1.1.7 =
* Connection failure notices now quote the exact PD.Cash error message, so rejected or unreachable credentials are diagnosable at a glance.

= 1.1.6 =
* Settings now show the site's webhook endpoint URL with a copy button, next to the webhook secret it pairs with.

= 1.1.5 =
* Block checkout: "Proceed to PD.Cash" place-order button, live availability that reacts to cart total and currency, merchant description markup rendered faithfully, supported-methods strip and a secure-redirect note in the payment panel, and translation support for checkout strings.

= 1.1.4 =
* New customer email: the PD.Cash payment link is sent as soon as an order is placed, so shoppers can finish paying from their inbox. Manage it under WooCommerce > Settings > Emails.
* New order action to re-send the payment link for unpaid PD.Cash orders.

= 1.1.3 =
* Show which PD.Cash account is connected (email address) on the settings page, account summary and dashboard widget.

= 1.1.2 =
* Replace gateway availability dots with accessible text status pills.
* Remove the redundant live-mode badge and post-connection success banner.
* Keep operational notices in the correct dashboard location and improve their dismiss controls.

= 1.1.1 =
* Fix dashboard widget package row overlapping the upgrade and manage actions in narrow columns.
* Match the dashboard widget primary button to the PD.Cash brand colour used on the settings page.

= 1.1.0 =
* Add secure PD.Cash account linking with OAuth 2.0 Authorization Code, PKCE S256, explicit consent, encrypted token storage, refresh-token rotation and revocation.
* Keep manual API key credentials as a fallback and automatically use OAuth bearer authentication for linked accounts.
* Show the current account package and available gateways with their supported amount ranges in the PD.Cash settings page and WordPress dashboard widget.
* Display only explicitly available, API-named gateways and remove internal gateway metadata before caching or rendering.
* Improve the account dashboard layout, responsive gateway table and refresh feedback.
* Use pd.cash exclusively for production API and account links.
* Refresh balance and account capabilities independently, preserving the latest verified account data when one service is temporarily unavailable.
* Harden hosted checkout validation, webhook verification, polling fairness, API error handling and connection-state recovery.
* Isolate parallel OAuth connection attempts and re-register older cached clients during the secure server transition.
* Encrypt manual API and webhook secrets at rest, including automatic migration from earlier plaintext settings.
* Bound dashboard API latency and rate-limit unsigned webhook verification attempts without weakening payment checks.
* Add privacy-policy guidance, external-service disclosure and translation support.
* Keep API and webhook secrets out of rendered settings HTML.

= 1.0.0 =
* Initial release: account connect, live balance dashboard widget, WooCommerce gateway (classic + block checkout), webhook confirmation with API verification, polling fallback, sandbox support.
