PHPackages                             yidas/line-pay-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. yidas/line-pay-sdk

ActiveLibrary[API Development](/categories/api)

yidas/line-pay-sdk
==================

LINE Pay SDK for PHP

4.0.1(4mo ago)8428.3k↓20.8%32MITPHPPHP &gt;=5.4

Since Jun 19Pushed 4mo ago4 watchersCompare

[ Source](https://github.com/yidas/line-pay-sdk-php)[ Packagist](https://packagist.org/packages/yidas/line-pay-sdk)[ Docs](https://github.com/yidas/line-pay-sdk-php)[ RSS](/packages/yidas-line-pay-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (28)Used By (0)

 [ ![](https://camo.githubusercontent.com/f52fab8893ea6283685672f65d682339c2429078c426f2569382da0f110e8530/68747470733a2f2f7363646e2e6c696e652d617070732e636f6d2f6c696e657061792f706f7274616c2f6173736574732f696d672f706f7274616c2f6a702f6c6f676f2e737667) ](https://pay.line.me/)

LINE Pay SDK *for* PHP
======================

[](#line-pay-sdk-for-php)

LINE Pay SDK for PHP

[![Latest Stable Version](https://camo.githubusercontent.com/f9c5fbde38b2dd17e90cc3bced5e8b62043f661057fed0d28ddf8352277eeddb/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f6c696e652d7061792d73646b2f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/line-pay-sdk)[![License](https://camo.githubusercontent.com/febe730c7d72a1ca7d0a3841024ad175b667f3a84198c9c2cc8263fd806c068e/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f6c696e652d7061792d73646b2f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/line-pay-sdk)[![Total Downloads](https://camo.githubusercontent.com/c230902dcc14e427e6c27a8d89772a2f98a899ab5d076e3625d7b3c2668ce172/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f6c696e652d7061792d73646b2f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/line-pay-sdk)

English | [繁體中文](https://github.com/yidas/line-pay-sdk-php/blob/v4/README-zh_TW.md)

SDK VersionOnline API VersionOffline API Versionv4 (Current)[v4](https://developers-pay.line.me/online-api-v4)[v4](https://developers-pay.line.me/offline-api-v4)[v3.9](https://github.com/yidas/line-pay-sdk-php/tree/3.9.0)[v4](https://developers-pay.line.me/online-api-v4)[v2.4](https://developers-pay.line.me/offline-api-v2_4)[v3](https://github.com/yidas/line-pay-sdk-php/tree/3.8.0)[v3](https://pay.line.me/tw/developers/apis/onlineApis?locale=en_US)[v2](https://pay.line.me/tw/developers/apis/documentOffline?locale=en_US)[v2](https://github.com/yidas/line-pay-sdk-php/tree/v2)[v2](https://pay.line.me/documents/online_v2_en.html)[v2](https://pay.line.me/tw/developers/apis/documentOffline?locale=en_US)OUTLINE
-------

[](#outline)

- [Demonstration](#demonstration)
- [Requirements](#requirements)
    - [Authentication](#authentication)
- [Installation](#installation)
- [Usage](#usage)
    - [Client](#client)
        - [Device Information](#device-information)
    - [Response](#response)
        - [Retrieving Data](#retrieving-data)
            - [Retrieving as Object](#retrieving-as-object)
            - [Retrieving as Array](#retrieving-as-array)
        - [Methods](#methods)
            - [isSuccessful()](#issuccessful)
            - [getPaymentUrl()](#getpaymenturl)
            - [getPayInfo()](#getpayinfo)
            - [toArray()](#toarray)
            - [toObject()](#toobject)
            - [getStats()](#getstats)
    - [Online APIs](#online-apis)
        - [Payment Details API](#payment-details-api)
        - [Request API](#request-api)
        - [Confirm API](#confirm-api)
        - [Refund API](#refund-api)
        - [Check Payment Status API](#check-payment-status-api)
        - [Capture API](#capture-api)
        - [Void API](#void-api)
        - [Pay Preapproved API](#pay-preapproved-api)
        - [Check RegKey API](#check-regkey-api)
        - [Expire RegKey API](#expire-regkey-api)
    - [Offline APIs](#offline-apis)
        - [Payment](#payment)
        - [Payment Status Check](#payment-status-check)
        - [Void](#void)
        - [Capture](#capture)
        - [Refund](#refund)
        - [Authorization Details](#authorization-details)
    - [Exceptions](#exceptions)
        - [ConnectException](#connectException)
- [Resources](#resources)
- [References](#references)

---

DEMONSTRATION
-------------

[](#demonstration)

[Sample Codes Site for LINE Pay (Request, Confirm, Refund)](https://github.com/yidas/line-pay-sdk-php/tree/v3/sample)

```
// Create LINE Pay client
$linePay = new \yidas\linePay\Client([
    'channelId' => 'Your merchant X-LINE-ChannelId',
    'channelSecret' => 'Your merchant X-LINE-ChannelSecret',
    'isSandbox' => true,
]);

// Online Request API
$response = $linePay->request([
    'amount' => 250,
    'currency' => 'TWD',
    'orderId' => 'Your order ID',
    'packages' => [
        [
            'id' => 'Your package ID',
            'amount' => 250,
            'name' => 'Your package name',
            'products' => [
                [
                    'name' => 'Your product name',
                    'quantity' => 1,
                    'price' => 250,
                    'imageUrl' => 'https://yourname.com/assets/img/product.png',
                ],
            ],
        ],
    ],
    'redirectUrls' => [
        'confirmUrl' => 'https://yourname.com/line-pay/confirm',
        'cancelUrl' => 'https://yourname.com/line-pay/cancel',
    ],
]);

// Check Request API result (returnCode "0000" check method)
if (!$response->isSuccessful()) {
    throw new Exception("ErrorCode {$response['returnCode']}: {$response['returnMessage']}");
}

// Redirect to LINE Pay payment URL
header('Location: '. $response->getPaymentUrl() );
```

> [LINE Pay API Tool for testing and loging APIs](https://github.com/yidas/line-pay-sdk-php/tree/v3/tool)

---

REQUIREMENTS
------------

[](#requirements)

This library requires the following:

- PHP 5.4.0+|7.0+
- guzzlehttp/guzzle 5.3.1+|6.0+
- [LINE Pay merchant authentication](#authentication)

### Authentication

[](#authentication)

Each LINE Pay merchant Requires authentication information for LINE Pay integration, as shown below:

- channel ID
- channel Secret

To get an LINE Pay Authentication:

1. Merchant's verification information can be viewed at [LINE Pay Merchant Center](http://pay.line.me) after evaluation process is complete.
2. Login into [LINE Pay Merchant Center](http://pay.line.me), then **get the ChannelId/ChannelSecret** (Payment Integration Management &gt; Manage Link Key).
3. In [LINE Pay Merchant Center](http://pay.line.me), **set IP white list** for your servers (Payment Integration Management &gt; Manage Payment Server IP) *(v3 is not required)*.

> You can immediately create a sandbox merchant account for test through [LINE Pay Sandbox Creation](https://pay.line.me/tw/developers/techsupport/sandbox/creation?locale=en_US).

---

INSTALLATION
------------

[](#installation)

Run Composer in your project:

```
composer require yidas/line-pay-sdk ~3.0.0

```

Then you could use SDK class after Composer is loaded on your PHP project:

```
require __DIR__ . '/vendor/autoload.php';

use yidas\linePay\Client;
```

---

USAGE
-----

[](#usage)

Before using any API methods, first you need to create a Client with configuration, then use the client to access LINE Pay API methods.

### Client

[](#client)

Create a LINE Pay Client with [API Authentication](#authentication):

```
$linePay = new \yidas\linePay\Client([
    'channelId' => 'Your merchant X-LINE-ChannelId',
    'channelSecret' => 'Your merchant X-LINE-ChannelSecret',
    'isSandbox' => true,
]);
```

#### Device Information

[](#device-information)

You could set device information for Client (Optional):

```
$linePay = new \yidas\linePay\Client([
    'channelId' => 'Your merchant X-LINE-ChannelId',
    'channelSecret' => 'Your merchant X-LINE-ChannelSecret',
    'isSandbox' => true,
    'merchantDeviceType' => 'Device type string',
    'merchantDeviceProfileId' => 'Device profile ID string',
]);
```

### Response

[](#response)

Each API methods will return `yidas\linePay\Response` object, which can retrieve data referred to LINE Pay JSON response data structure.

#### Retrieving Data

[](#retrieving-data)

Response object provides response body data accessing by object attributes or array keys:

##### Retrieving as Object

[](#retrieving-as-object)

```
// Get object of response body
$bodyObject = response->toObject();
// Get LINE Pay results code from response
$returnCode = $response->returnCode;
// Get LINE Pay info.payInfo[] from response
$payInfo = $response->info->payInfo;
```

##### Retrieving as Array

[](#retrieving-as-array)

```
// Get array of response body
$bodyArray = response->toArray();
// Get LINE Pay results code from response
$returnCode = $response['returnCode'];
// Get LINE Pay info.payInfo[] from response
$payInfo = $response['info']['payInfo'];
```

#### Methods

[](#methods)

Response object has some helpful methods to use:

##### isSuccessful()

[](#issuccessful)

LINE Pay API result successful status (Check that returnCode is "0000")

*Example:*

```
if (!$response->isSuccessful()) {

    throw new Exception("Code {$response['returnCode']}: {$response['returnMessage']}");
}
```

##### getPaymentUrl()

[](#getpaymenturl)

Get LINE Pay API response body's info.paymentUrl (Default type is "web")

##### getPayInfo()

[](#getpayinfo)

Get LINE Pay API response body's info.payInfo\[\] or info.\[$param1\].payInfo\[\] as array

##### toArray()

[](#toarray)

Get LINE Pay response body as array

##### toObject()

[](#toobject)

Get LINE Pay response body as object

##### getStats()

[](#getstats)

Get `\GuzzleHttp\TransferStats` object

### Online APIs

[](#online-apis)

For Web integration. Merchant will requests a payment and generates payment URL(QR code) to customer to scan by LINE App.

> Flow: [`Request`](#request-api) -&gt; [`Confirm`](#confirm-api) -&gt; [`Details`](#payment-details-api) -&gt; [`Refund`](#refund-api)

[![Flow](https://camo.githubusercontent.com/dec748b8754f32ede3315cddde45b3fcff495334c8f9f72f66766dc1ce48e7c4/68747470733a2f2f646576656c6f706572732d7061792e6c696e652e6d652f6173736574732f696d616765732f62617369632d7061796d656e742d776f726b666c6f772d39346235353063666230633938663766663165323863616430636633383466362e737667)](https://camo.githubusercontent.com/dec748b8754f32ede3315cddde45b3fcff495334c8f9f72f66766dc1ce48e7c4/68747470733a2f2f646576656c6f706572732d7061792e6c696e652e6d652f6173736574732f696d616765732f62617369632d7061796d656e742d776f726b666c6f772d39346235353063666230633938663766663165323863616430636633383466362e737667)

#### Payment Details API

[](#payment-details-api)

Gets the details of payments made with LINE Pay. This API only gets the payments that have been captured.

```
public Response details(array $queryParams=null)
```

*Example:*

```
$response = $linePay->details([
    "transactionId" => [$transactionId],
]);
```

#### Request API

[](#request-api)

Prior to processing payments with LINE Pay, the Merchant is evaluated if it is a normal Merchant store then the information is requested for payment. When a payment is successfully requested, the Merchant gets a "transactionId" that is a key value used until the payment is completed or refunded.

```
public Response request(array $bodyParams=null)
```

*Example:*

```
$response = $linePay->request([
    'amount' => 250,
    'currency' => 'TWD',
    'orderId' => 'Your order ID',
    'packages' => [
        [
            'id' => 'Your package ID',
            'amount' => 250,
            'name' => 'Your package name',
            'products' => [
                [
                    'name' => 'Your product name',
                    'quantity' => 1,
                    'price' => 250,
                    'imageUrl' => 'https://yourname.com/assets/img/product.png',
                ],
            ],
        ],
    ],
    'redirectUrls' => [
        'confirmUrl' => 'https://yourname.com/line-pay/confirm',
        'cancelUrl' => 'https://yourname.com/line-pay/cancel',
    ],
]);
```

> The `$bodyParams` specification can be referred to [Request API v3 Request Body](https://pay.line.me/documents/online_v3_en.html#request-api)

#### Confirm API

[](#confirm-api)

This API is used for a Merchant to complete its payment. The Merchant must call Confirm Payment API to actually complete the payment. However, when "capture" parameter is "false" on payment reservation, the payment status becomes AUTHORIZATION, and the payment is completed only after "Capture API" is called.

```
public Response confirm(integer $transactionId, array $bodyParams=null)
```

*Example:*

```
try {

    $response = $linePay->confirm($transactionId, [
        "amount" => 250,
        "currency" => 'TWD',
    ]);

} catch (\yidas\linePay\exception\ConnectException $e) {
    // Timeout error handling such as re-checking
}
```

#### Refund API

[](#refund-api)

Requests refund of payments made with LINE Pay. To refund a payment, the LINE Pay user's payment transactionId must be forwarded. A partial refund is also possible depending on the refund amount.

```
public Response refund(integer $transactionId, array $bodyParams=null)
```

*Example:*

```
try {

    $response = $linePay->refund($transactionId);

} catch (\yidas\linePay\exception\ConnectException $e) {
    // Timeout error handling such as retrying
}
```

*For Partial refund:*

```
$response = $linePay->refund($transactionId, [
    'refundAmount' => 200,
]);
```

#### Check Payment Status API

[](#check-payment-status-api)

An API to check payment request status of LINE Pay. The merchant should regularly check user payment confirm status **without using the ConfirmURL** and decide if it is possible to complete the payment.

```
public Response check(integer $transactionId)
```

*Example:*

```
$response = $linePay->check($transactionId);
```

#### Capture API

[](#capture-api)

If "capture" is "false" when the Merchant calls the “Request API” , the payment is completed only after the Capture API is called.

```
public Response capture(integer $transactionId, array $bodyParams=null)
```

*Example:*

```
try {

    $response = $linePay->capture($transactionId, [
        "amount" => 250,
        "currency" => 'TWD',
    ]);

} catch (\yidas\linePay\exception\ConnectException $e) {
    // Timeout error handling such as retrying
}
```

#### Void API

[](#void-api)

Voids a previously authorized payment. A payment that has been already captured can be refunded by using the “Refund API”.

```
public Response void(integer $transactionId, array $bodyParams=null)
```

*Example:*

```
$response = $linePay->void($transactionId);
```

#### Pay Preapproved API

[](#pay-preapproved-api)

When the payment type of the Request API was set as PREAPPROVED, a regKey is returned with the payment result. Pay Preapproved API uses this regKey to directly complete a payment without using the LINE app.

```
public Response preapproved(integer $regKey, array $bodyParams=null)
```

*Example:*

```
$response = $linePay->preapproved([
    'productName' => 'Your product name',
    'amount' => 250,
    'currency' => 'TWD',
    'orderId' => 'Your order ID',
]);
```

#### Check RegKey API

[](#check-regkey-api)

Checks if regKey is available before using the preapproved payment API.

```
public Response preapprovedCheck(integer $regKey, array $queryParams=null)
```

*Example:*

```
$response = $linePay->preapprovedCheck($regKey);
```

#### Expire RegKey API

[](#expire-regkey-api)

Expires the regKey information registered for preapproved payment. Once the API is called, the regKey is no longer used for preapproved payments.

```
public Response preapprovedExpire(integer $regKey, array $bodyParams=null)
```

*Example:*

```
$response = $linePay->preapprovedExpire($regKey);
```

### Offline APIs

[](#offline-apis)

For POS integration. Customer presents their barcode or QR code to merchants to scan at the POS machine.

> Flow: [`OneTimeKeysPay`](#payment) -&gt; [`OrdersCheck`](#payment-status-check) -&gt; [`OrdersRefund`](#refund)

[![Flow](https://camo.githubusercontent.com/e9742db99bd914269b7d7a69063997b37584912ed816eef6225c7c11f42ce337/68747470733a2f2f646576656c6f706572732d7061792e6c696e652e6d652f6173736574732f696d616765732f7061796d656e742d776f726b666c6f772d37656235336538643538376663373037396432336335356165316339653639642e737667)](https://camo.githubusercontent.com/e9742db99bd914269b7d7a69063997b37584912ed816eef6225c7c11f42ce337/68747470733a2f2f646576656c6f706572732d7061792e6c696e652e6d652f6173736574732f696d616765732f7061796d656e742d776f726b666c6f772d37656235336538643538376663373037396432336335356165316339653639642e737667)

#### Payment

[](#payment)

This API is to process payment by reading MyCode provided from LINE Pay App with Merchant's device.

```
public Response oneTimeKeysPay(array $bodyParams=null)
```

*Example:*

```
try {

    $response = $linePay->oneTimeKeysPay([
        'productName' => 'Your product name',
        'amount' => 250,
        'currency' => 'TWD',
        'productImageUrl' => 'https://yourname.com/assets/img/product.png',
        'orderId' => 'Your order ID',
        "oneTimeKey"=> 'LINE Pay MyCode',
    ]);

} catch (\yidas\linePay\exception\ConnectException $e) {
    // Timeout error handling such as re-checking
}
```

#### Payment Status Check

[](#payment-status-check)

It's the API used when the final payment status can't be checked due to read timeout.

- The status needs to be checked by calling it at regular intervals and 3~5 seconds are recommended for the interval time.
- Payment valid time is maximum 20 minutes and it's calculated from the Payment API Response time. Therefore, a merchant should check the payment status for maximum 20 minutes. In case 20 minutes are exceeded, that transaction will be the payment that couldn't be completed due to exceeded valid time.

```
public Response ordersCheck(string $orderId, array $$queryParams=null)
```

*Example:*

```
$response = $linePay->ordersCheck($orderId);
```

#### Void

[](#void)

This API is to void the authorization.

```
public Response ordersVoid(string $orderId, array $bodyParams=null)
```

*Example:*

```
$response = $linePay->ordersVoid($orderId);
```

#### Capture

[](#capture)

This API is to capture the authorized transaction.

```
public Response ordersCapture(string $orderId, array $bodyParams=null)
```

*Example:*

```
try {

    $response = $linePay->ordersCapture($orderId);

} catch (\yidas\linePay\exception\ConnectException $e) {
    // Timeout error handling such as retrying
}
```

#### Refund

[](#refund)

This API is to refund after the payment completion (Captured data).

```
public Response ordersRefund(string $orderId, array $bodyParams=null)
```

*Example:*

```
try {

    $response = $linePay->ordersRefund($orderId);

} catch (\yidas\linePay\exception\ConnectException $e) {
    // Timeout error handling such as retrying
}
```

#### Authorization Details

[](#authorization-details)

This API is to search the authorization details. Only authorized or cancelled (Void or Expire) data can be searched and the data after capturing can be searched by The Payment Details API.

```
public Response authorizations(array $queryParams=null)
```

*Example for searching transactionId:*

```
$response = $linePay->authorizations([
    "transactionId" => [$transactionId],
]);
```

*Example for searching orderId:*

```
$response = $linePay->authorizations([
    "orderId" => $orderId,
]);
```

---

EXCEPTIONS
----------

[](#exceptions)

Client throws exceptions for errors that occur during a API transaction.

### ConnectException

[](#connectexception)

A `yidas\linePay\exception\ConnectException` exception is thrown in the event of a networking error (Timeout).

```
try {

    $response = $linePay->confirm($transactionId, $bodyParams);

} catch (\yidas\linePay\exception\ConnectException $e) {

    // Process of confirm API timeout handling
}
```

---

RESOURCES
---------

[](#resources)

**[LINE Pay Online API v3 Guide (EN)](https://pay.line.me/tw/developers/apis/onlineApis?locale=en_US)**

**[LINE Pay Offline API v2 Guide (EN)](https://pay.line.me/tw/developers/apis/documentOffline?locale=en_US)**

[LINE Pay Sandbox creation](https://pay.line.me/tw/developers/techsupport/sandbox/creation?locale=en_US)

[LINE Pay OneTimeKeys Simulation](https://sandbox-web-pay.line.me/web/sandbox/payment/otk)

[LINE Pay OneTimeKeys Simulation (For TW Merchant)](https://sandbox-web-pay.line.me/web/sandbox/payment/oneTimeKey?countryCode=TW&paymentMethod=card&preset=1)

[LINE Pay Online API v2 Documents PDF version (Multi-language)](https://pay.line.me/tw/developers/documentation/download/tech?locale=en_US)

---

REFERENCES
----------

[](#references)

[LINE Pay Developers - APIs](https://pay.line.me/tw/developers/apis/apis?locale=en_US)

[LINE Pay API (v3) sample codes in multi-languages](https://gist.github.com/yidas/08c0f7009a72102df3b57fcbe3da6681)

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance74

Regular maintenance activity

Popularity44

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 99.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~91 days

Recently: every ~101 days

Total

27

Last Release

141d ago

Major Versions

1.0.1 → 2.0.02019-06-27

2.0.0 → 3.0.02019-07-10

v2.x-dev → 3.5.22021-08-03

3.9.0 → 4.0.02025-12-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/b30d2b2c0b53aef65fad4af56cd3c7912d3db2b612890c706fe79448717f6aba?d=identicon)[yidas](/maintainers/yidas)

---

Top Contributors

[![yidas](https://avatars.githubusercontent.com/u/12604195?v=4)](https://github.com/yidas "yidas (124 commits)")[![MilesChou](https://avatars.githubusercontent.com/u/1258752?v=4)](https://github.com/MilesChou "MilesChou (1 commits)")

---

Tags

apiline-payline-sdksdk-phpphpapisdkline payLINE SDK

### Embed Badge

![Health badge](/badges/yidas-line-pay-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/yidas-line-pay-sdk/health.svg)](https://phpackages.com/packages/yidas-line-pay-sdk)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)[php-opencloud/openstack

PHP SDK for OpenStack APIs. Supports BlockStorage, Compute, Identity, Images, Networking and Metric Gnocchi

2292.2M24](/packages/php-opencloud-openstack)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[resend/resend-php

Resend PHP library.

574.7M21](/packages/resend-resend-php)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

553.3M7](/packages/checkout-checkout-sdk-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
