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