Getting Started

Create LINE Pay Sandbox Account

You may need Sandbox account to develop and test LINE Pay application. If you already have a Sandbox account, feel free to skip this step.

Channel ID and channel secret key are two important items used to authenticate the identity of merchants. Using production channel ID and channel secret key in development environment is inconvenient and dangerous. Follow the steps below to create your Sandbox account and find your channel ID and channel secret key.

  1. Apply for a Sandbox account in Sandbox Creation menuopen in new window. Merchant ID and password will be sent to the email address provided in the application form.

  2. Find your merchant ID and password in the email.

  3. Log in to Merchant Centeropen in new window with merchant ID and password.

  4. Find your channel ID and channel secret key at Manage Link Key Pageopen in new window by following the Channel ID & SK guideopen in new window.

You may now test the LINE Pay Online API with your new channel ID and channel secret key.

For more information, please visit the official Test Flow Pageopen in new window.

Installation

You can install the package from NPMopen in new window or YARNopen in new window with the following commands:

npm install line-pay-merchant
yarn add line-pay-merchant

Or build from source:

git clone https://github.com/enylin/line-pay-merchant
cd line-pay-merchant
npm install
npm run build

Example

LINE Pay Request API

Import createLinePayClient function from line-pay-merchant.

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

Create client with channel ID and channel secret key.

const linePayClient = createLinePayClient({
  channelId: '1479113123', // your channel ID
  channelSecretKey: '1f021e50f28fb3f40b7a9c5e758b0a19', // your channel secret key
  env: 'development' // env can be 'development' or 'production'
})

Use the client created to call LINE Pay request API.

async function request() {
  try {
    const res = await linePayClient.request.send({
      body: {
        amount: 1000,
        currency: 'TWD',
        orderId: '20211209003',
        packages: [
          {
            id: 'c99abc79-3b29-4f40-8851-bc618ca57856',
            amount: 1000,
            products: [
              {
                name: 'Product Name',
                quantity: 2,
                price: 500
              }
            ]
          }
        ],
        redirectUrls: {
          confirmUrl: 'https://myshop.com/confirmUrl',
          cancelUrl: 'https://myshop.com/cancelUrl'
        }
      }
    })

    console.log(res)
  } catch (e) {
    console.log('error', e)
  }
}

Response:

{
  "body": {
    "returnCode": "0000",
    "returnMessage": "Success.",
    "info": {
      "paymentUrl": {
        "web": "https://sandbox-web-pay.line.me/web/payment/wait?transactionReserveId=eVBISG5rQ09QL2JBVmJsdGdGN3RiUlBLaU0vMUtKWGEvVzhZS3o5NnBvSUlqZXdLdXk3Wlh0RXY2a0o3ZHp6Yw",
        "app": "line://pay/payment/eVBISG5rQ09QL2JBVmJsdGdGN3RiUlBLaU0vMUtKWGEvVzhZS3o5NnBvSUlqZXdLdXk3Wlh0RXY2a0o3ZHp6Yw"
      },
      "transactionId": "2021121600698709710",
      "paymentAccessToken": "656097936065"
    }
  },
  "comments": {}
}
Last Updated:
Contributors: Sean Lin