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

paynet-sdk

v0.1.2

Published

TypeScript SDK for Paynet API v0.5

Readme

Paynet TypeScript SDK

TypeScript SDK for Paynet API v0.5. Server-side SDK for managing payment flows.

Note: This SDK is based on Paynet API documentation. For official API specifications, refer to paynet.md.

⚠️ Warning: Some parts of this package were "vibe-coded" and may require additional review and testing.

Installation

npm install paynet-sdk
# or
pnpm add paynet-sdk
# or
yarn add paynet-sdk

Requirements

  • Node.js >= 18.0.0
  • TypeScript 5.x (for TypeScript projects)

Quick Start

import { PaynetServerSDK } from 'paynet-sdk';

const sdk = new PaynetServerSDK({
  apiHost: 'https://api-merchant.test.paynet.md',
  portalHost: 'https://test.paynet.md',
  secretKey: '550e8400-e29b-41d4-a716-446655440000',
  debug: true, // optional
});

// Authenticate
await sdk.authenticate('username', 'password');

// Create a payment
const payment = await sdk.createPayment({
  Invoice: 12345,
  MerchantCode: '123456',
  Currency: 498, // MDL
  ExpiryDate: new Date(Date.now() + 4 * 3600 * 1000).toISOString(),
  Customer: {
    Code: 'CUST001',
    Name: 'John Doe',
    PhoneNumber: '+37360123456',
    email: '[email protected]',
  },
  Services: [
    {
      Name: 'Product Purchase',
      Description: 'Payment for order #12345',
      Amount: 100000, // in minor units (1000.00 MDL)
      Products: [
        {
          Code: 'PROD001',
          Name: 'Product Name',
          Amount: 100000,
          Quantity: 1,
        },
      ],
    },
  ],
});

console.log('Payment created:', payment.PaymentID);

Usage Examples

Authentication

// Basic authentication
const authResponse = await sdk.authenticate('123456', 'password');
console.log('Token expires in:', authResponse.expires_in, 'seconds');

// Manual token setting (if obtained externally)
sdk.setAccessToken('your-token-here', 3600); // expires in 1 hour

// Get current token
const token = sdk.getAccessToken();

Create Payment (Server-to-Server Flow)

const payment = await sdk.createPayment({
  Invoice: 12345,
  MerchantCode: '123456',
  Currency: 498, // MDL
  ExternalDate: new Date().toISOString(),
  ExpiryDate: new Date(Date.now() + 4 * 3600 * 1000).toISOString(),
  Customer: {
    Code: 'CUST001',
    NameFirst: 'John',
    NameLast: 'Doe',
    PhoneNumber: '+37360123456',
    email: '[email protected]',
    Country: 'MD',
    City: 'Chisinau',
    Address: '123 Main St',
  },
  Services: [
    {
      Name: 'Service Name',
      Description: 'Service description',
      Amount: 50000, // Amount can be omitted if Products are provided
      Products: [
        {
          Code: 'PROD001',
          Name: 'Product 1',
          Amount: 30000,
          Quantity: 1,
          UnitPrice: 30000,
        },
        {
          Code: 'PROD002',
          Name: 'Product 2',
          Amount: 20000,
          Quantity: 2,
          UnitPrice: 10000,
        },
      ],
    },
  ],
  LinkUrlSuccess: 'https://yoursite.com/success',
  LinkUrlCancel: 'https://yoursite.com/cancel',
  Lang: 'en-US',
});

// Payment is created, use PaymentID to redirect user
console.log('Payment ID:', payment.PaymentID);
console.log('Signature:', payment.Signature);

Get Payment Status

const payment = await sdk.getPayment(12345);
console.log('Status:', payment.Status);
console.log('Processed:', payment.Processed);

Search Payments

// Search by invoice
const payments = await sdk.searchPayments({
  Invoice: 12345,
});

// Search by date range
const payments = await sdk.searchPayments({
  from: '2024-01-01T00:00:00Z',
  to: '2024-01-31T23:59:59Z',
});

Build Payment Forms

GetEcom Form (Server-to-Server Flow)

After creating a payment via API, redirect user to Paynet portal:

const payment = await sdk.createPayment({
  /* ... */
});

const formHtml = sdk.buildGetEcomForm(
  payment,
  'https://yoursite.com/success',
  'https://yoursite.com/cancel',
  'en-US'
);

// Return form HTML to client, or auto-submit
res.send(formHtml);

SetEcom Form (Client-to-Server Flow)

Build form directly from payment data (no API call needed):

const payment = {
  Invoice: 12345,
  MerchantCode: '123456',
  Currency: 498,
  ExpiryDate: new Date(Date.now() + 4 * 3600 * 1000).toISOString(),
  ExternalDate: new Date().toISOString(),
  Customer: {
    /* ... */
  },
  Services: [
    /* ... */
  ],
  LinkUrlSuccess: 'https://yoursite.com/success',
  LinkUrlCancel: 'https://yoursite.com/cancel',
};

const formHtml = sdk.buildSetEcomForm(
  payment,
  'https://yoursite.com/success',
  'https://yoursite.com/cancel',
  'en-US'
);

Webhook Verification

import { verifyNotificationSignature } from 'paynet-sdk';

app.post('/webhooks/paynet', (req, res) => {
  const notification = req.body;

  // Verify signature
  const isValid = sdk.verifyNotificationSignature(notification);
  if (!isValid) {
    return res.status(401).send('Invalid signature');
  }

  // Process notification
  if (notification.EventType === 'PAID') {
    console.log('Payment paid:', notification.Payment.ID);
    // Update your database, send confirmation email, etc.
  }

  res.status(200).send('OK');
});

Manual Signature Generation

import { generatePaymentSignature } from 'paynet-sdk';

const payment = {
  /* ... */
  Signature: generatePaymentSignature(payment, '550e8400-e29b-41d4-a716-446655440000'),
};

API Reference

PaynetServerSDK

Constructor

new PaynetServerSDK(config: PaynetServerSDKConfig)

Config:

  • apiHost (string, required): Paynet API host URL
  • portalHost (string, required): Paynet portal host URL
  • secretKey (string, required): Shared secret for signature generation
  • httpClient (object, optional): Custom fetch implementation
  • debug (boolean, optional): Enable debug logging

Methods

  • authenticate(username: string, password: string): Promise<AuthenticateResponse>
  • setAccessToken(token: string, expiresIn?: number): void
  • getAccessToken(): string | null
  • createPayment(payment: Payment): Promise<Payment>
  • getPayment(paymentId: number): Promise<Payment>
  • searchPayments(criteria: SearchCriteria): Promise<Payment[]>
  • verifyNotificationSignature(notification: PaymentNotificationRequest): boolean
  • generatePaymentSignature(payment: Payment): string
  • buildGetEcomForm(payment: Payment, successUrl: string, cancelUrl: string, lang?: string): string
  • buildSetEcomForm(payment: Payment, successUrl: string, cancelUrl: string, lang?: string): string

TODO

  • [ ] Add retry logic for transient API failures
  • [ ] Implement request/response interceptors
  • [ ] Add unit/int tests
  • [ ] JSDoc public methods

Development

# Install dependencies
pnpm install

# Build
pnpm build

# Type check
pnpm type-check

# Lint
pnpm lint

# Format
pnpm format

License

MIT

Attribution

This SDK is based on Paynet API v0.5 specifications. Refer to paynet.md for official API documentation.