Skip to main content

Implement basic payment

LINE Pay's basic online payment method automatically processes capture after payment confirmation is processed. The basic payment flow is as follows.

Based on the payment flow above, implement the following operations on the merchant server.

To separate payment confirmation and capture when implementing payment, familiarize yourself with the basic payment implementation and then see Implement capture-separated payment.

Payment request

When a customer attempts to make a payment with LINE Pay after deciding on the product or service to purchase, the merchant server needs to send the following information to the LINE Pay server to request payment.

  • Payment amount and currency code
  • Order ID managed by the merchant
  • Purchased product or service information
  • Redirection information of the page to redirect to after LINE Pay authentication
  • Other payment information

The merchant provides the following product page (on the left) and order page (on the right) to obtain the above information from the customer.

After obtaining the information, call the payment request API. The following is a request to pay for two 50 yen pens.

For information on obtaining the credentials needed to call the Online API, see Prepare API credentials. The code example described on this page uses the requestOnlineAPI() function defined in the Prepare API credentials code example.

try {
let response = await requestOnlineAPI({
method: "POST",
baseUrl: targetAPIServer,
apiPath: "/v3/payments/request",
data: {
amount: 100,
currency: "TWD",
orderId: "EXAMPLE_ORDER_20230422_1000001",
packages: [
{
id: "1",
amount: 100,
products: [
{
id: "PEN-B-001",
name: "Pen Brown",
imageUrl: "https://store.example.com/images/pen_brown.jpg",
quantity: 2,
price: 50,
},
],
},
],
redirectUrls: {
confirmUrl: "https://store.example.com/order/payment/authorize",
cancelUrl: "https://store.example.com/order/payment/cancel",
},
},
});

console.log("Response: ", response);
} catch (error) {
console.log(error);
}

Once the payment request is completed, you will receive the following response.

{
"returnCode": "0000",
"returnMessage": "Success.",
"info": {
"paymentUrl": {
"web": "https://sandbox-web-pay.line.me/web/payment/wait?transactionReserveId=REpEWEttQ0F2RmFnaFFzVndIdjl6Z0lqbGpPemZjOHpNWTFZTmdibUlRNlEzOG50N2VSRmdGU2IxcnVjMHZ1NQ",
"app": "line://pay/payment/REpEWEttQ0F2RmFnaFFzVndIdjl6Z0lqbGpPemZjOHpNWTFZTmdibUlRNlEzOG50N2VSRmdGU2IxcnVjMHZ1NQ"
},
"transactionId": 2023042201206549310,
"paymentAccessToken": "056579816895"
}
}

Next, you need to redirect the customer to the LINE Pay authentication screen. Among the payment screen redirection URLs (info.paymentUrl) received as a response, redirect the customer to the URL that corresponds to the device they're using.

  • PC users: Display the URL of the info.paymentUrl.web field in the pop-up window or redirect to the web page the URL directs to.
  • Mobile device users: A deep link in the info.paymentUrl.app field launches the LINE Pay authentication screen in the LINE app.

If the result code (returnCode) is not 0000, see Result code.

LINE Pay authentication

LINE Pay authentication is the process in which the customer navigates to the URL (paymentUrl) received as a response to the payment request, authenticates themselves in the LINE app or web environment, and enters their payment password. On the LINE Pay screen of the LINE app or on a LINE Pay authentication pop-up page, the customer authenticates in the following order.

1. Redirection to authentication page

The LINE Pay authentication process can be cancelled by the customer at any time.

After LINE Pay authentication is completed in the LINE app or pop-up page, the customer is redirected to one of the redirection pages specified when calling the payment request API. Based on where the customer is redirected to, you can determine whether the customer completed LINE Pay authentication or canceled the payment.

After the payment confirmation page is displayed, you can proceed with payment confirmation. The following is an example of a payment confirmation page that the merchant needs to provide.

Depending on the situation, you can implement payment without providing the redirection page. For more information, see Implement without redirection URL document.

Payment confirmation

Once the customer has completed LINE Pay authentication and finalized their purchase information, the merchant server can request payment confirmation to the LINE Pay server. If you did not separate payment confirmation and capture, the capture will be processed automatically upon confirmation and the payment will be settled immediately.

Enter the following information to call the payment confirmation request API.

Depending on the service implementation language, you may need to process the transaction ID as a string when handling transaction ID information. For more information, see the Transaction ID.

The following code requests the confirmation of the previously requested payment.

try {
let response = await requestOnlineAPI({
method: "POST",
baseUrl: targetAPIServer,
apiPath: `/v3/payments/${requestTransactionId}/confirm`,
data: {
amount: 100,
currency: "TWD",
},
});

console.log("Response: ", response);
} catch (error) {
console.log(error);
}

Once the payment confirmation is completed, you will receive the following response.

{
"returnCode": "0000",
"returnMessage": "OK",
"info": {
"orderId": "EXAMPLE_ORDER_20230422_1000001",
"transactionId": 2023042201206549310,
"payInfo": [
{
"method": "BALANCE",
"amount": 100
}
]
}
}

After receiving the above response, provide a page indicating that the payment was ultimately completed to customers.

If the payment is automatically captured, you can't void the payment and can only process refund.