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

unipay-sdk

v1.0.0-beta

Published

Universal TypeScript SDK for popular payment gateways

Readme

unipay-sdk

Universal TypeScript SDK for payment gateways — one API, zero vendor SDK dependencies.

Supported gateways: Stripe, Xendit, Midtrans, Doku

Features

  • Single PaymentRequest / PaymentResponse interface across all gateways
  • Zero vendor SDK dependencies — all communication via fetch + custom crypto
  • Runtime-agnostic (Bun, Node.js >= 18, Deno, edge runtimes)
  • Dual ESM + CJS output
  • Type-safe with strict TypeScript
  • Webhook signature verification for all gateways

Installation

# npm
npm install unipay-sdk

# yarn
yarn add unipay-sdk

# pnpm
pnpm add unipay-sdk

# bun
bun add unipay-sdk

Quick Start

import { StripeGateway } from 'unipay-sdk/stripe';

const gateway = new StripeGateway();
gateway.initialize({
  secretKey: 'sk_test_...',
});

const response = await gateway.createPayment({
  amount: 2000,
  currency: 'usd',
  referenceId: 'order-123',
  description: 'Test payment',
  paymentMethod: 'card',
});

console.log(response.status); // 'PENDING', 'SUCCESS', etc.

Gateway Examples

Stripe

import { StripeGateway } from 'unipay-sdk/stripe';

const gateway = new StripeGateway();
gateway.initialize({ secretKey: 'sk_test_...' });

// Card payment
const response = await gateway.createPayment({
  amount: 2000,
  currency: 'usd',
  referenceId: 'order-123',
  paymentMethod: 'card',
});

// Check status
const status = await gateway.getPaymentStatus(response.transactionId);

Xendit

import { XenditGateway } from 'unipay-sdk/xendit';

const gateway = new XenditGateway();
gateway.initialize({ secretApiKey: 'xnd_...' });

// E-wallet payment
const response = await gateway.createPayment({
  amount: 50000,
  currency: 'IDR',
  referenceId: 'order-456',
  paymentMethod: 'ewallet',
  country: 'ID',
});

Midtrans

import { MidtransGateway } from 'unipay-sdk/midtrans';

const gateway = new MidtransGateway();
gateway.initialize({
  serverKey: 'SB-Mid-server-...',
  clientKey: 'SB-Mid-client-...',
  isProduction: false,
});

// Bank transfer (BCA VA)
const response = await gateway.createPayment({
  amount: 100000,
  currency: 'IDR',
  referenceId: 'order-789',
  paymentMethod: 'bank_transfer',
  bank: 'bca',
});

Doku

import { DokuGateway } from 'unipay-sdk/doku';

const gateway = new DokuGateway();
gateway.initialize({
  clientId: 'doku-client-...',
  secretKey: 'doku-secret-...',
  privateKey: '-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----',
  isProduction: false,
});

// Virtual Account
const response = await gateway.createPayment({
  amount: 75000,
  currency: 'IDR',
  referenceId: 'order-101',
  paymentMethod: 'va',
  customer: { name: 'John Doe', email: '[email protected]' },
});

Using the UnipayClient Facade

For multi-gateway setups, use the UnipayClient facade:

import { UnipayClient } from 'unipay-sdk';

const client = new UnipayClient({
  gateways: {
    stripe: { secretKey: 'sk_test_...' },
    xendit: { secretApiKey: 'xnd_...' },
  },
});

// Use any configured gateway
const stripe = client.use('stripe');
const response = await stripe.createPayment({ ... });

Webhook Verification

import { verifyWebhook } from 'unipay-sdk';

const event = verifyWebhook('stripe', payload, headers, webhookSecret, {
  throwOnInvalid: true, // default
});

if (event.verified) {
  console.log('Webhook verified:', event.eventType, event.transactionId);
}

Supported Payment Methods

| Gateway | Card | E-wallet | Bank Transfer | VA | QRIS | | -------- | ---- | -------- | ------------- | --- | ---- | | Stripe | Yes | -- | -- | -- | -- | | Xendit | -- | Yes | -- | -- | -- | | Midtrans | Yes | Yes | Yes | Yes | Yes | | Doku | -- | Yes | -- | Yes | -- |

Known Assumptions

The following areas require validation against a real sandbox account before production use:

  • Doku VA & H2H payload structures (src/gateways/doku/mapper.ts): The request body structures for Virtual Account creation and Host-to-Host payments are based on Doku SNAP documentation. Verify against the latest official Doku API docs before going live.

  • Doku card binding: Not implemented in v1. Use Doku.js client-side tokenization for card tokenization flows.

  • Midtrans status mapping: The SDK maps Midtrans transaction_status + fraud_status combinations to a universal status. Verify the mapping matches your expected behavior for edge cases like challenge fraud status.

  • Midtrans Classic Core API v2: This SDK uses the classic Core API v2 (/v2/charge with Basic Auth), not the newer BI-SNAP token-exchange variant. See Reconciliation Notes for why.

  • Xendit v3 API: Uses v3 (/v3/payment_requests) with request_amount field (not amount). See Reconciliation Notes for details.

Architecture

See Adding a Gateway for the extension pattern.

See Reconciliation Notes for decisions on API versioning and endpoint selection.

Development

# Install dependencies
bun install

# Run tests
bun run test

# Run tests with coverage
bun run test -- --coverage

# Type check
bun run typecheck

# Lint
bun run lint

# Build
bun run build

# Run e2e sandbox tests (requires env vars)
bun run test:e2e

License

MIT