npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mpp-card

v0.1.8

Published

TypeScript SDK for card payments in the Machine Payments Protocol

Downloads

1,915

Readme

mpp-card

TypeScript SDK for card payments in the Machine Payments Protocol. Gate any HTTP endpoint behind a Visa, Mastercard, Amex, or Discover payment — the server returns 402 Payment Required with a challenge, the client obtains an encrypted network token and retries, and the server charges the card and returns a receipt. Works with any payment processor.

Documentation

Full protocol specification at paymentauth.org/draft-card-charge-00.html.

Install

npm i mpp-card

Quick Start

Server

import { MppCard } from 'mpp-card/server'

const mpp = MppCard.create({
  acceptedNetworks: ['visa', 'mastercard'],
  merchantName: 'Demo',
  privateKey: process.env.PRIVATE_KEY,
  secretKey: process.env.MPP_SECRET_KEY,
  gateway: myServerEnabler, // Visa Acceptance, or custom
})

const charge = mpp.charge({ amount: '500', currency: 'usd' })

export async function handler(request: Request) {
  const result = await charge(request)
  if (result.status === 402) return result.challenge
  return result.withReceipt(Response.json({ data: '...' }))
}

Use generateKeyPair() from mpp-card/server to generate a key pair, or bring your own RSA-2048 PEM. When gateway is omitted and NODE_ENV is not "production", charges are mocked automatically.

Client

import { MppCard, vgsClientEnabler } from 'mpp-card/client'

MppCard.create({
  cardId: 'CRD...',
  enabler: vgsClientEnabler({ clientId: '...', clientSecret: '...' }),
})

// Global fetch now handles 402 automatically
const res = await fetch('https://api.merchant.com/data')

Omit enabler for a built-in dev mock.

Node.js HTTP

import * as http from 'node:http'

const listener = MppCard.toNodeListener(charge)

http.createServer(async (req, res) => {
  const result = await listener(req, res)
  if (result.status === 402) return
  res.writeHead(200, { 'Content-Type': 'application/json' })
  res.end(JSON.stringify({ data: '...' }))
}).listen(3000)

Custom Integrations

Payment Gateway (Server Enabler)

Connect any payment processor by implementing ServerEnabler:

import type { ServerEnabler } from 'mpp-card/server'

const custom: ServerEnabler = {
  async charge({ token, network, amount, currency, idempotencyKey, ...extra }) {
    // token.token.paymentToken — network token (DPAN)
    // token.dynamicData.dynamicDataValue — cryptogram
    // All credential payload fields pass through via ...extra
    return { reference: 'ch_xxx', status: 'success' }
  },
}

Credential Issuer (Client Enabler)

Connect any credential issuer by implementing ClientEnabler:

import type { ClientEnabler } from 'mpp-card/client'

const custom: ClientEnabler = {
  async getPaymentData({ cardId, challenge }) {
    // challenge.encryptionJwk — server's RSA public key
    return {
      encryptedPayload: '...',  // JWE (RSA-OAEP-256 + AES-256-GCM)
      network: 'visa',
      // Extra fields pass through to the credential and server enabler
    }
  },
}

Built-in enablers: vgsClientEnabler, visaAcceptanceClientEnabler, visaAcceptanceServerEnabler. See examples/ for usage.

Exports

// Server
import { MppCard, card, generateKeyPair, decryptToken } from 'mpp-card/server'
import type { ServerEnabler } from 'mpp-card/server'

// Client
import { MppCard, vgsClientEnabler, visaAcceptanceClientEnabler } from 'mpp-card/client'
import type { ClientEnabler } from 'mpp-card/client'

// Core
import { Challenge, Credential, Receipt, Errors } from 'mpp-card'

Protocol

Built on the "Payment" HTTP Authentication Scheme. See draft-mpp-card-charge-00 for the card charge intent specification.

License

See LICENSE for terms.