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

linepay-offline-v2

v1.0.6

Published

a linepay Node.js SDK for integrating Linepay Offline Payment API. 提供 Linepay 線下交易 API 封裝,支援付款、退款、取消、查詢等功能。

Readme

LINE Pay 離線支付 SDK (Node.js)

這是一個輕量且易於使用的 Node.js SDK,用於串接 LINE Pay 離線支付 (Offline Payment) API。此 SDK 封裝了基本的支付、查詢和退款功能,讓您可以快速整合 LINE Pay 條碼支付功能到您的應用程式中。

專案設定

安裝套件: 在您的專案中,執行以下指令來安裝 linepay-offline-v2 套件。

npm install linepay-offline-v2

設定說明

.env 設定:

在專案根目錄下建立一個 .env 檔案,並填入您的 LINE Pay 通道 ID (Channel ID) 和密鑰 (Secret Key)。

LINEPAY_CHANNEL_ID="您的-LINE-Pay-Channel-ID"
LINEPAY_SECRET_KEY="您的-LINE-Pay-Secret-Key"

使用範例

以下範例展示了如何初始化 SDK 並執行一次完整的支付流程,包括付款、查詢及退款。

// index.js

const { LinePayOfflineSDK } = require("linepay-offline-v2");
const dotenv = require('dotenv');
dotenv.config();

(async () => {
    // 初始化 SDK,請確保在 .env 檔案中設定了 LINEPAY_CHANNEL_ID 和 LINEPAY_SECRET_KEY
    const sdk = new LinePayOfflineSDK({
        isProduction: false, // true 為正式環境,false 為沙盒環境
        channelId: process.env.LINEPAY_CHANNEL_ID,
        channelSecret: process.env.LINEPAY_SECRET_KEY,
        timeout: 10000
    });

    const order_id = "DEMO-" + Date.now();

    console.log("===== LINE Pay SDK 初始化完成 =====");
    try {
        // 1. 建立付款請求
        console.log("===== 正在建立付款請求 =====");
        const payRes = await sdk.offlinePayment({
            productName: "測試商品",
            amount: 1,
            currency: "TWD",
            orderId: order_id,
            oneTimeKey: "384407985918048433", // 此為範例 oneTimeKey,實際應用中需由客戶端提供
            extras: {
                branchName: "範例商店",
                branchId: "branch1"
            }
        });
        console.log("付款結果:", JSON.stringify(payRes, null, 2));

        // 2. 查詢付款狀態
        if (sdk.isSuccess(payRes)) {
            console.log("\n===== 正在查詢付款狀態 =====");
            const checkRes = await sdk.checkOrder(order_id);
            console.log("訂單狀態查詢結果:", JSON.stringify(checkRes, null, 2));

            // 3. 查詢付款明細
            console.log("\n===== 正在查詢付款明細 =====");
            const detailRes = await sdk.getPaymentDetails(order_id);
            console.log("付款明細查詢結果:", JSON.stringify(detailRes, null, 2));

            // 4. 進行退款
            console.log("\n===== 正在測試退款 =====");
            const refundRes = await sdk.refundOrder(order_id, 1);
            console.log("退款結果:", JSON.stringify(refundRes, null, 2));
        }

    } catch (err) {
        console.error("SDK 執行發生錯誤:", err.message);
    }

    // 5. 額外功能:錯誤碼查詢
    console.log("\n===== 錯誤碼說明 =====");
    console.log("錯誤碼 1142:", sdk.getStatusDescription("1142")); // 餘額不足

})();