ninepay-gateway/rest-client-php
Composer 安装命令:
composer require ninepay-gateway/rest-client-php
包简介
Official PHP SDK for 9PAY Payment Gateway
README 文档
README
Official PHP SDK for integrating 9PAY Payment Gateway.
Supports PHP Native, Laravel, and Lumen.
Features
The SDK currently supports:
- Create payment request
- Query transaction status
- Verify webhook / callback signature
- Refund transaction
- Payer authentication for installment payments
- Credit card authorization
- Capture authorized payment
- Reverse authorization
- Strong typed request objects
- Laravel & Lumen integration
- OOP & SOLID compliant architecture
Table of Contents
- Requirements
- Installation
- Configuration
- PHP Native
- Laravel
- Lumen
- Usage
- Initialization
- Create Payment
- Query Transaction
- Verify Webhook
- Refund Transaction
- Payer Authentication
- Authorize Card Payment
- Capture Authorized Payment
- Reverse Authorization
- Enums
- License
Requirements
- PHP >= 7.4
- Required extensions:
- json
- openssl
Installation
Install via Composer:
composer require ninepay-gateway/rest-client-php
Configuration
PHP Native
use NinePay\Config\NinePayConfig; use NinePay\Gateways\NinePayGateway; $config = new NinePayConfig( 'MERCHANT_ID', 'SECRET_KEY', 'CHECKSUM_KEY', 'https://your-endpoint-url' ); $gateway = new NinePayGateway($config);
You may also create configuration from array:
$config = NinePayConfig::fromArray([ 'merchant_id' => 'MID', 'secret_key' => 'SECRET', 'checksum_key' => 'CHECKSUM', 'endpoint' => 'https://your-endpoint-url', ]);
Laravel
Publish configuration file:
php artisan vendor:publish --tag=ninepay-config
Then configure environment variables:
NINEPAY_MERCHANT_ID=your_merchant_id NINEPAY_SECRET_KEY=your_secret_key NINEPAY_CHECKSUM_KEY=your_checksum_key NINEPAY_ENDPOINT=https://your-endpoint-url
After configuration, the gateway is automatically resolved via Laravel's service container.
Usage requires only the Facade:
use NinePay\Facades\NinePay; $response = NinePay::createPayment($request);
Example in controller:
public function pay() { $request = new CreatePaymentRequest( 'INV_' . time(), 50000, 'Payment Order', route('payment.return'), route('payment.cancel') ); $response = NinePay::createPayment($request); return redirect($response->getData()['redirect_url']); }
Lumen
Copy config file:
cp vendor/ninepay-gateway/rest-client-php/config/ninepay.php config/ninepay.php
Register provider in bootstrap/app.php:
$app->register(NinePay\NinePayServiceProvider::class); $app->configure('ninepay');
Enable facades:
$app->withFacades(); class_alias(NinePay\Facades\NinePay::class, 'NinePay');
Usage
Initialization
PHP Native:
use NinePay\Config\NinePayConfig; use NinePay\Gateways\NinePayGateway; $config = new NinePayConfig('MID', 'SECRET', 'CHECKSUM', 'https://your-endpoint-url'); $gateway = new NinePayGateway($config);
Laravel:
$response = NinePay::createPayment($request);
Create Payment
use NinePay\Request\CreatePaymentRequest; use NinePay\Enums\Currency; use NinePay\Enums\Language; use NinePay\Enums\TransactionType; $request = new CreatePaymentRequest( 'INV_' . time(), 3100000, 'Payment for Order', 'https://site.com/return', 'https://site.com/cancel' ); $request ->withClientIp('127.0.0.1') ->withCurrency(Currency::VND) ->withLang(Language::VI) ->withTransactionType(TransactionType::INSTALLMENT) ->withExpiresTime(1440); $response = $gateway->createPayment($request);
Query Transaction
$response = $gateway->inquiry('INV_123456'); if ($response->isSuccess()) { print_r($response->getData()); }
Verify Webhook
$result = $_POST['result'] ?? ''; $checksum = $_POST['checksum'] ?? ''; if ($gateway->verify($result, $checksum)) { $json = $gateway->decodeResult($result); $data = json_decode($json, true); $invoiceNo = $data['invoice_no']; $status = $data['status']; echo 'OK'; } else { http_response_code(400); echo 'Checksum Mismatch'; }
Refund Transaction
use NinePay\Request\CreateRefundRequest; use NinePay\Enums\Currency; $request = new CreateRefundRequest( 'REF_' . time(), 436271072913641, 3100000, 'Refund reason' ); $request->withCurrency(Currency::VND) ->withBank( 'BIDV', '1023020330000', 'NGUYEN VAN A' ); $response = $gateway->refund($request);
Payer Authentication
use NinePay\Request\PayerAuthRequest; $request = new PayerAuthRequest( 'REQ_' . time(), 5000000, 'https://site.com/return' ); $request->withInstallment(5000000, 'VCB', 12) ->withCard( '4456530000001005', 'NGUYEN VAN A', '12', '27', '123' ); $response = $gateway->payerAuth($request);
Authorize Card Payment
use NinePay\Request\AuthorizeCardPaymentRequest; use NinePay\Enums\Currency; $request = new AuthorizeCardPaymentRequest( 'REQ_' . time(), 436271072913641, 3100000, Currency::VND ); $request->withCard( '4456530000001005', 'NGUYEN VAN A', '12', '27', '123' ); $response = $gateway->authorizeCardPayment($request);
Capture Authorized Payment
use NinePay\Request\CapturePaymentRequest; use NinePay\Enums\Currency; $request = new CapturePaymentRequest( 'REQ_' . time(), 436272499763441, 20000, Currency::VND ); $response = $gateway->capture($request);
Reverse Authorization
use NinePay\Request\ReverseCardPaymentRequest; $request = new ReverseCardPaymentRequest( 'REQ_' . time(), 436272499763441, 3100000, 'VND' ); $request->withCard( '4456530000001005', 'NGUYEN VAN A', '12', '27', '123' ); $response = $gateway->reverseCardPayment($request);
Enums
Currency
Supported examples:
VND, USD, EUR, JPY, AUD, ...
Language
VI, EN
Transaction Type
INSTALLMENT
CARD_AUTHORIZATION
License
MIT License © 9Pay
ninepay-gateway/rest-client-php 适用场景与选型建议
ninepay-gateway/rest-client-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「payment」 「sdk」 「payment-gateway」 「9pay」 「ninepay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ninepay-gateway/rest-client-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ninepay-gateway/rest-client-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ninepay-gateway/rest-client-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
TrinkPOS Sanal POS (Virtual POS) API client for PHP
ABsurge PHP SDK for feature flags and A/B testing
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-14