=== TAFI - Págalo Relax ===
Contributors:      tafitechsys
Tags:              payment-gateway, bnpl, buy-now-pay-later, installments, checkout
Requires at least: 5.8
Tested up to:      7.0
Requires PHP:      8.0
Stable tag:        1.1.0
License:           GPL-2.0-or-later
License URI:       https://www.gnu.org/licenses/gpl-2.0.html

Accept TAFI Buy Now, Pay Later payments in your WooCommerce store. No card needed. Confirmed via WhatsApp.

== Description ==

**TAFI Pay** lets your customers buy now and pay in installments without a credit card, using a WhatsApp-based confirmation flow operated by TAFI Tech in Panama.

**How it works:**

1. The customer selects "Pay with TAFI" at checkout
2. The customer enters a Panamanian mobile phone number
3. TAFI sends a credit request to the customer through WhatsApp
4. The customer accepts within 2 minutes and the payment is confirmed automatically
5. Your store receives a webhook notification and processes the order

**Features:**

* Native integration with WooCommerce, no extra code required
* Simple setup: only an API Key and Merchant ID are needed
* Sandbox and production environments
* Automatic notifications via webhook
* High-Performance Order Storage (HPOS) compatible
* WooCommerce Checkout Blocks compatible
* Transaction details visible in the order admin panel
* Debug logs integrated with WooCommerce

**Requirements:**

* WordPress 5.8+
* WooCommerce 6.0+
* PHP 8.0+
* Active TAFI merchant account, available at the TAFI merchant portal

== Installation ==

**Automatic installation (recommended):**

1. In your WordPress dashboard go to Plugins > Add New
2. Search for "TAFI Pay"
3. Click "Install Now" and then "Activate"

**Manual installation:**

1. Download the plugin ZIP file
2. Go to Plugins > Add New > Upload Plugin
3. Upload the ZIP and activate the plugin

**Configuration:**

1. Go to WooCommerce > Settings > Payments
2. Click on "TAFI" to configure it
3. Enter your API Key and Merchant ID (obtained from the TAFI merchant portal)
4. Copy the displayed Webhook URL and register it in your TAFI panel
5. Choose the environment (Sandbox for testing, Production for live sales)
6. Save changes

== Frequently Asked Questions ==

= Do I need a TAFI account to use this plugin? =
Yes. You need to register as a merchant at the TAFI merchant portal to obtain your API Key and Merchant ID.

= Does the plugin work outside Panama? =
No. TAFI operates exclusively in Panama. The payment method only appears for customers with a Panamanian billing address (PA).

= What amounts does the sandbox accept? =
The sandbox environment accepts transactions between USD 20.00 and USD 300.00.

= How do I configure the webhook? =
After activating the plugin, go to WooCommerce > Settings > Payments > TAFI. You will find your webhook URL in this format:
`https://your-store.com/wc-api/tafi_webhook/`
Copy it and register it in your TAFI panel.

= Where can I see transaction logs? =
Enable "Debug log" in the plugin settings. Logs are available under WooCommerce > Status > Logs > tafi-pagalo-relax.

= Is the plugin HPOS compatible? =
Yes. The plugin is fully compatible with High-Performance Order Storage (Custom Order Tables).

== Changelog ==

= 1.1.0 =
* Thank-you confirmation block now renders above the order summary so the customer sees the WhatsApp flow first
* New modal pop-up that announces the final state (approved, rejected, expired) on top of the page
* Fixed reconciliation bug: status checks now mark the order as paid as soon as the customer signs in WhatsApp (estadoCredito "Aceptado" with creditoFirmado true), matching the webhook behaviour
* Added a "Consultar estado en TAFI" button in the order admin screen so merchants can manually trigger an API check when the customer's tab closed before polling resolved
* Manual status-check action is now available on any TAFI order, not only those still pending
* Background safety-net: when an admin loads the dashboard, the plugin sweeps TAFI orders stuck in "pending" for 5+ minutes and reconciles them against the TAFI API. Throttled to one sweep every two minutes. Runs independently of wp-cron so it works even on sites where scheduled tasks are unreliable.

= 1.0.0 =
* Initial release
* Full integration with the TAFI API
* Webhook confirmation support
* HPOS compatibility
* Settings panel
* Debug logging

== Third-Party Services ==

This plugin connects to the **TAFI API**, a service provided by TAFI Tech, to process Buy Now, Pay Later (BNPL) payments.

When a customer selects TAFI as their payment method at checkout, the following data is sent to the TAFI API:

* Merchant ID (idComercio)
* Customer phone number (celular)
* Order total amount (valor)
* Order description (descripcion)
* Branch name (sucursal)
* Salesperson name (vendedor)
* Transaction ID (idTransaccion)

TAFI sends payment confirmation notifications back to your store via webhook when the customer accepts or rejects the payment in WhatsApp. The webhook includes: idTransaccion, numeroAutorizacion, valor, creditoFirmado and descripcionError.

**Service endpoints:**

* Production: `https://api.fintafi.com`
* Sandbox: `https://api.tafitech.io/dev`

**Links:**

* TAFI website: [https://tafi.com.pa](https://tafi.com.pa)
* Privacy policy: [https://tafi.com.pa/politica-de-privacidad](https://tafi.com.pa/politica-de-privacidad)

Please review TAFI's privacy policy before using this plugin.

== Upgrade Notice ==

= 1.1.0 =
Improves the order confirmation page, fixes a reconciliation bug where orders signed in WhatsApp were not marked as paid immediately, and adds a manual status-check button to the order admin screen.

= 1.0.0 =
First stable release.
