Prerequisites
To use the Offline API, you need to prepare the following:
Set the allowlist of servers
To use the LINE Pay API, you need to enable the merchant server to access the sandbox. The merchant center manages an allowlist of servers that can call the LINE Pay API as a menu named Manage Payment Server IP. Register the IP address of your merchant server as follows.
If you are a sandbox merchant and testing the LINE Pay API in sandbox, you do not need to set the allowlist of servers.
-
Log in to the merchant center.
-
Select [Payment Integration Management > Manage Payment Server IP] from the menu on the left.
-
In the Manage Payment Server IP page, enter the merchant server's IP address and IP address mask value as follows, and click the Add button.
-
(Optional) If you have more than one merchant server to test, click the Add Row button in the upper right corner to add a row, and repeat step 3 as many times as necessary.
Handle API credentials
To use the Offline API, you must specify your credentials in the HTTP request header when calling the API.
After you join as a merchant, you can get the channel ID and channel secret key from the merchant center, which you must include in the appropriate HTTP request header.
You can apply for a sandbox account to request a channel ID and channel secret key for the sandbox for testing.
If you already have a channel ID and channel secret key issued by join as a merchant, you can use it in the sandbox environment without separate application.
The HTTP request header that specifies the credentials is as follows.
X-LINE-ChannelId
X-LINE-ChannelSecret
When calling the Offline API, you can also include information about the merchant's device in the HTTP request header. For more information, see Offline API request header.
Enter the channel ID value in the X-LINE-ChannelId
header and the channel secret key in the X-LINE-ChannelSecret
header. The following example code enables calling an Offline API by adding credentials information to the HTTP request header.
In the code examples below, the
handleBigInteger()
function is required when dealing with the transaction ID value. For more information on transaction IDs and thehandleBigInteger()
function, see Transaction ID.
const crypto = require("crypto");
async function requestOfflineAPI({
method,
baseUrl = "https://sandbox-api-pay.line.me",
apiPath,
queryString = "",
data = null,
signal = null,
}) {
const headers = {
"X-LINE-ChannelId": YOUR_CHANNEL_ID,
"X-LINE-ChannelSecret": YOUR_CHANNEL_SECRET,
"X-LINE-MerchantDeviceProfileId": YOUR_DEVICE_PROFILE_ID,
"X-LINE-MerchantDeviceType": YOUR_DEVICE_TYPE,
};
const response = await fetch(
`${baseUrl}${apiPath}${queryString !== "" ? "&" + queryString : ""}`,
{
method: method,
headers: {
"Content-Type": "application/json",
...headers,
},
body: data ? JSON.stringify(data) : null,
signal: signal,
}
);
const processedResponse = handleBigInteger(await response.text());
return processedResponse;
}