=== Lopay Gateway for WooCommerce ===
Contributors: lopay
Tags: woocommerce, payments, payment gateway, checkout, lopay
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 8.3
Stable tag: 0.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Requires Plugins: woocommerce

Accept payments via Lopay on your WooCommerce store.

== Description ==

Lopay Gateway for WooCommerce lets merchants accept card payments through [Lopay](https://lopay.com) directly from their WooCommerce checkout.

= External service =

This plugin connects your store to the Lopay payment platform (lopay.com) to process payments. When you enable and configure the gateway, the plugin sends payment and order information (such as order amount, currency, and a reference to the order) to Lopay's API in order to take payment, and receives payment status updates back from Lopay. This only happens once you have explicitly connected your store to your Lopay merchant account and enabled the gateway — no data is sent to Lopay before that point.

Once connected, the plugin also asks Lopay (GET /merchant-api/me, sending your API key) for your account's currency when you connect and again about every five minutes while the store is in use, so a currency change on your Lopay account is picked up.

By using this plugin you agree to [Lopay's Terms of Use](https://lopay.com/legal/terms) and [Privacy Policy](https://lopay.com/legal/privacy). Please review these before connecting your store.

= Data collected =

To process a payment, the plugin shares the following with Lopay: order total and currency, an order reference/id, and (depending on the payment method) the customer's billing details needed to complete the transaction. Card details are handled directly by Lopay and never stored by this plugin or your WordPress database. See [Lopay's Privacy Policy](https://lopay.com/legal/privacy) for how Lopay handles this data.

== Installation ==

1. Upload the plugin files to `/wp-content/plugins/woocommerce-lopay-gateway`, or install the plugin through the WordPress Plugins screen directly.
2. Activate the plugin through the 'Plugins' screen in WordPress.
3. Make sure WooCommerce is installed and active.
4. Go to **WooCommerce > Settings > Payments > Lopay** to connect your store and configure the gateway.

== Frequently Asked Questions ==

= Does this plugin store my Lopay credentials in the WordPress database? =

Your Lopay API key is never saved as plain text. It is encrypted with libsodium before it is written to the database, or you can keep it out of the database entirely by defining `WC_LOPAY_API_KEY` in wp-config.php. The plugin does not store your Lopay account password or raw card details.

The encryption key is derived from your site's `LOGGED_IN_KEY` and `LOGGED_IN_SALT`, or from `WC_LOPAY_ENCRYPTION_KEY` if you define it. If those values change (for example after rotating your salts or moving the site to a host with different ones), the stored key can no longer be read: Lopay shows as disconnected and you paste the key again. Encryption protects a copy of the database, such as a leaked backup. It does not protect against someone who can run code on your site or read wp-config.php.

= How do I keep the API key in wp-config.php? =

Add this above the line "That's all, stop editing!":

`define( 'WC_LOPAY_API_KEY', 'your-lopay-api-key' );`

Then press Connect on the Lopay settings screen. To disconnect, remove the line as well as pressing Unlink. To choose your own encryption key for the stored copy, define `WC_LOPAY_ENCRYPTION_KEY` with a long random string.

= My Lopay account is in the United States. What do I change? =

The plugin talks to Lopay's UK and Europe service by default. For a US Lopay account, add this to wp-config.php above the line "That's all, stop editing!", then connect your key:

`define( 'WC_LOPAY_API_BASE_URL', 'https://us.api.lopay.com/api/1' );`

Without it, Lopay does not recognise a US key and Connect says the key doesn't look right.

= Why is Lopay hidden at checkout? =

Lopay only takes payments in the currency of your Lopay account and never converts. If your store currency differs, Lopay is hidden at checkout and the Lopay settings screen names both currencies. A plugin that changes the order's currency at checkout is refused with a notice before anything is sent. The currency and Stripe publishable key (both public, not secrets) are kept in the gateway settings when you connect, and re-read from Lopay about every five minutes; if Lopay cannot be reached the saved values are used. A store connected with an earlier version shows Lopay again once the currency has been read.

= How is a card payment verified? =

The shopper's card is entered into fields hosted by Stripe; the plugin never sees it. The plugin asks Lopay to start a payment for the order's exact total, and after the card is confirmed it asks Lopay again and only marks the order paid if Lopay reports the payment as succeeded for the same amount, currency and order. If anything does not match, the order is put on hold with a note and an entry in WooCommerce > Status > Logs (source: lopay) so you can check it. Lopay is only offered when your store currency equals your Lopay account's currency.

= Which WooCommerce checkout is supported? =

Both the block-based checkout (WooCommerce Blocks) and the classic shortcode checkout are supported, along with High-Performance Order Storage (HPOS).

= What happens if WooCommerce isn't active? =

The plugin shows an admin notice and does not attempt to register a payment gateway until WooCommerce is active.

= What does deleting the plugin remove? =

Deleting Lopay from the Plugins screen removes its settings and the stored API key, on every site of a network. Each order's Lopay payment details stay with the order. A key you added to wp-config.php stays there until you remove it.

== Screenshots ==

1. Lopay settings screen under WooCommerce > Settings > Payments.

== Changelog ==

= 0.2.0 =
* Default the Lopay API to production
* Cover signed webhook deliveries in the Playwright e2e suite
* Delete this site's webhook endpoint on unlink and uninstall
* Register this site's Lopay webhook endpoint and show its state
* Record refunds made in the Lopay dashboard or app from payment.refunded
* Finalise an order from Lopay's payment.success webhook
* Receive Lopay webhooks and verify the Svix signature
* Register and delete Lopay webhook endpoints through the merchant key
* Read the order from the database under the order lock
* Share the finalise lock with order-screen refunds
* Add a Prepare release workflow that bumps by patch, minor or major
* Manage Apple Pay and Google Pay domains from the Lopay settings screen
* Add admin-ajax handlers for the Apple Pay and Google Pay domain list
* Keep a list of Apple Pay and Google Pay domains, and release one at Lopay
* Remove the plugin's data when it is deleted
* Show the Lopay symbol and the Visa and Mastercard marks on the payment option
* Match the card field to the checkout's inputs and space the Lopay fields evenly
* Run Apple Pay and Google Pay end to end against the real Lopay API
* Show the Apple Pay and Google Pay button on the Blocks checkout
* Show the Apple Pay and Google Pay button on the classic checkout
* Accept Apple Pay and Google Pay payments on the server
* Register the store's domain for Apple Pay and Google Pay
* Register and list payment method domains through the merchant key
* Refund Lopay orders from the WooCommerce order screen
* Add a refund call to the API client
* Test the classic and Blocks checkouts end to end with Playwright
* Add Stripe card fields to the Blocks and classic checkout
* Take real card payments through Lopay checkout sessions
* Keep the merchant's currency and add checkout session calls to the API client
* Require PHP 8.3 and stop storing the API key in plaintext

= 0.1.0 =
* Require PHP 8.3 or newer; the plugin shows an admin notice and does not load on older versions.
* Card fields on the classic checkout: Stripe-hosted fields, 3D Secure and order confirmation. Lopay is not offered on the order-pay page.
* Card fields on the Blocks checkout: Stripe-hosted fields, 3D Secure and order confirmation.
* Initial scaffold: gateway registration, settings screen, HPOS/Blocks compatibility declaration.

== Upgrade Notice ==

= 0.2.0 =
Lopay now uses its production API by default. A staging store must define WC_LOPAY_API_BASE_URL in wp-config.php before updating. A US Lopay account needs https://us.api.lopay.com/api/1 (see the FAQ).

= 0.1.0 =
Initial release. Requires PHP 8.3 or newer.
