adamnatad/laravel-ntpayments
Composer 安装命令:
composer require adamnatad/laravel-ntpayments
包简介
Modular Payment Gateway Integration Package for Laravel and Flutter (Xendit, Paymongo)
README 文档
README
A modular and scalable payment gateway integration for Laravel, supporting Xendit and PayMongo with automatic currency conversion, dynamic payment method validation and configurable transaction IDs.
🚀 Features
✔ Supports Multiple Payment Gateways → Xendit & PayMongo (More coming soon!)
✔ Automatic Currency Conversion → Converts between preferred and secondary currencies.
✔ Dynamic Payment Method Validation → Ensures only supported methods are used.
✔ Configurable Transaction ID Format → {PREFIX}_{GATEWAY}_{UNIQUEID}_{TIMESTAMP}
✔ Programmatic Conversion Rate Override → Developers can adjust conversion rates dynamically per request.
✔ Retrieve Unique Transaction IDs → Ensures traceable and globally unique transaction tracking.
✔ Modular & Extensible → Easily add new gateways without modifying core logic.
📦 Installation
Install the package via Composer:
composer require adamnatad/laravel-ntpayments
Then, publish the configuration file:
php artisan vendor:publish --tag=ntpayments-config
This will create:
config/ntpayments.php
⚙️ Configuration
1️⃣ Set API Credentials
Update your .env file with your payment gateway credentials:
XENDIT_SECRET_KEY=your_xendit_api_key PAYMONGO_SECRET_KEY=your_paymongo_api_key
2️⃣ Define Default Payment Settings
Modify config/ntpayments.php to set:
return [ 'default_gateway' => env('PAYMENT_GATEWAY', 'xendit'), 'preferred_currency' => 'USD', 'secondary_currency' => 'PHP', 'conversion_rate' => 54.30, 'transaction_prefix' => 'NTP', // Custom transaction prefix ];
🛠 Usage
✅ Processing a Payment
use AdamNatad\LaravelNTPayments\Facades\NTPayments; $response = NTPayments::createPayment([ 'amount' => 1000, 'currency' => 'USD', 'gateway' => 'xendit', 'payment_type' => 'credit_card', ]); dd($response);
✅ Fetch Available Payment Methods
$methods = NTPayments::getMethods('xendit'); dd($methods);
✅ Get Available Currencies
$currencies = NTPayments::getCurrencies('paymongo'); dd($currencies);
✅ Retrieve Conversion Rate
$rate = NTPayments::getConversionRate(); dd($rate);
✅ Override Conversion Rate (For Current Request)
$ntp = new NTPayments(); $ntp->setConversionRate(55.00); $rate = $ntp->getConversionRate(); dd($rate);
✅ Generate a Unique Transaction ID
The transaction ID is generated using the following format:
{PREFIX}_{GATEWAY}_{UNIQUEID}_{TIMESTAMP}
- PREFIX → Defined in
config/ntpayments.php(transaction_prefix, default:NTP) - GATEWAY → The selected payment gateway (e.g.,
XENDIT,PAYMONGO) - UNIQUEID → A secure 10-character unique identifier generated via
bin2hex(random_bytes(5)) - TIMESTAMP → The Unix timestamp at the time of transaction creation
$transactionId = NTPayments::generateTransactionId('xendit'); dd($transactionId);
Example Output:
NTP_XENDIT_65AB2C7F12D_1719214023
✅ Charge a Payment
$chargeResponse = NTPayments::charge(1000, 'USD', 'credit_card', 'xendit'); dd($chargeResponse);
✅ Retrieve Payment Details
Note: The payment ID used here (
invoice_12345) is the unique invoice ID returned by Xendit when processing a payment. This is not the same as the internally generated transaction ID (NTP_XENDIT_65AB2C7F12D_1719214023). When retrieving payment details, always use the invoice ID provided by Xendit.
$paymentDetails = NTPayments::getPaymentDetails('xendit', 'invoice_12345'); dd($paymentDetails);
✅ Retrieve Payment Status
Note: Similar to retrieving payment details, the payment ID used here (
invoice_12345) is the unique invoice ID returned by Xendit when processing a payment. This is not the same as the internally generated transaction ID (NTP_XENDIT_65AB2C7F12D_1719214023). When retrieving payment status, always use the invoice ID provided by Xendit.
$paymentStatus = NTPayments::getPaymentStatus('xendit', 'invoice_12345'); dd($paymentStatus);
📜 License
This package is open-source and licensed under the MIT License.
📞 Support & Contributions
Pull requests and feature suggestions are welcome! If you encounter any issues, feel free to open an issue on GitHub.
adamnatad/laravel-ntpayments 适用场景与选型建议
adamnatad/laravel-ntpayments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 adamnatad/laravel-ntpayments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adamnatad/laravel-ntpayments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-25