=== Doxtudio Duka: M-PESA Payments & Selling ===
Contributors: doxtudio
Tags: mpesa, m-pesa, kenya, payments, woocommerce
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Lipa na M-PESA (and cards through Paystack) for WordPress and WooCommerce: pay buttons on any page, products, downloads and donations, with instant alerts.

== Description ==

Doxtudio Duka lets Kenyan businesses, churches, schools, writers and event organisers take M-PESA payments on their WordPress site, with or without WooCommerce. Bring your own approved Daraja (Safaricom) app: money goes straight to your paybill or till.

= Payments that are never missed =

* The buyer enters their number and gets the M-PESA prompt (STK push) on their phone.
* A payment is confirmed by whichever arrives first: Safaricom's callback, the buyer's page asking Safaricom for the status, or a background check every 5 minutes. A late or lost callback never leaves a paid order unconfirmed.
* No prompt (phone off, SIM toolkit busy)? The buyer sees your paybill or till with the order number as the account, pays by hand, and types the M-PESA code.
* Amounts are checked, a payment can only count once, and every step is in the order's history.

= Cards too (optional) =

* Add your Paystack secret key and buyers can choose "Card (Visa, Mastercard)" next to M-PESA, on Pay buttons and in WooCommerce.
* The buyer pays on Paystack's secure page; card numbers never touch your site. The card's Pay button stays off until the buyer types an email (Paystack sends the receipt there).
* An order is marked paid only after Duka checks with Paystack itself that the payment succeeded, in KES, for the full amount: when the buyer comes back, on Paystack's signed webhook, or in the 5-minute background check.

= Sell anything =

* **Physical goods** with stock, quantities, delivery or pickup and a delivery fee.
* **Downloads** (PDFs, e-books, music, software): private files, personal links that work a few times only.
* **Donations, harambees and fees**: the payer chooses the amount, with an optional progress bar to a target.
* **Any amount** with `[duka_pay amount="1500" label="School fees"]`.
* **WooCommerce**: M-PESA as a payment method in the classic and block checkout; orders are completed automatically.

= Sell anywhere =

* Every product has a **Buy link**: put it on a Wix button, your Instagram or TikTok bio, WhatsApp, SMS or a poster (Pro adds a printable QR code).
* An **embed box** for Wix (Embed HTML), Squarespace, Webflow and Google Sites: buyers pay inside the box.
* Pro: one line of script puts your **whole shop with the cart** on any other website (Shopify, Squarespace, Webflow, Blogger, plain HTML). Orders, stock and payments stay in Duka.

= Built for Kenya =

* "Order on WhatsApp" buttons next to every Pay button, with the order already written.
* Instant email to the buyer (receipt with your KRA PIN) and to you (with a one-tap WhatsApp link to the buyer).
* A dashboard with today's, this week's and this month's sales, orders to check, CSV export.
* Test connection: your Daraja keys are checked with Safaricom and problems explained in plain words.

= Doxtudio Duka Pro =

[Doxtudio Duka Pro](https://doxtudio.com/plugins/duka/) adds event tickets with QR check-in at the door, locked pages and memberships, automatic matching of payments made straight to your paybill or till, payment links and invoices, a customers list, discount codes, SMS alerts (Africa's Talking, Advanta), a daily sales summary, low-stock alerts and staff accounts.

= What you need =

* An approved Daraja app (developer.safaricom.co.ke) for your paybill or till: consumer key and secret, and the Lipa na M-PESA Online passkey. The sandbox works for testing.
* HTTPS on your site, so Safaricom can send confirmations (payments are still confirmed by status checks without it).

== Installation ==

1. Install and activate the plugin.
2. Go to Duka → Settings, enter your shortcode, passkey, consumer key and secret, and click "Save and test connection".
3. Add a product under Duka → Products.
4. Put its Pay button on any page with the "Duka: Pay with M-PESA" block or `[duka_buy id="…"]`. For a list of products: `[duka_products]`.
5. WooCommerce shops: WooCommerce → Settings → Payments → enable M-PESA (and "Card via Paystack" if you added a Paystack key).
6. Cards (optional): paste your Paystack secret key under Duka → Settings → Card payments, and copy the webhook address shown there into Paystack → Settings → API Keys & Webhooks.

== Frequently Asked Questions ==

= Is my money held by Doxtudio? =

No. Payments go from the buyer straight to your own paybill or till. Doxtudio never sees or holds your money or your keys.

= Does it work with a till (Buy Goods)? =

Yes. Choose "A Till" in the settings and enter your store (head office) number as the shortcode and your till number.

= What happens if the buyer's phone is off? =

They can press "Send the prompt again", or pay by hand to your paybill or till and type the M-PESA code. You're asked to confirm hand payments (Pro matches them by itself).

= Which external services does it use? =

Safaricom's Daraja API (api.safaricom.co.ke, or sandbox.safaricom.co.ke for testing): the buyer's phone number, the amount and the order number are sent to Safaricom to request and confirm payments. See Safaricom's terms and privacy policy at https://www.safaricom.co.ke/.

Paystack (api.paystack.co), only if you add a Paystack key: when a buyer chooses to pay by card, their email, the amount and the order number are sent to Paystack to start and confirm the payment, and the buyer enters their card on Paystack's page. Paystack's terms: https://paystack.com/terms, privacy policy: https://paystack.com/privacy.

"Order on WhatsApp" links open wa.me in the buyer's browser only when they click them. No data is sent to Doxtudio.

== Changelog ==

= 1.2.0 =
* A shopping cart: Add to cart on every product, a cart button that follows the buyer, one payment for everything.
* Product options (sizes, colours, packages) with their own prices.
* Product categories, with filter buttons and search on the shop.
* Delivery areas with their own fees, and free delivery above an amount.
* A new payment window: a sheet from the bottom on phones, live totals, clearer M-PESA and card choice.
* Duka Anywhere: Buy links, embed boxes for Wix and other site builders, and (Pro) the shop on any website.
* Testing on localhost: M-PESA prompts now work (Safaricom can't reach localhost, so payments are confirmed by status checks).
* An M-PESA code typed by a buyer is refused at once if it was already used for another order.

= 1.1.0 =
* Card payments (Visa, Mastercard) through Paystack, on Pay buttons, payment links and in WooCommerce (classic and block checkout). Optional: add your Paystack key.
* The card's Pay button stays off until the buyer types an email.
* The payment window no longer clears what the buyer is typing while it waits.

= 1.0.0 =
* First release.

== Third-party resources ==

* M-PESA is a trademark of Safaricom PLC; this plugin is not made or endorsed by Safaricom.
