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

@paymint/node

v0.1.2-alpha

Published

Node.js HTTP client for Paymint API

Readme

@paymint/node

Low-level HTTP client for the Paymint API.

Installation

npm install @paymint/node

Note: For most use cases, use @paymint/server or @paymint/nextjs instead. This package provides the underlying HTTP client.

Quick Start

import { PaymintClient } from '@paymint/node';

const client = new PaymintClient({
  apiKey: 'paymint_test_xxx', // or paymint_live_xxx for production
});

// Get products
const products = await client.products.list();

// Initialize checkout
const init = await client.checkout.initialize({ email: '[email protected]' });

// Get subscriptions
const subscriptions = await client.subscriptions.list({ email: '[email protected]' });

// Cancel subscription
await client.subscriptions.cancel('[email protected]', 'sub_xxx', {
  effectiveFrom: 'next_billing_period',
});

Configuration

API Key Format

  • paymint_test_xxx - Sandbox/test environment
  • paymint_live_xxx - Production environment

The environment is automatically detected from your API key.

Client Options

const client = new PaymintClient({
  apiKey: 'paymint_test_xxx',     // Required
  baseUrl: 'https://api.paymint.dev', // Optional, defaults to api.paymint.dev
  timeout: 30000,                      // Optional, request timeout in ms
});

Resources

The client is organized into resources that map to API endpoints:

client.products

// List all products with prices
const products = await client.products.list();

// Product structure
interface Product {
  id: string;
  name: string;
  description: string | null;
  prices: Price[];
}

interface Price {
  id: string;
  name: string;
  description: string | null;
  unitPrice: {
    amount: string;
    currencyCode: string;
  };
  billingCycle: {
    interval: 'month' | 'year';
    frequency: number;
  };
  trialPeriod: {
    interval: 'day';
    frequency: number;
  } | null;
}

client.checkout

// Initialize checkout for a customer
const init = await client.checkout.initialize({
  email: '[email protected]',
});

// Returns
interface InitializeResponse {
  clientSideToken: string;      // Pass to Paddle.js
  paddleEnvironment: 'sandbox' | 'production';
  customerExists: boolean;
}

// Use with Paddle.js
Paddle.Initialize({
  token: init.clientSideToken,
  environment: init.paddleEnvironment,
});

client.subscriptions

// List subscriptions for a customer
const subscriptions = await client.subscriptions.list({
  email: '[email protected]',
});

// Cancel a subscription
await client.subscriptions.cancel('[email protected]', 'sub_xxx', {
  effectiveFrom: 'next_billing_period', // or 'immediately'
});

// Pause a subscription
await client.subscriptions.pause('[email protected]', 'sub_xxx', {
  effectiveFrom: 'next_billing_period',
  resumeAt: '2024-03-01T00:00:00Z', // Optional: auto-resume
});

// Resume a paused subscription
await client.subscriptions.resume('[email protected]', 'sub_xxx', {
  effectiveFrom: 'immediately',
});

// Activate a trialing subscription
await client.subscriptions.activate('[email protected]', 'sub_xxx');

Error Handling

All errors extend PaymintError:

import {
  PaymintClient,
  PaymintError,
  AuthenticationError,
  ValidationError,
  NotFoundError,
  RateLimitError,
  NetworkError,
} from '@paymint/node';

try {
  const products = await client.products.list();
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Invalid API key');
  } else if (error instanceof ValidationError) {
    console.error('Invalid request:', error.message);
  } else if (error instanceof NotFoundError) {
    console.error('Resource not found');
  } else if (error instanceof RateLimitError) {
    console.error('Rate limited. Retry after:', error.retryAfter);
  } else if (error instanceof NetworkError) {
    console.error('Network error:', error.message);
  } else if (error instanceof PaymintError) {
    console.error('Paymint error:', error.message, error.requestId);
  } else {
    console.error('Unknown error:', error);
  }
}

Error Types

| Error | Status | Description | |-------|--------|-------------| | AuthenticationError | 401 | Invalid API key | | ValidationError | 400 | Invalid request parameters | | NotFoundError | 404 | Resource not found | | RateLimitError | 429 | Too many requests | | NetworkError | - | Connection or timeout issues |

TypeScript Support

Full TypeScript types are included:

import type {
  Product,
  Price,
  Subscription,
  SubscriptionStatus,
  InitializeRequest,
  InitializeResponse,
  CancelSubscriptionOptions,
  PauseSubscriptionOptions,
  ResumeSubscriptionOptions,
} from '@paymint/node';

Complete Example

import { PaymintClient, PaymintError } from '@paymint/node';

async function billingExample() {
  const client = new PaymintClient({
    apiKey: process.env.PAYMINT_API_KEY!,
  });

  try {
    // Get available products
    const products = await client.products.list();
    console.log('Available products:', products.map(p => p.name));

    // Initialize checkout
    const init = await client.checkout.initialize({
      email: '[email protected]',
    });
    console.log('Checkout token:', init.clientSideToken);

    // Check existing subscriptions
    const subscriptions = await client.subscriptions.list({
      email: '[email protected]',
    });

    const activeSubscription = subscriptions.find(
      s => s.status === 'active' || s.status === 'trialing'
    );

    if (activeSubscription) {
      console.log('Active subscription:', activeSubscription.id);
      
      // Cancel at end of period
      await client.subscriptions.cancel(
        '[email protected]',
        activeSubscription.id,
        { effectiveFrom: 'next_billing_period' }
      );
      console.log('Subscription will cancel at end of period');
    }

  } catch (error) {
    if (error instanceof PaymintError) {
      console.error('Billing error:', error.message);
    } else {
      throw error;
    }
  }
}

Advanced Usage

Custom Base URL

For testing or self-hosted instances:

const client = new PaymintClient({
  apiKey: 'paymint_test_xxx',
  baseUrl: 'http://localhost:3002', // Override for local development
});

Environment-based Auto-Configuration:

By default, all SDKs connect to https://api.paymint.dev. To use a local API server during Paymint internal development:

PAYMINT_USE_LOCAL_API=true npm run dev

This will automatically use http://localhost:3002 instead of the production API.

Timeout Configuration

const client = new PaymintClient({
  apiKey: 'paymint_test_xxx',
  timeout: 10000, // 10 seconds
});

Request ID Tracking

All errors include a request ID for support:

try {
  await client.products.list();
} catch (error) {
  if (error instanceof PaymintError) {
    console.log('Request ID:', error.requestId);
    // Include this when contacting support
  }
}

License

MIT