Activepieces integration for Safaricom M-Pesa Daraja APIs
# M-Pesa for Activepieces
An Activepieces piece for integrating Safaricom Daraja payment APIs into workflows.
## Supported APIs
- M-Pesa Express (STK Push)
- Customer to Business (C2B)
- Business to Customer (B2C)
- Business to Business (B2B)
## Requirements
- Activepieces 0.86.0 or later
- A Safaricom Daraja application
- Daraja Consumer Key and Consumer Secret
- An M-Pesa Online Passkey for STK Push
- A Security Credential for B2C and B2B
- A publicly reachable HTTPS `AP_FRONTEND_URL` for callbacks
## Development
Install dependencies:
```bash
npm install
```
Run the checks:
```bash
npm run typecheck
npm test
```
Start the local Activepieces environment:
```bash
cp .env.example .env
docker compose -f docker-compose.local.yml up -d
```
Open
localhost. For callback testing, set `AP_FRONTEND_URL` in `.env` to a public HTTPS address before starting Activepieces.
## Building
From an Activepieces monorepo checkout, run:
```bash
turbo run build --filter=@activepieces/piece-mpesa
```
## Callback behavior
M-Pesa Express, B2C, and B2B use Activepieces webhook waitpoints. The piece generates the callback URL automatically, submits it to Daraja, pauses the flow, and resumes it when the callback arrives.
C2B callback URLs are registered when its trigger is enabled.
Payment rejection, cancellation, or timeout is returned as a completed business result with `successful: false`. Use `resultCode` and `resultDescription` to handle that result in later flow steps.
## Security
Do not commit Consumer Secrets, passkeys, Security Credentials, authorization headers, or `.env` files. B2C and B2B expect the encrypted Daraja Security Credential, not the plain initiator password.