=== Frebix Hubtel Payments for WooCommerce ===
Contributors: frebix
Tags: woocommerce, hubtel, payment gateway, mobile money, ghana
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.2.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Take mobile money, card, wallet and GhQR payments in Ghana through your Hubtel merchant account.

== Description ==

Frebix Hubtel Payments is for WooCommerce stores in Ghana that already have a
Hubtel merchant account and want their online sales to land there. If you do not
use Hubtel yet, other Ghana gateways (for example Paystack or Flutterwave) also take
mobile money and cards and offer a test mode.

Shoppers pay without leaving your shop. After "Place order" they stay on your own
pay page, where either:

* Hubtel's secure payment window opens right there (mobile money from MTN, Telecel
  and AirtelTigo, bank cards, Hubtel and G-Money wallets, or GhQR), or
* a mobile money prompt goes straight to their phone and they approve it with their PIN.
  This needs Hubtel to switch on Direct Receive Money for your account; until then the
  window is used.

Either way the order is only marked paid after the plugin checks with Hubtel itself.

**Features:**

* Payment inside your shop: no trip to Hubtel's website
* Phone prompts with the network recognised from the number, "Send it again" and "Use another number"
* Card details and PINs go to Hubtel, never to your site
* Works with the Cart and Checkout blocks and with the classic checkout
* Every payment is confirmed with Hubtel's Status Check API before an order is marked paid, with the amount and currency checked
* The thank-you page confirms the payment if the customer is back before Hubtel's callback
* Hourly check of recent unpaid orders, in case a callback is missed
* Full refunds through the Hubtel Refund API (within 45 days of payment)
* "Test connection" button that checks your API keys and whether Hubtel lets this website check payments
* Settings and a list of recent Hubtel payments under Frebix → Hubtel Payments
* WP-CLI commands for manual checks
* HPOS compatible

**Not supported:**

* Partial refunds through Hubtel. Hubtel's Refund API only refunds a whole order; refund part of an order manually instead.
* Subscriptions or saved payment methods. Hubtel's hosted checkout asks the customer to approve every payment.
* Currencies other than Ghana cedis (GHS). The payment method is hidden when the store or order currency is not GHS.

**Requirements:**

* WooCommerce 6.0 or later
* A Hubtel merchant account (API ID, API key, collection account number)
* Your website allowed by Hubtel for the Status Check and Refund APIs (your Hubtel account manager sets this up)

== External services ==

This plugin connects to Hubtel, a payments company in Ghana, to take payments and
refunds. It cannot work without these services. Nothing is sent until you enter
your Hubtel API details and a customer chooses Hubtel at checkout (or you use the
tools described below).

* **Hubtel Online Checkout** (`payproxyapi.hubtel.com`): called when a customer places an order with Hubtel. Sent: order amount, a short description with the order number, the customer's name, phone number and email address, an order reference, and the addresses Hubtel returns the customer and its callback to.
* **Hubtel Transaction Status** (`api-txnstatus.hubtel.com`): called after Hubtel's payment callback, when a customer lands on the thank-you page, by the hourly check of unpaid orders, by the "Check payment status" button and WP-CLI, to confirm refunds, and by the "Test connection" button. Sent: your collection account number and the order's payment reference.
* **Hubtel Refund API** (`refund-api.hubtel.com`): called when you refund an order to Hubtel from WooCommerce. Sent: your collection account number, Hubtel's order ID and the address for Hubtel's refund callback.

All three use your Hubtel API ID and API key. Hubtel's terms of use and privacy policy: https://explore.hubtel.com/legal/

* **ipify** (`api.ipify.org`): only when you press "Test connection" and Hubtel refuses the check, to show this server's IP address in case Hubtel asks for it. No store or customer data is sent: no cookies, no site address, a generic user agent. The answer is kept for an hour. ipify's terms and privacy: https://www.ipify.org (turn it off with the `frebix_hubtel_ip_echo_url` filter returning an empty string).

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/`, or install it from Plugins → Add New.
2. Activate it. WooCommerce must be active.
3. Go to WooCommerce → Settings → Payments → Frebix Hubtel Payments.
4. Enter your Hubtel API ID, API key and collection account number.
5. Press "Test connection". If it says Hubtel has not allowed this website yet, ask your Hubtel account manager to allow your domain (and the IP address it shows, if they ask).
6. Enable the payment method and save.

== Frequently Asked Questions ==

= Does this plugin handle card data? =

No. Customers enter their payment details on Hubtel's page. Your site never sees
card data.

= Why is a Status Check needed if Hubtel sends a callback? =

Hubtel does not sign its callbacks. To stop anyone faking one, the plugin asks
Hubtel's Status Check API about every payment before it marks an order as paid,
and checks the amount and currency.

= Is there a sandbox? =

No. All Hubtel endpoints are live. Use "Test connection" to check your settings
without paying, then test with a small amount (for example GHS 1).

= A customer paid but the order is still pending =

The order is confirmed when Hubtel's callback arrives, when the customer reloads
the thank-you page, or by the hourly check. If none of these can reach Hubtel, the
website is probably not allowed by Hubtel yet: press "Test connection" in the settings. Until it is, orders Hubtel reports as paid are put on hold for you to check in the Hubtel dashboard.

= Can I make a partial refund? =

Not through Hubtel: its Refund API refunds the whole order. Use "Refund manually"
in WooCommerce and pay the customer back outside Hubtel.

= Why do refunds fail with "not eligible"? =

Hubtel refunds are limited to 45 days after payment. For older refunds,
email business@hubtel.com.

== Changelog ==

= 1.2.4 =
* The pay button uses your shop’s colour from Your look (Appearance → Your look, shared by every Frebix plugin); until you set one, it follows your theme. The pay box keeps your theme’s fonts.




= 1.2.3 =
* New Frebix logo in the footer, signature and WordPress menu icon.

= 1.2.2 =
* The Frebix page in your dashboard is now a home for your plugins: what needs you, which plugins have updates, and each plugin's state. It also tells you when Hubtel is switched on but its keys are missing.

= 1.2.1 =
* Privacy: after paying, people go to the return page other plugins set (someone paying with Pay for Me no longer lands on the customer's order page).

= 1.2.0 =
* New: shoppers pay without leaving the checkout. After Place order, Hubtel's payment window (or the phone prompt) opens in a popup over the checkout; on phones it slides up from the bottom. Closing it keeps the order, with a Pay now button. If the popup can't open, shoppers get the shop's own pay page instead. Turn the popup off with the frebix_hubtel_popup filter.
* New: "A prompt on their phone": a mobile money prompt sent straight to the shopper's phone, with the network recognised from the number. Needs Hubtel to switch on Direct Receive Money; until then the window is used.
* New: settings in the Frebix look under Frebix → Hubtel Payments, with clearer connection test results and a list of recent Hubtel payments.
* Changed: the payment method is called "Mobile money or card" and shows the ways to pay. Shops that changed the name keep theirs.
* New: when Hubtel reports a payment but this website is not yet allowed to confirm it, the order goes on hold (not left waiting) and you are emailed to check it in the Hubtel dashboard.
* Changed: payment addresses work on sites that block /wp-json/, and setup talks about allowing your website rather than IP whitelists.

= 1.1.0 =
* Fixed: refunds are full refunds only (a partial refund could refund the whole order), confirmed by Hubtel before they count as done, and never requested twice.
* Fixed: the hourly check of missed payments is now scheduled, looks at the last 72 hours newest first, and recovers orders wrongly marked failed.
* Fixed: a paid order is never marked failed because Hubtel's status was a little behind.
* Fixed: payments on cancelled orders, short payments and wrong currencies put the order on hold and alert you.
* Fixed: a customer who retries payment and finishes the first Hubtel page is still matched.
* Fixed: refund callbacks are authenticated.
* New: Cart and Checkout block support.
* New: the thank-you page confirms the payment and tells the customer when it is still being confirmed.
* New: "Test connection" button in the settings.
* New: a neutral payment icon at checkout.
* Changed: the payment method is hidden when the currency is not GHS.
* Changed: logs no longer contain customer names, phone numbers, email addresses, order keys or callback tokens.
* Changed: phone numbers written without the leading 0, or with +233 / 00233, are sent to Hubtel correctly.
* Changed: staff who can edit orders can use "Check payment status".

= 1.0.0 =
* Initial release.
