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

tinker-payments-node-sdk

v0.2.2

Published

Node.js SDK for Tinker Payments API

Readme

Tinker Payments Node SDK

Node.js SDK for the standardized Tinker Payments API (/v1) with automatic authentication, sandbox/production environment routing, payment initiate/query, subscriptions, and webhook verification.

The SDK is authored in TypeScript and published as compiled CommonJS JavaScript with generated type declarations. It works in both JavaScript and TypeScript projects.

Installation

npm install tinker-payments-node-sdk

JavaScript Usage

const { TinkerPayments } = require('tinker-payments-node-sdk');

const client = new TinkerPayments('pk_test_xxx', 'sk_test_xxx');

// Payment initiate
const payment = await client.transactions().initiate({
  amount: 1200,
  currency: 'KES',
  gateway: 'mpesa',
  merchantReference: 'ORDER-1001',
  returnUrl: 'https://merchant.example/callback',
  customerEmail: '[email protected]',
  customerPhone: '+254712345678',
  transactionDesc: 'Payment for order ORDER-1001'
});

// Payment query
const result = await client.transactions().query({
  reference: 'TP-REF-123',
  gateway: 'mpesa'
});

TypeScript Usage

import { TinkerPayments, type PaymentInitiateRequest } from 'tinker-payments-node-sdk';

const client = new TinkerPayments('pk_test_xxx', 'sk_test_xxx');

const request: PaymentInitiateRequest = {
  amount: 1200,
  currency: 'KES',
  gateway: 'mpesa',
  merchantReference: 'ORDER-1001',
  returnUrl: 'https://merchant.example/callback',
  customerEmail: '[email protected]',
  customerPhone: '+254712345678',
  transactionDesc: 'Payment for order ORDER-1001'
};

const payment = await client.transactions().initiate(request);

Error Handling

import { TinkerPayments, errors } from 'tinker-payments-node-sdk';

const client = new TinkerPayments('pk_test_xxx', 'sk_test_xxx');

try {
  await client.transactions().initiate({
    amount: 1200,
    currency: 'KES',
    gateway: 'mpesa',
    merchantReference: 'ORDER-1001',
    returnUrl: 'https://merchant.example/callback',
    customerPhone: '+254712345678',
    transactionDesc: 'Payment for order ORDER-1001'
  });
} catch (error) {
  if (error instanceof errors.TinkerError) {
    console.error(error.getError());
  }
}

Environment Resolution

  • Uses https://sandbox-api.tinkerpayments.com/v1/ when keys start with pk_test_ or sk_test_.
  • Uses https://api.tinkerpayments.com/v1/ for live keys.
  • Override with new TinkerPayments(pk, sk, { baseUrl: 'https://custom-host/v1' }).

Standard API Envelope

All standardized endpoints are expected to return:

{
  "success": true,
  "data": {},
  "error": null,
  "meta": {
    "request_id": "5b5b3526-8dc1-4f7b-9bb8-cdbfc8df4984",
    "timestamp": "2026-02-11T22:52:45Z",
    "environment": "production"
  }
}

The SDK stores the latest auth envelope meta via client.getLastAuthMeta().

Subscriptions

const subscriptions = client.subscriptions();

await subscriptions.createPlan({
  name: 'Pro',
  amount: 1000,
  currency: 'KES',
  intervals: ['monthly'],
  description: 'Pro plan',
  is_active: true
});

await subscriptions.listPlans();
await subscriptions.create({
  plan_id: 'plan_123',
  gateway: 'stripe',
  customer: {
    external_customer_id: 'cust_123',
    email: '[email protected]'
  }
});
await subscriptions.list('plan_123', 'cust_123');
await subscriptions.cancel('sub_123');

Webhooks

const event = client.webhooks().handle(rawBody);

const ok = client.webhooks().verifySignature(event, process.env.TINKER_WEBHOOK_SECRET);
if (!ok) {
  throw new Error('Invalid signature');
}

Signature verification uses HMAC-SHA256 on JSON payload fields: id, type, source, timestamp, data, and meta.

Development

npm install
npm run build
npm test

The TypeScript source lives in src/. npm run build emits runtime JavaScript and .d.ts files into dist/, and package.json points consumers at:

{
  "main": "dist/index.js",
  "types": "dist/index.d.ts"
}

Before publishing, run:

npm test
npm pack --dry-run