=== CatCode E-Invoice with ClearTax for WooCommerce ===
Contributors: catcodestudio
Tags: e-invoice, irn, gst, india, cleartax
Requires at least: 6.4
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

Registers WooCommerce orders as GST e-invoices through your ClearTax (Clear) account: IRN, acknowledgement and signed QR code on the order.

== Description ==

For Indian stores that have to report their B2B invoices to the Invoice Registration Portal. The plugin sends an order to the E-Invoicing API of [ClearTax (Clear)](https://www.clear.in/) with your own API client, and keeps what comes back on the order.

* **Generate IRN from the order screen** — one button in the "E-invoice (ClearTax)" box. The IRN, the acknowledgement number and date and the signed QR code are saved on the order.
* **Check before you send** — the "Check" button looks at the order first (GSTIN of the buyer, State and PIN code, HSN or SAC of every line, document number, totals) and then runs the validation of ClearTax without registering anything.
* **Signed QR code where it is needed** — on the order screen, in the order e-mails, on the order page of the customer's account, and on the invoice and credit note printed by CatCode GST Invoice (its version 1.0.1 or newer), and on the invoice of "PDF Invoices & Packing Slips for WooCommerce" if you use it. The code is printed as the portal signed it.
* **E-invoice PDF** — download the PDF ClearTax prints for the IRN.
* **Link an IRN that exists already** — paste an IRN and the plugin reads the document back from ClearTax; useful after a request that timed out.
* **B2B, SEZ, deemed export and export** — the supply type is worked out from the order and can be set by hand. Orders in another currency take an exchange rate.
* **Sandbox and production** — switch on the settings screen. The client secret is stored encrypted, and the access token is reused until it expires, because ClearTax issues a limited number of tokens a day.
* HPOS and block checkout compatible.

= Works with CatCode GST Invoice and GSTR-1 =

If [CatCode GST Invoice and GSTR-1 for WooCommerce](https://catcode.com.ua/modules/gst-invoice-gstr1-woocommerce/) is active, this plugin adds no second GSTIN field and no second HSN field. It takes the buyer's GSTIN, the HSN codes and units, and the number, date and amounts of the tax invoice issued there, so the e-invoice is the same document the buyer holds. An order without a tax invoice gets one there first.

Without it, the plugin has its own fields: GSTIN and business name at the checkout (classic and block), HSN and unit code on products, and a number made of a prefix and the order number.

= Pro =

The Pro version is sold on [catcode.com.ua](https://catcode.com.ua/modules/catcode-e-invoice-with-cleartax-for-woocommerce/), with a 7-day trial that never starts by itself:

* **IRN by itself** — when an order becomes Processing or Completed, in the background.
* **Many orders at once** — a bulk action in the orders list, and an "E-invoice" column.
* **Cancel an IRN** — with the reason, from the order screen.
* **E-way bill** — from the IRN, or for orders that need no IRN; transporter, vehicle, Part B update, cancellation and the e-way bill PDF.
* **Credit notes** — a refund of an order with an IRN is registered as a credit note that points at the invoice.
* **B2C payment QR** — the dynamic UPI QR code of ClearTax for orders of buyers without a GSTIN.
* **Log** — every request with its result and, for the error codes ClearTax documents, what to do about it.
* Updates from catcode.com.ua.

The licence runs for 1-5 years and includes updates and support for that term; a purchased licence keeps its Pro features after the term ends. One key covers two sites: the shop and its test copy.

ClearTax and Clear are trademarks of their owner. This plugin is an independent integration made by CatCode; it is not an official plugin of ClearTax and is not affiliated with or endorsed by it. You need your own ClearTax account with the E-Invoicing product. This is software, not tax advice.

== External services ==

The plugin connects to the ClearTax (Clear) API ([docs.cleartax.in](https://docs.cleartax.in/cleartax-docs/e-invoicing-api/introduction-to-e-invoicing-api)) at `api.clear.in` (production) or `api-sandbox.clear.in` (sandbox), and only after you save a client secret.

* When you press "Check connection", and whenever a new access token is needed: your client secret.
* When you press "Check" or "Generate IRN" on an order: the document of that order — GSTIN, name, address, phone and e-mail of your store and of the buyer, the shipping address, the lines with HSN codes, quantities and amounts, and the totals.
* When you press "Refresh status", "Link this IRN" or "Download PDF": the IRN and your GSTIN.
* In Pro the same document is sent without a click when an order reaches the status you chose, and for refunds (credit notes), e-way bills (with the transporter and vehicle you enter) and B2C payment QR codes (with your UPI ID).
* Pro also contacts catcode.com.ua: to check the licence key (the key and the site address) and to look for updates.

[Clear terms of use](https://www.clear.in/meta/terms) and [privacy policy](https://www.clear.in/meta/privacy).

== Installation ==

1. Upload the plugin and activate it. WooCommerce must be active.
2. In your Clear account open Settings → Integrations → API Clients, create an API client with the E-Invoicing product and copy the client secret. Add your GSTIN and its portal (NIC) API credentials to the workspace.
3. WooCommerce → **E-Invoice (ClearTax)**: choose the environment, paste the client secret, press "Check connection", fill in the store details, save.
4. Open an order of a buyer with a GSTIN, press "Check", then "Generate IRN".

== Frequently Asked Questions ==

= Do I need a ClearTax account? =

Yes. The API client and its client secret belong to you, and e-invoices are registered under your GSTIN.

= Which orders get an IRN? =

Orders of buyers with a GSTIN (B2B), SEZ and deemed export supplies, and exports. Orders of buyers without a GSTIN are B2C: the portal does not register them.

= Can I test without touching the real portal? =

Yes, in the sandbox. It accepts only the test GSTINs of ClearTax as the seller, for example 29AAFCD5862R000; they are listed in the ClearTax documentation.

= What if the request times out? =

Nothing is saved as registered unless ClearTax confirmed it. If the document did reach the portal, a second attempt is refused as a duplicate: find the document in ClearTax, copy its IRN and use "The IRN exists already?" on the order.

= Does it calculate GST? =

No. It reports what the order charged. Set up your tax rates in WooCommerce (CatCode GST Invoice does that for you).

== Changelog ==

= 1.0.0 =
* First release.
