A Laravel package that allows your application to intelligently select the best payment processor for each transaction.
The Smart Routing Package for Laravel provides an intelligent routing system for payment gateways. It dynamically selects the most suitable payment processor based on various factors such as transaction cost, reliability, and currency support. This package ensures efficient, flexible, and secure handling of payment transactions.
You can install the package via composer:
composer require xsotechs/smart-payment-routing:dev-main
You can adjust your project's minimum-stability to allow less stable versions. Add the following to your composer.json file:
{
"minimum-stability": "dev",
"prefer-stable": true
}
After installation, publish the configuration file:
php artisan vendor:publish --provider="Xsotechs\SmartPaymentRouting\SmartPaymentRoutingServiceProvider" --tag="config"
Run your migration command:
php artisan migrate
To use the smart payment routing in your Laravel application:
use Xsotechs\SmartPaymentRouting\Services\SmartRouterService;
public function processPayment(Request $request)
{
$smartRouterService = new SmartRouterService();
$paymentData = [
'amount' => $request->amount,
'currency' => $request->currency,
'country' => $request->country,
// Add any other necessary data
];
try {
$data = $smartRouterService->route($paymentData);
// Use the data to initiate a payment logic
} catch (\Exception $e) {
return response()->json(['message' => 'Error: ' . $e->getMessage()], 500);
}
}
You can use the 'PaymentProcessorService' to manage payment processors:
use Xsotechs\SmartPaymentRouting\Services\PaymentProcessorService;
$processorService = new PaymentProcessorService();
// Create a new processor
$newProcessor = $processorService->create([
'name' => 'paystack',
'is_active' => true,
'transaction_cost' => 0.029,
'reliability_score' => 99.0,
'supported_currencies' => ['NGN', 'USD'], // Supported currencies
'supported_countries' => ['NG', 'US'], // Supported countries
'config' => ['api_key' => 'your_stripe_api_key'],
]);
// Update a processor
$processor = PaymentProcessor::find(1);
$processorService->update($processor, [
'transaction_cost' => 0.028,
'reliability_score' => 95.0,
]);
// Delete a processor
$processor = PaymentProcessor::find(1);
$processorService->delete($processor);
// Get all processors
$allProcessors = $processorService->getAll();
// Get active processors
$activeProcessors = $processorService->getActive();
Please make sure to update the database credentials in phpunit.xml with your own when running tests for the package.
<env name="DB_CONNECTION" value="mysql"/>
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_PORT" value="8889"/>
<env name="DB_DATABASE" value="test_database"/>
<env name="DB_USERNAME" value="root"/>
<env name="DB_PASSWORD" value="root"/>
<env name="DB_SOCKET" value="/Applications/MAMP/tmp/mysql/mysql.sock"/>
Then run the below commands: