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

@todaqmicro/payment-node

v0.4.0

Published

TODAQ Micro's Node.js SDK

Readme

Payment Node.JS

Server-side Node.js SDK for TODAQ Micro micropayments.

Installation

npm install @todaq/payment-node

Usage

Initialize the SDK

import { Micro } from '@todaq/payment-node';

const micro = new Micro(
  'your-client-id',
  'your-client-secret',
  { apiVersion: 'v2' }
);

Create a Commodity

const commodity = await micro.Commodity.createCommodity(
  accessToken,
  twinId,
  {
    cost: 100,
    descriptor: 'Premium Article Access',
    dq: 'usd'
  }
);

console.log('Commodity hash:', commodity.hash);

Validate a Payment

const isValid = await micro.Payment.validPayment(
  accessToken,
  commodityHash,
  nonce,
  timestamp
);

if (isValid) {
  console.log('Payment is valid!');
}

Session-Based Payments (Paywall)

The Paywall feature allows platforms to make payments on behalf of users using session tokens. This is useful for implementing paywalls, subscriptions, or any scenario where you want to process payments without requiring users to interact with the payment UI each time.

1. Create a Session

First, create a session for the authenticated user:

// After user has authenticated and you have their access token
const { session } = await micro.Session.createSession(userAccessToken);

// Store this session token securely (e.g., in a cookie or session storage)
// The session expires after 1 hour

2. Make Payments Using the Session

Once you have a session token, you can make payments on behalf of the user:

try {
  const result = await micro.Paywall.createPayment(
    sessionToken,
    'payment-type-hash',  // The commodity hash
    100,                  // Amount
    'https://destination.example.com/callback'  // Destination URL
  );

  console.log('Payment successful!', result);
} catch (error) {
  console.error('Payment failed:', error);
}

Example: Paywall Middleware

import express from 'express';
import { Micro } from '@todaq/payment-node';

const app = express();
const micro = new Micro(clientId, clientSecret, { apiVersion: 'v2' });

// Middleware to check for valid session
async function requirePayment(req, res, next) {
  const sessionToken = req.cookies.session_id;
  
  if (!sessionToken) {
    return res.redirect('/auth');
  }

  try {
    // Attempt to make payment for accessing this resource
    await micro.Paywall.createPayment(
      sessionToken,
      req.paywallHash,  // Set this based on the resource
      req.paywallAmount,
      req.originalUrl
    );
    
    next();
  } catch (error) {
    res.status(402).json({ error: 'Payment required' });
  }
}

// Protected route
app.get('/premium-content', requirePayment, (req, res) => {
  res.json({ content: 'This is premium content!' });
});

Personas

// Create a persona
const persona = await micro.Persona.createPersona(
  accessToken,
  twinId,
  {
    descriptor: 'Digital Collectible',
    // ... other persona properties
  }
);

API Reference

Commodity

  • createCommodity(accessToken, twinId, { cost, descriptor, dq }) - Create a new commodity

Payment

  • validPayment(accessToken, hash, nonce, timestamp) - Validate a payment transaction

Paywall

  • createPayment(session, paymentTypeHash, amount, destinationUrl) - Make a payment on behalf of a user using their session token

Session

  • createSession(accessToken) - Create a new session token for a user (expires in 1 hour)

Persona

  • createPersona(accessToken, twinId, personaData) - Create a new persona

Twin

  • Twin management utilities

Security Notes

  • Session Tokens: Session tokens expire after 1 hour. Store them securely and never expose them in client-side code.
  • Credentials: Never commit your client ID and secret to version control.
  • HTTPS Only: Always use HTTPS in production to protect session tokens in transit.

License

See LICENSE file.