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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ecpay-payment-node

v1.2.2

Published

Unofficial ECPay (綠界科技) Payment Gateway SDK for Node.js and Bun. Supports credit card, ATM, CVS, Apple Pay, and more. Full TypeScript support with ESM/CJS compatibility.

Downloads

368

Readme

ECPay Payment SDK for Node.js

English | 繁體中文

Unofficial ECPay Payment SDK for Node.js, built with Bun, supporting both ESM and CJS.

Features

  • 🚀 Full TypeScript support
  • 📦 Supports both ESM and CommonJS
  • 🔒 Built-in CheckMacValue calculation and verification
  • 🛠 Provides FormBuilder for quick payment form generation

Installation

npm install ecpay-payment-node
# or
yarn add ecpay-payment-node
# or
pnpm add ecpay-payment-node
# or
bun add ecpay-payment-node

Usage

1. Credit Card Payment (One-Time)

import { CreditPayment, FormBuilder } from 'ecpay-payment-node'

// 1. Initialize
const payment = new CreditPayment('2000132', '5294y06JbISpM5x9', 'v77hoKGq4kWxNNIS')

// 2. Set Parameters
payment
  .setMerchantTradeNo('Credit' + Date.now())
  .setMerchantTradeDate(new Date())
  .setTotalAmount(1000)
  .setTradeDesc('Test Transaction')
  .setItemName('Item A x 1')
  .setReturnURL('https://example.com/return')
  // Optional
  .setClientBackURL('https://example.com/client-back')
  .setNeedExtraPaidInfo('Y')

// 3. Generate HTML Form
const builder = new FormBuilder()
const html = builder.build(payment)

2. Credit Card Installment

import { CreditInstallment, FormBuilder } from 'ecpay-payment-node'

const payment = new CreditInstallment('2000132', '5294y06JbISpM5x9', 'v77hoKGq4kWxNNIS')
payment.setMerchantTradeNo('Inst' + Date.now())
       .setTotalAmount(3000)
       .setTradeDesc('Installment Test')
       .setItemName('Expensive Item x 1')
       .setReturnURL('https://example.com/return')
       // Set Installment Period (3, 6, 12, 18, 24)
       .setCreditInstallment('3')

const html = new FormBuilder().build(payment)

3. Credit Card Recurring (Subscription)

💡 Use Case: Subscription services, regular donations, membership fees.

import { CreditRecurring, FormBuilder, PeriodType } from 'ecpay-payment-node'

const payment = new CreditRecurring('2000132', '5294y06JbISpM5x9', 'v77hoKGq4kWxNNIS')
payment.setMerchantTradeNo('Rec' + Date.now())
       .setTotalAmount(99) // First authorization amount (usually same as period amount)
       .setTradeDesc('Subscription Service')
       .setItemName('Monthly Membership')
       .setReturnURL('https://example.com/return') // Callbak for initial authorization
       // Recurring Parameters (Required)
       .setPeriodAmount(99)        // Amount per charge
       .setPeriodType(PeriodType.Month) // Cycle unit (Year, Month, Day)
       .setFrequency(1)            // Frequency (Every 1 Month)
       .setExecTimes(12)           // Total executions (12 times)
       .setPeriodReturnURL('https://example.com/period-return') // Callback for each recurring charge

const html = new FormBuilder().build(payment)

Parameter Details:

| Method | Description | Example | | :--- | :--- | :--- | | setPeriodAmount | Period AmountThe amount to be charged for each period. | 99 | | setPeriodType | Cycle UnitUnit of the recurring cycle.- PeriodType.Day- PeriodType.Month- PeriodType.Year | PeriodType.Month | | setFrequency | FrequencyInterval of the cycle.e.g., if Type is Month and Frequency is 1, it means "Every 1 Month". | 1 | | setExecTimes | Execution TimesTotal number of times to charge.e.g., 12 means charge 12 times in total. | 12 | | setPeriodReturnURL| Recurring Callback URLServer URL notified by ECPay after each successful recurring charge. | https://... |

4. ATM (Virtual Account)

import { AtmPayment, FormBuilder } from 'ecpay-payment-node'

const payment = new AtmPayment('2000132', '5294y06JbISpM5x9', 'v77hoKGq4kWxNNIS')
payment.setMerchantTradeNo('ATM' + Date.now())
       .setTotalAmount(500)
       .setTradeDesc('ATM Test')
       .setItemName('Transfer Item')
       .setReturnURL('https://example.com/return')
       // ATM Specifics
       .setExpireDate(3) // Expires in 3 days
       .setPaymentInfoURL('https://example.com/payment-info') // Server webhook

const html = new FormBuilder().build(payment)

5. CVS (Convenience Store Code)

import { CvsPayment, FormBuilder } from 'ecpay-payment-node'

const payment = new CvsPayment('2000132', '5294y06JbISpM5x9', 'v77hoKGq4kWxNNIS')
payment.setMerchantTradeNo('CVS' + Date.now())
       .setTotalAmount(200)
       .setTradeDesc('CVS Test')
       .setItemName('CVS Item')
       .setReturnURL('https://example.com/return')
       // CVS Specifics
       .setStoreExpireDate(10080) // Minutes (7 days)
       .setPaymentInfoURL('https://example.com/payment-info')

const html = new FormBuilder().build(payment)

6. Apple Pay

import { ApplePayPayment, FormBuilder } from 'ecpay-payment-node'

const payment = new ApplePayPayment(merchantID, hashKey, hashIV)
payment.setMerchantTradeNo('Apple' + Date.now())
       .setTotalAmount(1000)
       .setTradeDesc('Apple Pay Test')
       .setItemName('IPhone Case')
       .setReturnURL('https://example.com/return')

const builder = new FormBuilder()
const html = builder.build(payment)

Verify Notification

import { PaymentNotify } from 'ecpay-payment-node'

const notify = new PaymentNotify(hashKey, hashIV)
const data = { /* Parameters returned by ECPay */ }

if (notify.verify(data)) {
  console.log('Verification Successful')
  // Process order...
}

Order Query

import { QueryOrder, EcPayClient } from 'ecpay-payment-node'

const client = new EcPayClient(merchantID, hashKey, hashIV)
const query = new QueryOrder(merchantID, hashKey, hashIV)
query.setMerchantTradeNo('Test123456')

const result = await client.query(query)
console.log(result)

Development

# Install dependencies
bun install

# Run tests
bun test

# Build
bun run build

License

MIT © 2024 Carl Lee