eboseogbidi/smartpaymentrouter
Composer 安装命令:
composer require eboseogbidi/smartpaymentrouter
包简介
This package can intelligently route payment transactions to the most suitable payment processor based on various factors such as transaction cost, reliability, and currency support.
README 文档
README
A flexible and intelligent payment routing system that helps you manage multiple payment processors with automatic fallback and smart routing based on cost, reliability, and supported currencies.
Installation
You can install the package via composer:
composer require eboseogbidi/smartpaymentrouter
Migration
Migrate the schema for the payment transaction log this helps to improve the reliability of the different payment processors:
php artisan migrate
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=smartpaymentrouter-config
This will create a config/smartpaymentrouter.php file where you can configure your payment processors.
Basic Configuration Structure
return [ 'routing_rules' => [ 'transaction_cost' => true, 'reliability' => true, 'currency_support' => true, ], 'processors' => [ 'stripe' => [ 'name' => "Stripe", 'class' => \Eboseogbidi\Smartpaymentrouter\Processors\StripeProcessor::class, 'transaction_cost' => 1.8, 'reliability' => 95, 'currencies' => ['USD', 'GBP'], ], // Add more processors here ], ];
Configuration parameters:
name: Display name for the processorclass: The processor class that implements PaymentProcessorInterfacetransaction_cost: Processing fee percentagereliability: Estimated uptime percentagecurrencies: Array of supported currencies
Extending PaymentProcessorInterface
To create a new payment processor, implement the PaymentProcessorInterface:
use Eboseogbidi\Smartpaymentrouter\Interfaces\PaymentProcessorInterface; class StripeProcessor implements PaymentProcessorInterface{ //If you want to extend the callback functionality use DefaultCallbackTrait; public function getName():string{ return 'Stripe'; } public function processPayment(array $paymentData): array{ //process stripe payment return $paymentData; } public function callback($response){ return back()->with('success','Works fine'); } }
Using the Payment Router
Example of how to use the PaymentRouter in a Controller :
namespace Eboseogbidi\Smartpaymentrouter\Http\Controllers; use Illuminate\Http\Request; use Eboseogbidi\Smartpaymentrouter\Services\PaymentRouter; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Log; class ProcessPaymentController extends BaseController { public function __construct(protected PaymentRouter $paymentRouter){} /** * Handle the payment transaction. * * @param Request $request * @return mixed */ public function handlePayment(Request $request): mixed { $request->validate([ 'amount' => 'required|numeric|min:0.01', 'currency' => 'required|string|max:3', ]); try { $paymentData = $request->all(); $result = $this->paymentRouter->routeTransaction($paymentData); return $result; } catch (\Exception $e) { Log::error("Payment transaction error: {$e->getMessage()}"); return back()->with('error','Transaction failed'. $e->getMessage()); } } }
Using the ProcessorManager
The ProcessorManager provides methods to interact with and modify the payment configuration:
use Eboseogbidi\Smartpaymentrouter\Services\ProcessorManager; class PaymentService { public function __construct(protected ProcessorManager $processorManager){} public function updateProcessorConfig() { // Add new processor $this->processorManager->addProcessor('paypal', [ 'name' => 'PayPal', 'class' => PayPalProcessor::class, 'transaction_cost' => 2.0, 'reliability' => 98, 'currencies' => ['USD', 'EUR'], ]); // Update existing processor $this->processorManager->updateProcessor('stripe', [ 'transaction_cost' => 1.9, 'reliability' => 97, ]); // Remove processor $this->processorManager->removeProcessor('square'); //Get Processors $this->processorManager->getProcessors(); } }
Testing
The package includes a comprehensive test suite. Run the tests with:
composer test
Error Handling
The package provides built-in error handling for common scenarios:
try { $result = $processor->processPayment($paymentData); } catch (PaymentProcessingException $e) { // Handle processor-specific errors Log::error('Payment processing failed: ' . $e->getMessage()); } catch (RoutingException $e) { // Handle processor-specific errors Log::error('Routing error failed: ' . $e->getMessage()); } catch (ValidationException $e) { // Handle validation errors $errors = $e->getValidationErrors(); }
eboseogbidi/smartpaymentrouter 适用场景与选型建议
eboseogbidi/smartpaymentrouter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 eboseogbidi/smartpaymentrouter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eboseogbidi/smartpaymentrouter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-04