carllee/line-pay-online-v4
Composer 安装命令:
composer require carllee/line-pay-online-v4
包简介
LINE Pay Online V4 API SDK for PHP. Type-safe, PSR-4 compliant, with Builder Pattern and Laravel support.
关键字:
README 文档
README
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 | 繁體中文 | 日本語 | ภาษาไทย
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
- PHP 8.1 or higher
- Composer
- ext-json
- ext-openssl
Installation
composer require carllee/line-pay-online-v4
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
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
The package supports Laravel Package Discovery. Just install it via composer, and the ServiceProvider and Facade will be registered automatically.
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
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
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
Request Payment
$response = $client->payment() ->setAmount(1000) ->setCurrency(Currency::TWD) ->setOrderId('ORDER-001') ->addPackage($package) ->setRedirectUrls($confirmUrl, $cancelUrl) ->send();
Confirm Payment
$response = $client->confirm( transactionId: '1234567890123456789', amount: 1000, currency: Currency::TWD );
Capture Payment
$response = $client->capture( transactionId: '1234567890123456789', amount: 1000, currency: Currency::TWD );
Void Payment
$response = $client->void('1234567890123456789');
Refund Payment
// Full refund $response = $client->refund('1234567890123456789'); // Partial refund $response = $client->refund('1234567890123456789', 500);
Get Payment Details
$response = $client->getDetails( transactionIds: ['1234567890123456789'], orderIds: ['ORDER-001'] );
Check Payment Status
$response = $client->checkStatus('1234567890123456789');
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 & Troubleshooting
🚫 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)
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
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
composer install
composer test
composer analyze
Related Packages
carllee/line-pay-core-v4- Core SDK (dependency)carllee/line-pay-offline-v4- Offline Payment SDK
License
MIT License - see LICENSE for details.
Resources
carllee/line-pay-online-v4 适用场景与选型建议
carllee/line-pay-online-v4 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「ecommerce」 「api」 「payment」 「sdk」 「line」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 carllee/line-pay-online-v4 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 carllee/line-pay-online-v4 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 carllee/line-pay-online-v4 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nevogate Payment Gateway SDK
Dealing with payments through the Egyptian payment gateway PayMob
A PSR-7 compatible library for making CRUD API endpoints
A PHP (and Laravel) package to interface with the Snipcart api.
Alfabank REST API integration
Customer notes for Contao Isotope eCommerce checkout.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-11