=== TINXDK Pensopay Auto Capture Lite ===
Contributors: tinxdk
Tags: woocommerce, pensopay, quickpay, capture, payments
Requires at least: 6.3
Tested up to: 7.1
Requires PHP: 8.2.35
Requires Plugins: woocommerce
WC requires at least: 8.0
WC tested up to: 9.9
Stable tag: 2.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Captures the Pensopay amount automatically when a WooCommerce order is completed. Test mode, order notes and double-capture protection.

== Description ==

When an order changes to "Completed", this plugin asks Pensopay for the payment first and captures only what is still open, so an order is never captured twice. Every attempt gets an order note and a log entry.

Features:

* Automatic capture when an order changes to "Completed": the order total minus refunds, never more than is authorized.
* "Amount to capture" per order on the order screen (HPOS and classic), for discounts and credit notes. It prevents charging the customer too much.
* Test mode (on by default until you switch it off): logs and adds an order note what would happen, without any request to Pensopay.
* An order note for every capture attempt and its result, plus a log in the database (kept 90 days by default) and in the WooCommerce logs.
* Double-capture protection: the payment is read from Pensopay first, a per-order lock stops concurrent status changes, and an already captured payment is skipped.
* Two APIs, chosen in the settings: QuickPay-compatible (default, the API of the official Pensopay for WooCommerce plugin) and Pensopay API v2.
* Works with the official Pensopay for WooCommerce plugin: its transaction ids are used, and when its "Capture on complete" option is on this plugin leaves the Completed status to it (admin notice) so nothing is captured twice.
* Imports the settings of the old "OpenDIMS - Auto-capture Godkendte Ordre - Pensopay" plugin on activation and pauses itself while that plugin is still active.
* HPOS (custom order tables) compatible. The plugin has no public form and no public REST route.

**Pro add-on:** the separate plugin "TINXDK Pensopay Auto Capture Pro" (licence key, not on WordPress.org) adds the choice of other trigger statuses, "Capture now / retry" (order action and bulk action), a searchable capture log and an e-mail when a capture fails. This plugin works fully without it. More at https://tinxdkcloud.dk/wordpress-plugins/tinxdk-pensopay-capture/#pro

Developer hooks: filters `tinxdk_pc_payment_id` ( $id, $order ), `tinxdk_pc_should_capture` ( $bool, $order ), `tinxdk_pc_trigger_statuses` ( array( 'completed' ) ), `tinxdk_pc_settings_defaults`, `tinxdk_pc_sanitize_settings` and `tinxdk_pc_admin_tabs`; actions `tinxdk_pc_captured` ( $order, $amount_minor_units, $payment_id ), `tinxdk_pc_capture_failed` ( $order, $payment_id, $message ), `tinxdk_pc_admin_sections`, `tinxdk_pc_admin_tab` and `tinxdk_pc_loaded`.

== External services ==

This plugin sends requests to the payment API of Pensopay (Pensopay A/S, which also operates QuickPay). The API you choose in the settings is the only service it contacts, and only with the API key you enter yourself.

**QuickPay-compatible API (default): https://api.quickpay.net** (or **Pensopay API v2: https://api.pensopay.com/v2** when you choose "Pensopay API v2" in the settings).

* What is sent: the Pensopay payment id (the transaction id of the order), the amount to capture in the smallest currency unit (for example øre) and your Pensopay API key as the authentication (HTTP header). The shop's IP address and the plugin's request itself are of course visible to the service. No customer name, address or e-mail is sent.
* When: when an order reaches the status "Completed" (and the payment is not in test mode): first a read of the payment (payment id), then, if something is open, the capture (payment id and amount). Also when an administrator clicks "Test connection" on the settings page (one read-only request that lists one payment). In test mode no request is sent at all.
* Terms of service: https://pensopay.com/handelsbetingelser (QuickPay: https://quickpay.net/terms-of-service/)
* Privacy policy: https://pensopay.com/en/privacy-policy

No other external service is contacted. The plugin does not phone home and has no updater: updates come from WordPress.org.

== Installation ==

1. Install the plugin from Plugins > Add New (search for "TINXDK Pensopay Auto Capture Lite") or upload the folder to `/wp-content/plugins/`, and activate it. WooCommerce must be active.
2. Deactivate "OpenDIMS - Auto-capture Godkendte Ordre - Pensopay" if it is still active.
3. Open WooCommerce > Pensopay Auto Capture, save your Pensopay API key, use "Test connection", then switch test mode off.

== Frequently Asked Questions ==

= Is it safe to switch on? =
Test mode is on by default: nothing is sent to Pensopay and nothing is captured until you switch it off. In test mode you can see in the order notes and the WooCommerce logs what would have happened.

= How much is captured? =
The order total minus WooCommerce refunds (or the amount you set in the "Amount to capture" box on the order), never more than Pensopay has authorized and never more than what is still open on the payment.

= Which order statuses capture? =
"Completed". The Pro add-on lets you choose other statuses.

= The official Pensopay plugin also captures on complete. Will it be captured twice? =
No. When the official plugin's "Capture on complete" is on, this plugin leaves the Completed status to it and shows a notice. The payment state is also checked before every capture.

= Where is the log? =
Every attempt is written to the order notes, to a table in the database (deleted after the retention you set, 90 days by default) and to the WooCommerce logs (source `tinxdk-pensopay-capture`). The searchable log page is part of the Pro add-on.

= What is removed when I delete the plugin? =
The settings, the saved API key, the log table (`{prefix}tinxdk_pc_log`), per-order locks and the scheduled clean-up. The capture data on the orders (order meta starting with `_tinxdk_pc_`) is kept.

== Changelog ==

= 2.0.1 =
* Changed: Renamed to TINXDK Pensopay Auto Capture Lite (no functional change). Slug, settings and data are unchanged.

= 2.0.0 =
* Split into two plugins. This plugin is the free edition for WordPress.org and contains no licence code. The licensed features (choice of trigger statuses, "Capture now / retry" order action and bulk action, the searchable capture log, the failure e-mail and updates from the TINXDK licence server) moved physically into the new plugin "TINXDK Pensopay Auto Capture Pro" (`tinxdk-pensopay-capture-pro`). Settings, the log table, order meta and constants are unchanged, so Pro picks up where you left off.
* Renamed: the plugin folder is now `tinxdk-pensopay-capture` (it was `tinxdk-wp-pensopay-capture`). Deactivate the old plugin before activating this one; the settings are kept.
* New: extension points for add-ons (filters `tinxdk_pc_trigger_statuses`, `tinxdk_pc_settings_defaults`, `tinxdk_pc_sanitize_settings`, `tinxdk_pc_admin_tabs`; actions `tinxdk_pc_admin_sections`, `tinxdk_pc_admin_tab`, `tinxdk_pc_capture_failed`, `tinxdk_pc_loaded`).
* New: a dismissible hint about Pro on the plugin's own settings page and a "Pro" link on the plugins list.
* Changed: the plugin no longer loads its translation itself (WordPress does); the Danish translation is bundled.
* Changed: database queries use prepared identifiers, input is unslashed and sanitized (WordPress Plugin Check).
* Documented the external services (Pensopay / QuickPay API).

= 1.1.0 =
* New: the amount to capture is the order total minus WooCommerce refunds (not the authorized amount), never more than what is authorized.
* New: "Amount to capture" box on the order screen (HPOS and classic) to set a different amount per order.

= 1.0.0 =
* First release: capture on "Completed" through the QuickPay-compatible API (default) or Pensopay API v2, guard against the official plugin's "Capture on complete", test mode, order notes, double-capture protection, capture log, import from the old OpenDIMS plugin.

== Upgrade Notice ==

= 2.0.1 =
Renamed to TINXDK Pensopay Auto Capture Lite (no functional change).

= 2.0.0 =
The licensed features moved to the separate plugin "TINXDK Pensopay Auto Capture Pro". Without it, only "Completed" triggers a capture. Settings and data are kept.
