Basic Usage

It can be imported with CommonJS, ES2015 modules, and preferably TypeScript.

The library is written in TypeScript and includes TypeScript definitions by default. Nevertheless, it can surely be used with plain JavaScript too.

// CommonJS
const line = require('line-pay-sdk');

// ES6 modules or TypeScript
import * as line from 'line-pay-sdk';

Configuration

For the usage of webhook and client, LINE channel access token and secret are needed. About issuing the token and secret, please refer to Getting started with the Messaging API.

const config = {
  channelId: 'YOUR_LINE_PAY_CHANNEL_ID',
  channelSecret: 'YOUR_LINE_PAY_CHANNEL_SECRET',
};

new line.Client(config);

Synopsis

Here is a synopsis of echoing webhook server with Express:

const express = require('express');
const line = require('line-pay-sdk');
const uuid = require('uuid/v4');

const config = {
  channelId: 'YOUR_LINE_PAY_CHANNEL_ID',
  channelSecret: 'YOUR_LINE_PAY_CHANNEL_SECRET',
};

const app = express();
// Router configuration to start payment flow
app.use('/pay/reserve', (req, res) => {
    const options = {
        productName: 'Apple',
        amount: 1,
        currency: 'JPY',
        orderId: uuid(),
        confirmUrl: 'http://localhost:5000/pay/confirm',
    }

    line.reservePayment(options).then((response) => {
        let reservation = options;
        reservation.transactionId = response.info.transactionId;

        console.log('Reservation was made.');
        console.log(reservation);

        // Save order information
        cache.put(reservation.transactionId, reservation);

        res.redirect(response.info.paymentUrl.web);
    })
})

app.listen(5000);

The full examples with comments can be found in examples.

For the specifications of API, please refer to API Reference.