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

tappay-ng

v1.0.0

Published

TapPay SDK for Node.js with TypeScript support - minimal dependencies

Readme

TapPay NG (Next Generation)

TapPay SDK for Node.js with TypeScript support. Minimal dependencies implementation using only Node.js built-in modules.

Features

  • 🚀 Zero external dependencies (only TypeScript for development)
  • 📘 Full TypeScript support with type definitions
  • 🔒 Type-safe API interfaces
  • 🎯 Simple and intuitive API
  • ✅ Support for all TapPay backend APIs

Installation

npm install tappay-ng

Supported APIs

  • Pay by Prime - Process payment using prime token from frontend
  • Pay by Card Token - Process payment using stored card token (for recurring payments)
  • Refund - Process full or partial refund
  • Record Query - Query transaction records

Quick Start

import { TapPayClient } from 'tappay-ng';

const client = new TapPayClient({
  partnerId: 'YOUR_PARTNER_ID',
  partnerKey: 'YOUR_PARTNER_KEY',
  merchantId: 'YOUR_MERCHANT_ID',
  env: 'sandbox', // or 'production'
});

Usage Examples

Pay by Prime

const response = await client.payByPrime({
  prime: 'prime_from_frontend',
  amount: 100,
  details: 'Order payment',
  cardholder: {
    phone_number: '+886912345678',
    name: 'Test User',
    email: '[email protected]',
    zip_code: '100',
    address: 'Taipei',
  },
  currency: 'TWD',
  orderNumber: 'ORDER-123',
  remember: true, // Save card for future use
});

console.log('Transaction ID:', response.rec_trade_id);
console.log('Card Info:', response.card_info);

// If remember is true, you can get card_secret for future payments
if (response.card_secret) {
  console.log('Card Key:', response.card_secret.card_key);
  console.log('Card Token:', response.card_secret.card_token);
}

Pay by Prime with 3D Secure

const response = await client.payByPrime({
  prime: 'prime_from_frontend',
  amount: 100,
  details: 'Order payment',
  cardholder: {
    phone_number: '+886912345678',
    name: 'Test User',
    email: '[email protected]',
  },
  threeDomainSecure: true,
  frontendRedirectUrl: 'https://your-site.com/payment/result',
  backendNotifyUrl: 'https://your-site.com/api/payment/notify',
});

// For 3D Secure, redirect user to payment_url
if (response.payment_url) {
  console.log('Redirect user to:', response.payment_url);
}

Pay by Card Token

// Use saved card_key and card_token from previous payment
const response = await client.payByCardToken({
  cardKey: 'saved_card_key',
  cardToken: 'saved_card_token',
  amount: 100,
  details: 'Subscription payment',
  cardholder: {
    phone_number: '+886912345678',
    name: 'Test User',
    email: '[email protected]',
  },
  orderNumber: 'SUB-456',
});

console.log('Transaction ID:', response.rec_trade_id);

Refund

// Full refund
const response = await client.refund({
  recTradeId: 'transaction_id_to_refund',
});

// Partial refund
const partialResponse = await client.refund({
  recTradeId: 'transaction_id_to_refund',
  amount: 50, // Refund partial amount
});

console.log('Refund Amount:', response.refund_amount);

Query Transaction Records

// Query all records
const records = await client.queryRecords();

console.log('Total transactions:', records.number_of_transactions);
console.log('Records:', records.trade_records);

// Query with filters
const filteredRecords = await client.queryRecords({
  recordsPerPage: 20,
  page: 1,
  timeRange: {
    startTime: 1609459200000, // timestamp in milliseconds
    endTime: 1612137600000,
  },
  amountRange: {
    lowerLimit: 100,
    upperLimit: 1000,
  },
  currency: 'TWD',
  orderNumber: 'ORDER-123',
});

// Query by specific transaction ID
const specificRecord = await client.queryRecords({
  recTradeId: 'specific_transaction_id',
});

API Reference

TapPayClient

Constructor

new TapPayClient(config: TapPayConfig)

TapPayConfig:

  • partnerId (string) - Your TapPay partner ID
  • partnerKey (string) - Your TapPay partner key
  • merchantId (string) - Your merchant ID
  • env (optional) - Environment: 'sandbox' or 'production' (default: 'sandbox')

Methods

payByPrime(params)

Process payment using prime token from frontend.

Parameters:

  • prime (string) - Prime token from TapPay frontend SDK
  • amount (number) - Payment amount
  • details (string) - Payment description
  • cardholder (Cardholder) - Cardholder information
  • currency (optional) - Currency code (default: 'TWD')
  • remember (optional) - Save card for future use (default: false)
  • orderNumber (optional) - Your order number
  • bankTransactionId (optional) - Bank transaction ID
  • threeDomainSecure (optional) - Enable 3D Secure
  • frontendRedirectUrl (optional) - Frontend redirect URL (required for 3DS)
  • backendNotifyUrl (optional) - Backend notify URL (required for 3DS)
  • instalment (optional) - Number of instalments
  • delayCapture (optional) - Days to delay capture
payByCardToken(params)

Process payment using stored card token.

Parameters:

  • cardKey (string) - Card key from previous payment
  • cardToken (string) - Card token from previous payment
  • amount (number) - Payment amount
  • details (string) - Payment description
  • cardholder (Cardholder) - Cardholder information
  • currency (optional) - Currency code (default: 'TWD')
  • Other optional parameters similar to payByPrime
refund(params)

Process refund for a transaction.

Parameters:

  • recTradeId (string) - Transaction ID to refund
  • amount (optional) - Refund amount (omit for full refund)
queryRecords(params)

Query transaction records.

Parameters:

  • recordsPerPage (optional) - Number of records per page
  • page (optional) - Page number
  • timeRange (optional) - Time range filter
  • amountRange (optional) - Amount range filter
  • cardholder (optional) - Cardholder filter
  • merchantId (optional) - Merchant ID filter
  • currency (optional) - Currency filter
  • orderNumber (optional) - Order number filter
  • recTradeId (optional) - Transaction ID filter

Error Handling

import { TapPayError } from 'tappay-ng';

try {
  const response = await client.payByPrime({
    // ... params
  });
} catch (error) {
  const tapPayError = error as TapPayError;
  console.error('Error status:', tapPayError.status);
  console.error('Error message:', tapPayError.msg);
}

TypeScript Support

This package includes full TypeScript type definitions. All request and response types are exported:

import {
  TapPayClient,
  TapPayConfig,
  PayByPrimeResponse,
  PayByCardTokenResponse,
  RefundResponse,
  RecordResponse,
  Cardholder,
  Currency,
  TapPayError,
} from 'tappay-ng';

Security Notes

  • Never expose your partnerKey in client-side code
  • Always validate payment results on your backend
  • Use HTTPS for all communications
  • Verify 3D Secure callbacks on your backend
  • Store card tokens securely and never log them

Testing

Use sandbox environment for testing:

const client = new TapPayClient({
  partnerId: 'YOUR_PARTNER_ID',
  partnerKey: 'YOUR_PARTNER_KEY',
  merchantId: 'YOUR_MERCHANT_ID',
  env: 'sandbox',
});

License

MIT

Links

Support

For TapPay API issues, please contact TapPay support. For SDK issues, please open an issue on GitHub.