1. Go to this page and download the library: Download carllee/line-pay-online-v4 library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
carllee / line-pay-online-v4 example snippets
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'];
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']);
}
}