PHP code example of eboseogbidi / smartpaymentrouter

1. Go to this page and download the library: Download eboseogbidi/smartpaymentrouter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eboseogbidi / smartpaymentrouter example snippets


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
    ],
];

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');
    }


}

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' => '

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();
        
    }
}

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();
}
bash
php artisan migrate
bash
php artisan vendor:publish --tag=smartpaymentrouter-config