M-Pesa & Mobile Money Payment Integration User Guide
lynx-anchor
lynx-anchor
lynx-anchor
This user guide is written for store owners, retail cashiers, and restaurant managers in Kenya and East Africa. Learn how to configure Safaricom M-Pesa STK Push (Express), collect instant cashless customer payments at checkout, and reconcile Till and Paybill transactions without coding!
Table of Contents
- Overview & How M-Pesa STK Push Works
- Configuring M-Pesa in Software Settings
- Testing M-Pesa STK Push Connectivity
- Collecting M-Pesa Payments at POS Counter
- M-Pesa Webhook Callbacks & Instant Reconciliation
- Troubleshooting & Frequently Asked Questions
1. Overview & How M-Pesa STK Push Works
**M-Pesa Express (STK Push)**allows cashiers to trigger a secure payment prompt directly on the customer's mobile phone:
sequenceDiagram
autonumber
actor Customer as Customer (Shopper)
actor Cashier as Cashier (POS Terminal)
participant POS as Famalth Lynx POS
participant Safaricom as Safaricom Daraja M-Pesa Gateway
Cashier->>POS: Scans items & clicks Pay with M-Pesa
Cashier->>POS: Enters customer phone (e.g. 0712345678)
POS->>Safaricom: Triggers STK Push Request
Safaricom->>Customer: Mobile Prompt: "Pay KSh 1,250 to Store? Enter PIN:"
Customer->>Customer: Enters secret 4-digit M-Pesa PIN
Safaricom->>POS: Instant Confirmation Webhook (Receipt: QKH48201Z)
POS->>POS: Bill settles automatically & prints thermal receipt!
2. Configuring M-Pesa in Software Settings
To setup your Safaricom Daraja credentials:
- Open the left sidebar and navigate to Settings > M-Pesa Configuration.
- Toggle Enable M-Pesa Integrationto
ON. - Choose Environment:
- Sandbox: For testing with simulated money before going live.
- Production (Live): For processing real customer transactions.
- Select Account Type:
- Buy Goods / Till Number: Standard retail counter Till (e.g., Till
123456). - Paybill Number: Commercial Paybill with custom Business Shortcode and Account Number (e.g., Paybill
400200).
- Buy Goods / Till Number: Standard retail counter Till (e.g., Till
Daraja API Credentials (from Safaricom Developer Portal)
- Shortcode / Till: Your 5-to-7 digit M-Pesa Store Number.
- Consumer Key: 32-character API key from Daraja portal.
- Consumer Secret: 32-character secret key from Daraja portal.
- Online Passkey: LIPA NA M-PESA passkey provided by Safaricom.
- Click Save Configuration.
3. Testing M-Pesa STK Push Connectivity
Before billing real customers, perform a simulated test:
- In the M-Pesa Configurationscreen, scroll to the Test STK Pushcard.
- Enter your personal phone number (e.g.,
254712345678or0712345678). - Set Amount to
1.00KSh. - Click **Send Test STK Push **.
- Check your mobile phone. An M-Pesa PIN prompt should appear on your screen within 2 seconds.
- The test log will show
[SUCCESS] MerchantRequestID received.
4. Collecting M-Pesa Payments at POS Counter
- On the Enterprise POSor Restaurant Billingscreen, scan items into the cart.
- Click Pay / Settle (F12).
- Select M-Pesaas the payment mode.
- Enter or confirm the customer's phone number.
- Click Request STK Push.
- Inform the customer: "Please check your phone and enter your M-Pesa PIN."
- As soon as the customer enters their PIN:
- The POS screen flashes green: "Payment Received!"
- The unique M-Pesa Transaction Code (e.g.,
RKH9283KLS) is saved on the invoice. - The cash drawer stays closed, preventing cash shortages.
- The receipt prints with full M-Pesa reference details!
5. M-Pesa Webhook Callbacks & Instant Reconciliation
- Every transaction is verified cryptographically via the webhook endpoint
/api/mpesa/callback. - If the customer cancels the prompt on their phone or has insufficient funds, the POS screen displays an immediate alert: "Transaction Cancelled by Customer" or "Insufficient Balance", allowing the cashier to choose an alternate payment method.
6. Troubleshooting & Frequently Asked Questions
| Problem | Cause | Solution |
|---|---|---|
| "Phone number format invalid" | Entered number with spaces or symbols | Enter 10 digits starting with 07... / 01... or international 254.... The software auto-normalizes the format. |
| "STK Push timed out" | Customer didn't enter PIN in 30 seconds | Click Retry STK Pushon POS or collect via Cash/Card. |
| "Invalid Credentials / 401 Unauthorized" | Consumer Key or Secret has a typo | Re-copy credentials from the Safaricom Daraja portal and save settings. |
Speed up checkout lines and eliminate cash handling errors with M-Pesa Express!