=== CatCode Invoices with Focus NFe for WooCommerce ===
Contributors: catcodestudio
Tags: nf-e, nota fiscal, focus nfe, woocommerce, brazil
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Issues the NF-e (model 55) of a WooCommerce order through your Focus NFe account, follows it until the SEFAZ authorizes it and shows the DANFE and XML on the order.

== Description ==

You sell with WooCommerce in Brazil and your accountant needs an NF-e for each sale. This plugin sends the order to your Focus NFe account, waits for the SEFAZ to answer and keeps the number, the access key, the DANFE and the XML on the order, so nobody types a sale twice.

Focus NFe is a third-party service. This is an independent integration, not affiliated with or endorsed by Focus NFe.

= What it does =

* **One click on the order.** The NF-e box on the order screen issues the document from the buyer, the products, the shipping, the discount and the payment method of the order.
* **Follows the document.** Focus NFe answers asynchronously. The plugin asks again after a few seconds, then after a few minutes, and stops when the NF-e is authorized, rejected or denied. The reason of a rejection is shown on the order, with a button to issue it again.
* **DANFE and XML on the order.** Links to the files, the number, the series and the access key.
* **Sandbox first.** Choose the sandbox (homologacao) or the production environment, each with its own token. Documents issued in the sandbox have no fiscal validity and the order says so.
* **CPF and CNPJ.** Read from the fields of the Brazilian Market and Extra Checkout Fields for Brazil plugins (`_billing_cpf`, `_billing_cnpj`, `_billing_persontype`, `_billing_number`, `_billing_neighborhood`, `_billing_ie`).
* **Totals that add up.** Discount, shipping and fees are spread over the items to the cent. If the NF-e total would differ from the order total, the plugin refuses to send and says why, instead of waiting for a SEFAZ rejection.
* **Safe to repeat.** A reference is kept for every attempt. If the answer to a send is lost, the plugin asks Focus NFe first and never sends the same sale twice.
* **Nothing guessed.** NCM, CFOP, origin, ICMS, PIS and COFINS are chosen by you or your accountant. Issuing stays blocked until they are complete.
* **A staging copy stays quiet.** If the site address changes, issuing stops until you confirm that this is the real store.

= What it does not do =

* It does not issue NFS-e (service) or NFC-e, only the NF-e of model 55 for products.
* It does not issue for buyers outside Brazil.
* It does not calculate taxes. The ICMS situations offered need no rate or base (for example Simples Nacional 102 or 400). A developer can add fields for other situations with the `catcode_fne_item` filter.
* It does not register your company or upload your certificate. Do that in the Focus NFe panel.

// @pro-begin
= Pro =

Sold on [catcode.com.ua](https://catcode.com.ua/modules/focus-nfe-woocommerce/) with a 7-day trial:

* **Issues by itself** when the order reaches the status you choose.
* **Tax data per product:** NCM, CFOP, origin, unit, ICMS, PIS and COFINS, over the defaults of the store.
* **Cancel an authorized NF-e** and e-mail it to the buyer again from the order.
* **Authorization trigger:** Focus NFe tells the store the moment the NF-e is authorized.
* **Issue past orders in bulk** from the orders list.
* **E-mail alerts** when Focus NFe refuses the token or an NF-e cannot be issued.
// @pro-end

== Installation ==

1. Install and activate the plugin. WooCommerce must be active.
2. In the Focus NFe panel register your company (CNPJ, address, digital certificate A1) and the NF-e document settings.
3. In the API panel, Tokens, copy the token of the sandbox environment. Use the token of the company, not the master token.
4. Open **WooCommerce > NF-e Focus NFe**, choose Sandbox and paste the token. It is kept encrypted with your site's keys.
5. On the **Invoices** tab fill in the CNPJ and state of the company and the tax defaults. Ask your accountant which values apply to your products.
6. Open an order and press **Issue NF-e**. Check the document in the Focus NFe panel before you switch to production.

== Frequently Asked Questions ==

= Does this need a CatCode account? =

No. The plugin talks to Focus NFe directly, with your own token.

= Which token do I use? =

The token of the company for the environment you chose. Sandbox and production have different tokens. The master token is not used.

= Does Focus NFe need a real CNPJ and certificate for the sandbox? =

That is a rule of Focus NFe, not of this plugin. Read their registration guide before you start.

= An NF-e was rejected. What now? =

The order box and the Activity tab show the reason given by the SEFAZ. Fix the order or the settings and press **Issue a new NF-e**.

= How long can an NF-e be cancelled? =

The limit is set by the SEFAZ of each state. Focus NFe refuses the cancellation after it and the plugin shows its message.

// @pro-begin
= Will old orders get an NF-e when I connect? =

No. Only orders placed after connecting are issued automatically. An older one can be issued from its own screen.
// @pro-end

= Does it use up my API calls? =

Focus NFe allows 100 calls a minute for each token. An NF-e takes one call to send and a few to follow. The plugin spaces its calls and waits when asked to.

== External services ==

This plugin connects to Focus NFe, an NF-e issuing service run by a third party, because issuing the document there is its purpose.

It sends, from your server to the Focus NFe API (https://api.focusnfe.com.br for production, https://homologacao.focusnfe.com.br for the sandbox):

* when you connect or press the test button: your token, in a request for a document that does not exist, to check that the token is accepted;
* when you issue an NF-e, or an order reaches a chosen status: the data of the document, which are the CNPJ you entered, the buyer's name, CPF or CNPJ, e-mail, phone and address, the products with their prices and tax codes, the shipping, the discount and the payment method;
* afterwards: the reference of the document, to ask how it is going.

Nothing is sent before you enter your token. Focus NFe: [terms of use](https://focusnfe.com.br/termos-de-uso/).

== Changelog ==

= 1.0.0 =
* First release.

== Upgrade Notice ==

= 1.0.0 =
First release.
