360 Secure SkillHub
360 安全技能中心

M-Pesa Daraja

面向 Safaricom M-Pesa Daraja 的咨询类参考技能,明确不调用真实支付 API。围绕 STK Push、C2B、B2C 与对账流程,给出架构边界、授权值与会话缓存、回调幂等与脱敏日志建议、测试用例和上线检查清单,并附带端点、示例与维护参考文档。

nevilpaulo
nevilpaulo
热度 44.82
最近更新 2026-05-25 16:13:01
分类:开发依赖:纯提示词应用场景:代码生成 / 代码审查 / API 集成 / 调试排错 ...

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add mpesa-daraja
Metadata
name
mpesa-daraja
description
Advisory reference for Safaricom M-Pesa Daraja integration planning, reviews, sandbox testing, callbacks, reconciliation, and production-readiness. It provides implementation guidance only and does not require external account access to use.
version
1.2.2

M-Pesa Daraja

This is an advisory/reference skill. It does not call Safaricom APIs, initiate payments, or require external account access to install or use.

Operating Rules

  • Treat this as payment-integration guidance, not permission to move money.
  • Default to Daraja sandbox endpoints and placeholder configuration unless the user explicitly asks for production guidance.
  • Never store sensitive Daraja values, callback payloads with phone numbers, or transaction IDs in committed files.
  • Ask before calling any live/production endpoint or sending any request that could trigger a payment prompt, payout, reversal, or customer-facing callback.
  • Prefer environment variables and protected deployment settings over `.env` files in shared repos. If `.env.example` is needed, use placeholder values only.
  • Make callbacks idempotent: verify request shape, persist raw event safely, deduplicate by CheckoutRequestID/ConversationID/TransactionID, then process business state transitions.

Workflow

  1. Identify the payment flow:
    • STK Push / Lipa na M-Pesa Online for customer-initiated checkout.
    • C2B for paybill/till customer payments with validation and confirmation callbacks.
    • B2C for business payouts to customers or agents.
    • Transaction Status / Reversal for reconciliation and recovery.
  2. Confirm runtime context: language/framework, sandbox vs production, callback URL availability, persistence layer, and compliance constraints.
  3. Design the integration around these boundaries:
    • Daraja session setup and caching
    • request authorization value generation
    • outbound Daraja client
    • callback receiver
    • idempotency/reconciliation
    • observability without leaking personal or payment data
  4. Use `references/examples.md` when the user asks for sample OpenClaw prompts, implementation examples, or architecture snippets.
  5. Use `references/test-cases.md` when the user asks for QA scenarios, unit tests, integration tests, sandbox tests, or production-readiness checks.
  6. Use `references/stk-push.md` for STK Push/Lipa na M-Pesa Online implementation details.
  7. Use `references/api-endpoints.md` when the user needs current Daraja endpoint names, versions, or flow coverage.
  8. Use `references/production-readiness.md` before production-readiness reviews, client handoff, or launch checklists.
  9. Use `references/maintenance.md` before updating or publishing this skill. Always check official Safaricom/Daraja sources for API changes, update the version, and run validation before pushing to ClawHub.

Implementation Guidance

  • Keep Daraja client code small and injectable so app tests can mock HTTP calls.
  • Follow Safaricom's current STK authorization formula with timestamp format `YYYYMMDDHHmmss`.
  • Cache Daraja authorization sessions until shortly before expiry.
  • Expose public HTTPS callback URLs in sandbox using a stable tunnel or deployed test environment; avoid local-only callback URLs.
  • Return fast from callbacks after durable persistence; do heavier fulfillment asynchronously when possible.
  • Log correlation IDs, response codes, and internal order IDs. Mask phone numbers, names, and all sensitive Daraja values.
  • Model payment state explicitly, for example: `pending`, `prompt_sent`, `paid`, `failed`, `cancelled`, `expired`, `reversed`, `manual_review`.

Common OpenClaw Requests

  • "Use $mpesa-daraja to add STK Push checkout to this Django app."
  • "Use $mpesa-daraja to write sandbox test cases for our M-Pesa checkout."
  • "Use $mpesa-daraja to review this Daraja callback handler for idempotency and sensitive-data leakage."
  • "Use $mpesa-daraja to create an OpenClaw automation that drafts M-Pesa reconciliation reports without touching production APIs."

Deliverables To Prefer

  • For implementation: client module, callback route, typed request/response models, masked logging, tests, and `.env.example`.
  • For review: findings ordered by payment risk, security risk, idempotency/reconciliation risk, then code quality.
  • For planning: flow diagram in text, endpoint list, configuration list, callback contract, test plan, and production checklist.
  • For troubleshooting: exact failing step, expected Daraja response, likely causes, and the smallest safe verification step.