M-Pesa icon

M-Pesa

Process and verify M-Pesa payments

Overview

This node integrates with the M-Pesa payment system to facilitate mobile money transactions. Specifically, it supports initiating STK Push payments, which prompt a customer’s phone to authorize a payment, and querying the status of existing transactions.

Common scenarios for this node include:

  • E-commerce platforms requesting customers to pay via M-Pesa by sending an STK Push prompt.
  • Businesses verifying the status of payments made through M-Pesa.
  • Automating payment collection and reconciliation workflows using M-Pesa's API.

For example, an online store can use the STK Push operation to charge a customer’s phone number a specified amount, triggering a payment prompt on their device. Later, the store can query the transaction status to confirm payment success.

Properties

Name Meaning
Phone Number Customer phone number in the format 254XXXXXXXXX to receive the STK Push payment prompt.
Amount The amount of money to charge the customer via M-Pesa.
Account Reference A reference string for the transaction, e.g., an invoice number like "INV001".
Callback URL URL where M-Pesa will send payment notification callbacks after the STK Push is processed.

Output

The node outputs JSON data containing the response from the M-Pesa API for each input item processed.

  • For STK Push operations, the output includes fields indicating whether the request was successful along with details returned by M-Pesa (e.g., CheckoutRequestID).
  • If the node encounters errors during processing, the output JSON will contain success: false and an error message describing the issue.

No binary data is produced by this node.

Dependencies

  • Requires an active M-Pesa API credential with necessary keys and secrets configured in n8n.
  • The node uses the M-Pesa OAuth token endpoint to authenticate requests.
  • Network access to either the M-Pesa production or sandbox API endpoints is required.
  • For transaction queries, additional credentials such as initiator name and password are needed.

Troubleshooting

  • Missing Credentials: The node requires valid M-Pesa API credentials including consumer key, secret, business shortcode, and passkey. For transaction queries, initiator name and password must also be set.
  • Invalid Access Token Errors: The node automatically refreshes expired tokens, but persistent authentication failures indicate incorrect credentials.
  • Incorrect Phone Number Format: Ensure phone numbers follow the Kenyan format starting with country code 254 and no leading zeros or plus signs.
  • Callback URL Issues: The callback URL must be publicly accessible and able to receive POST requests from M-Pesa.
  • API Errors: Errors returned by M-Pesa (e.g., insufficient funds, invalid parameters) are surfaced in the node output. Review error messages for corrective action.

Links and References

Discussion