PHPackages                             carllee/line-pay-online-v4 - 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. carllee/line-pay-online-v4

ActiveLibrary[API Development](/categories/api)

carllee/line-pay-online-v4
==========================

LINE Pay Online V4 API SDK for PHP. Type-safe, PSR-4 compliant, with Builder Pattern and Laravel support.

v1.2.3(2mo ago)00[1 PRs](https://github.com/CarlLee1983/line-pay-online-v4/pulls)MITPHPPHP ^8.1CI passing

Since Dec 11Pushed 1mo agoCompare

[ Source](https://github.com/CarlLee1983/line-pay-online-v4)[ Packagist](https://packagist.org/packages/carllee/line-pay-online-v4)[ Docs](https://github.com/CarlLee1983/line-pay-online-v4-php)[ RSS](/packages/carllee-line-pay-online-v4/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (8)Used By (0)

LINE Pay Online V4 PHP SDK
==========================

[](#line-pay-online-v4-php-sdk)

[![CI](https://github.com/CarlLee1983/line-pay-online-v4-php/actions/workflows/ci.yml/badge.svg)](https://github.com/CarlLee1983/line-pay-online-v4-php/actions/workflows/ci.yml)[![PHP Version](https://camo.githubusercontent.com/5236ef53d78aa626da713885a8d77dd1c52df5e5f4922d56c994b77ba34c86be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6361726c6c65652f6c696e652d7061792d6f6e6c696e652d7634)](https://packagist.org/packages/carllee/line-pay-online-v4)[![License](https://camo.githubusercontent.com/ef82c2e3596face6a51f4e2af81b132c56933eb1758eddb59f6f7fd0ed120af3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4361726c4c6565313938332f6c696e652d7061792d6f6e6c696e652d76342d706870)](LICENSE)

**PHP SDK for LINE Pay Online API V4.**A type-safe, strictly typed library featuring a **Fluent Builder** for constructing complex payment requests. Native support for **Laravel** with auto-discovery and Facades.

**🌐 Language / 語言 / 言語 / ภาษา:**[English](./README.md) | [繁體中文](./README_ZH.md) | [日本語](./README_JA.md) | [ภาษาไทย](./README_TH.md)

Features
--------

[](#features)

- ✅ **PHP 8.1+** with strict types
- ✅ **Laravel Integration** - ServiceProvider, Facade, IoC support
- ✅ **Builder Pattern** for request construction
- ✅ **Type-safe Enums** for currencies and options
- ✅ **Comprehensive Validation** before API calls
- ✅ **PHPStan Level Max** static analysis
- ✅ Built on `carllee/line-pay-core-v4`

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer
- ext-json
- ext-openssl

Installation
------------

[](#installation)

```
composer require carllee/line-pay-online-v4
```

Payment Flow
------------

[](#payment-flow)

 ```
sequenceDiagram
    participant U as User (Browser)
    participant S as Merchant Server
    participant L as LINE Pay API

    U->>S: 1. Checkout (Click Pay)
    S->>L: POST /v3/payments/request
    L-->>S: Returns paymentUrl (Web/App)
    S-->>U: 302 Redirect to paymentUrl

    Note over U,L: User approves payment on LINE App/Web

    L-->>U: Redirect to confirmUrl (with transactionId)
    U->>S: GET /payment/confirm?transactionId=...
    S->>L: POST /v3/payments/{id}/confirm
    L-->>S: 200 OK (Payment Complete)
    S-->>U: Show Success Page
```

      Loading Quick Start
-----------

[](#quick-start)

### Standard PHP Usage

[](#standard-php-usage)

```
use LinePay\Core\Config\LinePayConfig;
use LinePay\Online\LinePayClient;
use LinePay\Online\Domain\PaymentPackage;
use LinePay\Online\Domain\PaymentProduct;
use LinePay\Online\Enums\Currency;

// Create configuration
$config = new LinePayConfig(
    channelId: getenv('LINE_PAY_CHANNEL_ID'),
    channelSecret: getenv('LINE_PAY_CHANNEL_SECRET'),
    env: 'sandbox'
);

// Create client
$client = new LinePayClient($config);

// Create a package with products
$package = new PaymentPackage(id: 'PKG-001', amount: 1000);
$package->addProduct(new PaymentProduct(
    name: 'Product Name',
    quantity: 1,
    price: 1000
));

// Request payment using Builder Pattern
$response = $client->payment()
    ->setAmount(1000)
    ->setCurrency(Currency::TWD)
    ->setOrderId('ORDER-' . time())
    ->addPackage($package)
    ->setRedirectUrls(
        'https://example.com/confirm',
        'https://example.com/cancel'
    )
    ->send();

// Get payment URL
$paymentUrl = $response['info']['paymentUrl']['web'];
```

Laravel Integration
-------------------

[](#laravel-integration)

The package supports **Laravel Package Discovery**. Just install it via composer, and the ServiceProvider and Facade will be registered automatically.

### Configuration

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --tag=linepay-config
```

Add to your `.env`:

```
LINE_PAY_CHANNEL_ID=your-channel-id
LINE_PAY_CHANNEL_SECRET=your-channel-secret
LINE_PAY_ENV=sandbox
LINE_PAY_TIMEOUT=20
```

### Using Dependency Injection

[](#using-dependency-injection)

```
namespace App\Http\Controllers;

use LinePay\Online\LinePayClient;
use LinePay\Online\Domain\PaymentPackage;
use LinePay\Online\Enums\Currency;

class PaymentController extends Controller
{
    public function __construct(
        private LinePayClient $linePay
    ) {}

    public function createPayment()
    {
        $package = new PaymentPackage(id: 'PKG-001', amount: 1000);

        $response = $this->linePay->payment()
            ->setAmount(1000)
            ->setCurrency(Currency::TWD)
            ->setOrderId('ORDER-' . time())
            ->addPackage($package)
            ->setRedirectUrls(
                route('payment.confirm'),
                route('payment.cancel')
            )
            ->send();

        return redirect($response['info']['paymentUrl']['web']);
    }
}
```

### Using Facade

[](#using-facade)

```
use LinePay\Online\Laravel\LinePay;
use LinePay\Online\Enums\Currency;

// Confirm payment
$response = LinePay::confirm(
    transactionId: $request->input('transactionId'),
    amount: 1000,
    currency: 'TWD'
);

// Refund
$response = LinePay::refund($transactionId, 500);
```

API Methods
-----------

[](#api-methods)

### Request Payment

[](#request-payment)

```
$response = $client->payment()
    ->setAmount(1000)
    ->setCurrency(Currency::TWD)
    ->setOrderId('ORDER-001')
    ->addPackage($package)
    ->setRedirectUrls($confirmUrl, $cancelUrl)
    ->send();
```

### Confirm Payment

[](#confirm-payment)

```
$response = $client->confirm(
    transactionId: '1234567890123456789',
    amount: 1000,
    currency: Currency::TWD
);
```

### Capture Payment

[](#capture-payment)

```
$response = $client->capture(
    transactionId: '1234567890123456789',
    amount: 1000,
    currency: Currency::TWD
);
```

### Void Payment

[](#void-payment)

```
$response = $client->void('1234567890123456789');
```

### Refund Payment

[](#refund-payment)

```
// Full refund
$response = $client->refund('1234567890123456789');

// Partial refund
$response = $client->refund('1234567890123456789', 500);
```

### Get Payment Details

[](#get-payment-details)

```
$response = $client->getDetails(
    transactionIds: ['1234567890123456789'],
    orderIds: ['ORDER-001']
);
```

### Check Payment Status

[](#check-payment-status)

```
$response = $client->checkStatus('1234567890123456789');
```

Error Handling
--------------

[](#error-handling)

```
use LinePay\Core\Errors\LinePayError;
use LinePay\Core\Errors\LinePayTimeoutError;
use LinePay\Core\Errors\LinePayValidationError;

try {
    $response = $client->confirm($transactionId, 1000, Currency::TWD);
} catch (LinePayValidationError $e) {
    // Validation error (before API call)
    echo "Validation Error: " . $e->getMessage();
} catch (LinePayTimeoutError $e) {
    // Request timeout
    echo "Timeout after " . $e->getTimeout() . " seconds";
} catch (LinePayError $e) {
    // API error
    echo "Error Code: " . $e->getReturnCode();
    echo "Error Message: " . $e->getReturnMessage();
}
```

Common Pitfalls &amp; Troubleshooting
-------------------------------------

[](#common-pitfalls--troubleshooting)

### 🚫 Double Confirmation (Error 1198)

[](#-double-confirmation-error-1198)

Each `transactionId` can only be confirmed **once**.

- If users refresh the success page, your server might try to confirm again.
- **Solution:** Check your local database order status *before* calling `$client->confirm()`. If it's already "PAID", skip the API call.

```
// In your confirm callback handler
$order = Order::where('transaction_id', $transactionId)->first();

if ($order->status === 'PAID') {
    // Already confirmed, just show success page
    return redirect()->route('payment.success');
}

// Only call confirm if not yet paid
$response = $client->confirm($transactionId, $order->amount, Currency::TWD);
$order->update(['status' => 'PAID']);
```

### 💰 Amount Mismatch (Error 1106)

[](#-amount-mismatch-error-1106)

The amount passed to `confirm()` must match the amount requested exactly.

- **Tip:** Do not trust the amount in the URL query string (if any). Always retrieve the amount from your own database using the `orderId`.

```
// ✗ BAD: Using amount from query string
$amount = $request->input('amount'); // Vulnerable!

// ✓ GOOD: Using amount from database
$order = Order::findOrFail($orderId);
$amount = $order->amount;
```

### ⏱️ Transaction Expiration

[](#️-transaction-expiration)

The `paymentUrl` and `transactionId` have an expiration time (usually 20 minutes). If the user takes too long, the confirm call will fail.

- Store the expiration time and show a countdown to the user.
- Handle the expiration error gracefully and allow the user to restart the payment.

Testing
-------

[](#testing)

```
composer install
composer test
composer analyze
```

Related Packages
----------------

[](#related-packages)

- [`carllee/line-pay-core-v4`](https://github.com/CarlLee1983/line-pay-core-v4-php) - Core SDK (dependency)
- [`carllee/line-pay-offline-v4`](https://github.com/CarlLee1983/line-pay-offline-v4-php) - Offline Payment SDK

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) for details.

Resources
---------

[](#resources)

- [LINE Pay API Documentation](https://pay.line.me/documents/online_v3_en.html)
- [LINE Pay Merchant Center](https://pay.line.me/portal/tw/)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance89

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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 ~16 days

Total

6

Last Release

71d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cc3f5bb28af8b207b65843e86f3b3e9feb1efd05b8ba888e1fa223a370ab822?d=identicon)[Carl Lee](/maintainers/Carl%20Lee)

---

Top Contributors

[![CarlLee1983](https://avatars.githubusercontent.com/u/8252510?v=4)](https://github.com/CarlLee1983 "CarlLee1983 (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

---

Tags

phpapilaravelsdkpaymentecommercejapanpayment gatewaylinepayTaiwanthailandfintechlineline pay

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/carllee-line-pay-online-v4/health.svg)

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

###  Alternatives

[wallee/sdk

wallee SDK for PHP

12354.2k11](/packages/wallee-sdk)

PHPackages © 2026

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