=== Chave Direta for Pix ===
Contributors: starlink1207
Tags: pix, woocommerce, payment gateway, brazil, qr code
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Accept Pix in WooCommerce with a QR code and copy-and-paste code for the exact order total, a Pix discount, receipt uploads and auto-cancel.

== Description ==

Chave Direta for Pix adds Pix, the instant payment system of the Banco Central do Brasil, to your WooCommerce store. Payments go straight to your own Pix key and bank account: there is no payment company in between and no gateway fee from this plugin (your bank's own terms apply).

When the customer places an order, the plugin generates a BR Code (the official Pix "copy and paste" format) with your Pix key, the exact order amount and a transaction ID, and draws the QR code on your own server. Nothing is sent to third-party services.

**Why stores choose it**

* No payment company, so no per-sale fee: money goes straight to your own Pix key. There is no gateway fee from this plugin; your bank's own terms apply.
* Maintained for the Cart & Checkout blocks, High-Performance Order Storage (HPOS) and current WordPress and WooCommerce versions.
* A complete manual workflow out of the box (QR code, receipts, confirmation, automatic cancellation), and the option to upgrade to automatic confirmation later without switching plugins or losing orders.
* Looks native in any theme: it uses your theme fonts, colours and buttons, works on phones, dark themes and right-to-left languages, and loads its small CSS and JavaScript only on the order page.

**For your customers**

* QR code and copy-and-paste code on the order received page, the order payment page, in My Account and in the order email.
* One-click "Copy code" button that works on phones, with a read-only code field as a fallback. The copied code never contains line breaks.
* Optional discount when paying with Pix, shown at checkout as "Pix (5% off)".
* Countdown to the payment deadline.
* The page updates by itself as soon as you confirm the payment.
* Upload of the payment receipt (JPG, PNG, WebP or PDF), or "Send receipt via WhatsApp" with the order number and amount already filled in.

**For you**

* Works with CPF, CNPJ, email, mobile phone and random (EVP) keys, with CPF/CNPJ check-digit validation.
* "Test my Pix code": builds a sample R$ 1,00 code, reads it back and shows exactly what the bank app will show (receiver name, city, key, amount, transaction ID, CRC check) with the QR code, and warns about the usual mistakes (phone key without +55, punctuation in CPF/CNPJ, accents or names over 25 characters).
* Pix discount as a percentage or fixed amount. It is added only while Pix is the selected method, recalculated when the customer switches method (classic and block checkout) and checked again when the order is created, so it can never end up on a card payment.
* One-click import of your Pix key, key type, receiver name and city from "Pix por Piggly" (the other plugin is left untouched).
* WooCommerce > Pix Payments screen with every Pix order, receipts, deadlines and one-click "Confirm payment" or "Cancel order" (also in bulk).
* "Pix payment" box and "Confirm Pix payment received" action on the order screen.
* Email notification when a receipt is uploaded. Receipts are stored in a private folder and can only be opened by shop managers.
* Unpaid orders are cancelled automatically after the deadline you choose, and stock goes back to your inventory. Orders with a receipt can be kept for review.
* Classic checkout and Cart & Checkout blocks. Compatible with High-Performance Order Storage (HPOS).
* Translation ready, with Brazilian Portuguese included.

The Pro version connects to Mercado Pago or PagBank to create a dynamic Pix charge for each order and confirms payments automatically through webhooks (with a polling backup), so there is nothing to check by hand. Refunds made in WooCommerce are sent to the provider, refunds made at the provider are reflected in the order, and customers get a reminder email with the Pix code a few hours before an unpaid order would be cancelled.

== Installation ==

1. Install and activate WooCommerce, and set the store currency to Brazilian real (BRL).
2. Upload the plugin to `/wp-content/plugins/chave-direta-for-pix/` or install it from the Plugins screen, then activate it.
3. Go to WooCommerce > Pix Payments > Settings and enter your Pix key type, Pix key, receiver name and city. Coming from Pix por Piggly? Click "Import these settings" in the notice instead.
4. Use "Test my Pix code" on the same screen and scan the sample QR code with your bank app (without confirming) to check the receiver data.
5. Go to WooCommerce > Settings > Payments, enable Pix and adjust the title and description shown at checkout.

== Frequently Asked Questions ==

= Do I need an account with a payment company? =

No. The free version uses your own Pix key. Customers pay directly to your bank account and you confirm the payment in WooCommerce > Pix Payments after you see it in your bank app.

= Are there fees? =

This plugin charges no gateway fee and takes no share of your sales. Pix transfers are handled by your bank, so your bank's own terms apply.

= How do I know which transfer belongs to which order? =

Each code carries a transaction ID made of your prefix and the order number (for example WC1234). Most banks show it in the transfer details. The amount is also fixed for each order.

= How does the Pix discount work? =

Set a percentage or a fixed amount in WooCommerce > Pix Payments > Settings > Checkout. It is applied to the products total (after coupons, without shipping) as a negative fee only while Pix is selected, and the totals refresh when the customer switches method. When the order is created the plugin checks the payment method again and removes the discount from any order that is not paid with Pix. Set it to 0 to turn it off.

= How do I check that my Pix code is right before selling? =

Open WooCommerce > Pix Payments > Settings and use "Test my Pix code". It shows exactly what the bank app will display and warns about typical mistakes. You can also try other values there without saving them.

= Can I move from Pix por Piggly? =

Yes. When its settings are found, a notice offers to import the Pix key, key type, receiver name and city. Nothing is changed in the other plugin; deactivate it yourself when you are ready.

= How does "Send receipt via WhatsApp" work? =

Enter your store WhatsApp number in the settings. The order page then shows a button that opens WhatsApp with a message containing the order number and amount, so the customer only has to attach the receipt.

= What happens if the customer does not pay? =

The order stays "On hold" until the deadline (24 hours by default). After that it is cancelled automatically and the stock is restored. Set the deadline to 0 to turn this off.

= Where are the receipts stored? Are they public? =

In `wp-content/uploads/chave-direta-for-pix-proofs/` with random file names and deny rules for Apache. Shop managers open them through a protected link in the admin. On Nginx you can add a `deny all` rule for that folder for extra protection.

= Why doesn't Pix show at checkout? =

Pix appears only when the gateway is enabled, the Pix key, receiver name and city are valid, and the store currency is BRL.

= Does it work with the block checkout? =

Yes, both the classic shortcode checkout and the Cart & Checkout blocks are supported, including the Pix discount.

= Does it slow down my site? =

No. Its CSS and JavaScript load only on the order page that shows the Pix code, and it makes no external requests while visitors browse.

= What is removed when I delete the plugin? =

Settings and scheduled tasks are always removed. If you enable "Delete uploaded receipts and Pix order data" in the settings, receipts and Pix order details are removed too. Orders themselves are never deleted.

== Screenshots ==

1. Pix QR code, copy-and-paste code and payment deadline on the order received page.
2. Pix Payments screen: every Pix order with receipts, deadlines and one-click confirmation.
3. Settings: Pix key, receiver details, Pix discount, deadline and receipt options.
4. "Test my Pix code": what the bank app will show, with the sample QR code.

== Changelog ==

= 1.0.3 =
* New: discount when paying with Pix (percentage or fixed amount), recalculated when the customer switches method in classic and block checkout, and checked again when the order is created.
* New: "Test my Pix code" builds a sample R$ 1,00 code, decodes it and warns about common mistakes.
* New: one-click import of the receiver details from Pix por Piggly.
* New: "Send receipt via WhatsApp" button on the order page.
* New in Pro: reminder email with the Pix code before an unpaid order is cancelled.
* Improved: safer copy on the order page (read-only fallback field, never copies line breaks).
* Improved: the payment box follows the theme fonts, colours and buttons, including dark themes, RTL and mobile.
* Improved: fewer database queries on normal pages; payment list counts are cached.
* Changed: "Pix" is now written as the Banco Central brand ("Pix", not "PIX") everywhere.

= 1.0.2 =
* Brazilian Portuguese (pt_BR) translation included.
* Hardened output escaping, input sanitizing and database queries.
* 14-day free trial of Pro from the plugin screen.

= 1.0.1 =
* Pix is turned on at checkout automatically the first time the receiver details are saved, and the Pix screen warns when the gateway is turned off.
* Cleaner admin menu (no separate Contact Us item).

= 1.0.0 =
* First release: BR Code and QR code generation, classic and block checkout, receipt uploads, manual confirmation, automatic cancellation of unpaid orders.
