Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tope19/smart-payment-routing

A Laravel package that allows your application to intelligently select the best payment processor for each transaction.
https://github.com/tope19/smart-payment-routing

Last synced: about 1 month ago
JSON representation

A Laravel package that allows your application to intelligently select the best payment processor for each transaction.

Awesome Lists containing this project

README

        

# Smart Routing Package

## Introduction

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.

## Features

- **Dynamic Routing Logic**: Intelligently routes transactions to the best payment processor.
- **Processor Management**: Manage multiple payment processors with ease.
- **Configuration Options**: Customize routing rules based on transaction cost, reliability, and other criteria.
- **Laravel Compatibility**: Compatible with the latest stable version of Laravel.

## Table of Contents

1. [Installation](#installation)
2. [Usage](#usage)
3. [Running Tests](#running-tests)

## Installation

You can install the package via composer:

```bash
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:

```bash
{
"minimum-stability": "dev",
"prefer-stable": true
}
```

After installation, publish the configuration file:

```bash
php artisan vendor:publish --provider="Xsotechs\SmartPaymentRouting\SmartPaymentRoutingServiceProvider" --tag="config"
```

Run your migration command:
```bash
php artisan migrate
```

## Usage
To use the smart payment routing in your Laravel application:

```php
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);
}
}
```

## Managing Payment Processors
You can use the '**PaymentProcessorService**' to manage payment processors:

```php
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();
```

## Running Tests

Please make sure to update the database credentials in phpunit.xml with your own when running tests for the package.
```php

```

Then run the below commands:
1. vendor/bin/phpunit tests/unit/PaymentProcessorServiceTest.php
2. vendor/bin/phpunit tests/unit/SmartRouterServiceTest.php
3. vendor/bin/phpunit tests/unit/*.php