Skip to content

Payment lifecycle event hooks in Mppx.create() #329

@starc007

Description

@starc007

Feature Request

Add an event/hook system to Mppx.create() so payment events can be handled centrally instead of wrapping each route handler manually.

Problem

Right now there's no centralized way to track payments across routes. If you want analytics, logging, or alerting, you have to manually add tracking code inside every route handler:

app.get('/api/data', mppx.charge({ amount: '0.01' }), async (c) => {
  await db.insert({ event: 'payment', amount: '0.01', ... }) // manual per route
  return c.json({ data: '...' })
})

This doesn't scale for services with many endpoints, and proxy operators (mppx/proxy) have zero payment visibility.

Suggested API

An on option in Mppx.create():

const mppx = Mppx.create({
  methods: [tempo({ ... })],
  on: {
    'charge.received': (receipt, request) => { /* analytics, logging */ },
    'charge.failed': (error, challenge) => { /* alerting */ },
    'session.opened': (session) => { /* monitoring */ },
    'session.settled': (session, receipt) => { /* reconciliation */ },
    'session.closed': (session, refund) => { /* cleanup */ },
  },
})

Use Cases

  • Analytics — track revenue per endpoint, per method, over time
  • Monitoring — alert on failed payments, unusual patterns
  • Reconciliation — match on-chain settlements to business events
  • Proxy operators — centralized payment visibility across multiple upstream services

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions