Skip to content

line-pay-merchantA Node.js library for the LINE Pay Online API V4

Zero runtime dependencies, fully typed. When the outcome of a payment is unknown, it says so and gives you a way to look it up, instead of calling it a failure.

Install ​

sh
npm install line-pay-merchant

In a few lines ​

ts
import { createLinePayClient } from 'line-pay-merchant'

export const linePay = createLinePayClient({
  channelId: process.env.LINE_PAY_CHANNEL_ID ?? '',
  channelSecretKey: process.env.LINE_PAY_CHANNEL_SECRET ?? '',
  env: 'sandbox' // 'production' for real payments
})
ts
export async function confirmOrder(transactionId: string, amount: number) {
  try {
    const { body } = await linePay.confirm({
      transactionId,
      amount,
      currency: 'TWD'
    })
    return { paid: true, orderId: body.info.orderId }
  } catch (error) {
    // Anything but a timeout or a cut connection is an ordinary failure.
    if (!needsReconcile(error)) throw error

    // The payment may have gone through. Ask the payment details.
    const result = await linePay.reconcile(error)

    if (result.status === 'applied' && result.operation === 'confirm') {
      // Not received from LINE Pay but inferred from the payment details. Check
      // result.body.info.orderId against the order you sent to `request`.
      return { paid: true, orderId: result.body.info.orderId }
    }
    // `not-applied` and `indeterminate` alike: one look does not settle it. A
    // payment that LINE Pay is still processing is not in the details yet, and
    // "not there now" is not "never". Keep the order as it is, tell the user it
    // is being checked, and look again a few minutes later (see the background
    // job): only a second look that still finds nothing lets the user try again.
    return { paid: false, checking: true, status: result.status }
  }
}

Known limitations in 1.0

The ordinary payment flow has been tested in production. Payment requests, payment/refund details, status checks, refunds, duplicate confirm, and reconciliation have been tested in V4 Sandbox. Advanced scenarios including preapproved payments, authorization-only capture, buyer authorization before confirm, mixed payment methods, and other currencies remain incompletely verified. Discount/promotion totals in reconciliation after partial refunds are also not fully verified. These behaviors are not guaranteed, and outstanding questions remain marked in source.

Released under the MIT License. An independent library, not made or endorsed by LINE Pay.