onepay/laravel-checkout
Composer 安装命令:
composer require onepay/laravel-checkout
包简介
Laravel integration for the OnePay Checkout Link API
README 文档
README
Laravel · OnePay · Checkout Link API
OnePay Checkout for Laravel
Server-side Laravel integration for the OnePay Checkout Link API (api.onepay.lk) — create payment links with correct SHA-256 hashing, validation, and structured error handling.
Getting started
The steps below work with Laravel 10.x, 11.x, and 12.x (PHP 8.1+).
Laravel auto-discovers the package: you do not need to register the service provider manually unless you disabled discovery.
Install
Install the package with Composer:
composer require onepay/laravel-checkout
Configure
Publish the configuration file:
php artisan vendor:publish --tag=onepay-config
This creates config/onepay.php. Set your server-side only secrets in .env (never expose these in frontend or mobile apps):
ONEPAY_APP_ID=your-app-id-here ONEPAY_APP_TOKEN=your-app-token-here ONEPAY_HASH_SALT=your-hash-salt-here
The API base URL is fixed in config/onepay.php (https://api.onepay.lk/v3) and is not read from .env, so it cannot be overridden from client input.
Usage
Dependency injection (recommended)
Inject OnePay\Checkout\Services\OnePayService into your controller or action:
use OnePay\Checkout\Services\OnePayService; use OnePay\Checkout\Exceptions\OnePayException; public function pay(OnePayService $onePay) { try { $response = $onePay->createCheckoutLink([ 'reference' => 'ORD-' . $order->id, // required — your unique transaction reference 'currency' => 'LKR', // required — 3-letter ISO code (e.g. from config('onepay.currency')) 'amount' => 200.00, 'customer_first_name' => 'John', 'customer_last_name' => 'Doe', 'customer_phone_number' => '+94771234567', 'customer_email' => 'john@example.com', 'transaction_redirect_url' => 'https://yoursite.test/payment/return', // optional: // 'additionalData' => 'extra context for the transaction', // 'items' => ['item_id_1', 'item_id_2'], ]); if (! $response->succeeded()) { // Handle logical failure using $response->rawResponse } return redirect()->away($response->redirectUrl); } catch (OnePayException $e) { if ($e->hasRemoteErrorPayload()) { // OnePay JSON: message + error — see $e->getRemoteMessage(), getRemoteError() } throw $e; } }
Facade
use OnePay\Checkout\Facades\OnePay; $response = OnePay::createCheckoutLink([ 'reference' => OnePay::generateReference('INV'), 'currency' => 'LKR', 'amount' => 1500, 'customer_first_name' => 'Jane', 'customer_last_name' => 'Doe', 'customer_phone_number' => '+94770000000', 'customer_email' => 'jane@example.com', 'transaction_redirect_url' => 'https://yoursite.test/done', ]);
Request fields
| Field | Required | Description |
|---|---|---|
reference |
Yes | Unique transaction reference (10–64 characters). Use your order id or generateReference(). |
amount |
Yes | Amount; normalised to 2 decimals for hashing and the API. |
customer_first_name |
Yes | |
customer_last_name |
Yes | |
customer_phone_number |
Yes | |
customer_email |
Yes | |
transaction_redirect_url |
Yes | Return URL after payment. |
currency |
Yes | Exactly 3 characters (e.g. LKR). Often config('onepay.currency'). |
additionalData |
No | Any extra string metadata for the transaction (API key: additionalData). |
items |
No | Array of created item ids (numeric ids are sent as strings in JSON). |
Response object
createCheckoutLink() returns OnePay\Checkout\DTOs\CheckoutResponse:
| Property / method | Description |
|---|---|
reference |
Same reference you passed in (echo from your payload) |
hash |
SHA-256 sent to the API |
redirectUrl |
Gateway URL to send the customer to |
rawResponse |
Decoded JSON from OnePay |
succeeded() |
Helper for success-style payloads |
toArray() |
Array for JSON APIs |
Hash rules (OnePay requirement)
The package normalises amount to two decimal places and builds:
sha256(app_id + currency + amount + hash_salt) → lowercase hex.
Laravel version compatibility
| Laravel | PHP | Package status |
|---|---|---|
| 12.x | ≥ 8.1 | Supported |
| 11.x | ≥ 8.1 | Supported |
| 10.x | ≥ 8.1 | Supported |
| 9.x | — | Not supported |
Security
- Keep
ONEPAY_APP_TOKENandONEPAY_HASH_SALTonly on the server. - Validate and allowlist
transaction_redirect_urlif it can be influenced by end users (open-redirect risk). - Confirm paid orders using OnePay’s official callback / status flows — this package covers checkout link creation only.
License
This package is open-sourced software licensed under the MIT license.
Links
- Packagist —
onepay/laravel-checkout - OnePay API base:
https://api.onepay.lk/v3/checkout/link/
onepay/laravel-checkout 适用场景与选型建议
onepay/laravel-checkout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「checkout」 「laravel」 「onepay」 「sri-lanka」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 onepay/laravel-checkout 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 onepay/laravel-checkout 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 onepay/laravel-checkout 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Adds a 'checkout' to a SilverStripe site which links to an Estimate and adds the ability to setup and pay
Rich payment solutions for Laravel framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
Add a simple webshop to your Laravel project
Alfabank REST API integration
Customer notes for Contao Isotope eCommerce checkout.
Cliente em PHP para integração server-side com APIs Moip v2
统计信息
- 总下载量: 66
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-08