Use this quickstart to create a minimal Node.js project, send a sandbox M-Pesa Express payment, and check the payment status.Documentation Index
Fetch the complete documentation index at: https://docs.moflay.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- A Moflay account and organization
- A sandbox API key with
express.payandtransactions.read - Node.js 18 or later
Sandbox test values
For the default sandbox path, you do not need to set up Daraja credentials before your first payment. Moflay uses default sandbox test credentials unless you add your own sandbox credentials. Use these values for the first test:| Value | Use |
|---|---|
254712345678 | Default sandbox test phone number |
amount: 1000 | KES 10.00 in minor currency units |
mof_test_... | Sandbox API key |
pending; check the final status by polling during development or by using webhooks in production.
Send your first payment
Check the dashboard
- Open the Moflay dashboard.
- Go to the Transactions page.
- Confirm that the payment appears in the sandbox environment.
pending after Moflay sends the STK push request. A final status such as completed, failed, or canceled appears after Moflay receives the M-Pesa result.
Verify the result
Your setup is working if:- The SDK call returns a
paymentIdandtransactionId. - The payment uses the
sandboxenvironment. - The transaction appears in the dashboard.
- The status check returns the same payment or transaction.
Production status handling
Polling payment status is useful during development. In production, configure Moflay webhooks so your backend receives signed payment events such aspayment.completed, payment.failed, and payment.canceled.
Troubleshooting
- The API returns
missing_api_key: Make sureMOFLAY_API_KEYis exported in the same terminal where you runnode index.mjs. - The API returns
invalid_api_key: Check that the key is active, copied correctly, and starts withmof_test_for sandbox. - Payment creation returns
invalid_access: Add theexpress.paypermission to the key or create a new sandbox key with that permission. - Status polling returns
invalid_access: Add thetransactions.readpermission to the key or create a new sandbox key with that permission. - The payment does not appear in the dashboard: Confirm you are viewing the sandbox environment.