PHP code example of geekabel / mobile-money-payment

1. Go to this page and download the library: Download geekabel/mobile-money-payment 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/ */

    

geekabel / mobile-money-payment example snippets


use MobileMoneyPayment\PaymentManager;
use MobileMoneyPayment\Service\TmoneyService;
use MobileMoneyPayment\Service\FloozService;
use MobileMoneyPayment\Service\DefaultFloozCounterManager;

// Create service instances
$tmoneyService = new TmoneyService(
    $httpClient,
    $logger,
    'tmoney_username',
    'tmoney_password',
    'tmoney_alias',
    'https://tmoney-api-url.com'
);

$floozService = new FloozService(
    $httpClient,
    $logger,
    new DefaultFloozCounterManager(),
    'flooz_username',
    'flooz_password',
    'flooz_key',
    'flooz_merchant_name',
    'flooz_partner_msisdn',
    'https://flooz-api-url.com'
);

// Create and set up the Payment Manager
$paymentManager = new PaymentManager();
$paymentManager->addService('tmoney', $tmoneyService);
$paymentManager->addService('flooz', $floozService);

$response = $paymentManager->pay('tmoney', '1234567890', 100.00, 'REF123', 'Payment for order #123');

if ($response->success) {
    echo "Payment successful! Transaction ID: " . $response->transactionId;
} else {
    echo "Payment failed: " . $response->message;
}

$status = $paymentManager->checkStatus('flooz', 'REF123');

echo "Payment status: " . $status->status;

use MobileMoneyPayment\Interface\PaymentServiceInterface;
use MobileMoneyPayment\Model\PaymentResponse;

class NewPaymentService implements PaymentServiceInterface
{
    public function pay(string $phone, float $amount, string $reference, string $description = ''): PaymentResponse
    {
        // Implement payment logic
    }

    public function checkStatus(string $reference): PaymentResponse
    {
        // Implement status check logic
    }
}

$newService = new NewPaymentService(/* ... */);
$paymentManager->addService('new_service', $newService);

use MobileMoneyPayment\Interface\FloozCounterManagerInterface;

class CustomFloozCounterManager implements FloozCounterManagerInterface
{
    public function getAndIncrementCounter(): int
    {
        // Implement custom counter logic
    }
}

$customCounterManager = new CustomFloozCounterManager();
$floozService = new FloozService(
    $httpClient,
    $logger,
    $customCounterManager,
    // ... other parameters
);

use MobileMoneyPayment\Exception\PaymentException;

try {
    $response = $paymentManager->pay('tmoney', '1234567890', 100.00, 'REF123');
} catch (PaymentException $e) {
    echo "Payment error: " . $e->getMessage();
} catch (\Exception $e) {
    echo "Unexpected error: " . $e->getMessage();
}

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('payment');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG));

$tmoneyService = new TmoneyService(
    $httpClient,
    $logger,
    // ... other parameters
);