PHP code example of mattdi / telebirr-ussd

1. Go to this page and download the library: Download mattdi/telebirr-ussd 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/ */

    

mattdi / telebirr-ussd example snippets


use Mattdi\Telebirr\Facades\Telebirr;
use Mattdi\Telebirr\DTOs\BuyGoodsPayment;

$response = Telebirr::buyGoods(new BuyGoodsPayment(
    customerMsisdn: '2519XXXXXXXX',   // customer phone (no leading +)
    merchantShortCode: '20088001',    // merchant shortcode
    amount: '10.00',
    currency: 'ETB',
));

if ($response->accepted()) {
    // Request accepted for asynchronous processing.
    // Do NOT mark the order as paid yet. Await the callback.
}

use Mattdi\Telebirr\Events\TelebirrTransactionCompleted;

Event::listen(TelebirrTransactionCompleted::class, function ($event) {
    $result = $event->result;

    // Find your payment using OriginatorConversationID.
    // Verify business context and idempotency.
    // Mark the payment/order successful only after your validation.
});

use Mattdi\Telebirr\Webhooks\IdempotencyChecker;

app()->bind(IdempotencyChecker::class, YourIdempotencyChecker::class);

use Mattdi\Telebirr\Security\SecurityCredentialProvider;

app()->bind(SecurityCredentialProvider::class, function () {
    return new YourProvider();
});
bash
php artisan vendor:publish --tag=telebirr-ussd-config