PHP code example of ghanem / bee

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

    

ghanem / bee example snippets


use Ghanem\Bee\Facades\Bee;

// Get all categories
$categories = Bee::getCategoryList();

// Get category service list
$categoryServices = Bee::getCategoryServiceList();

// Get provider list by category
$providers = Bee::getProviderList(categoryId: 2);

// Get all services
$services = Bee::getServiceList();

// Get service input/output parameters
$inputParams = Bee::getServiceInputParameterList();
$outputParams = Bee::getServiceOutputParameterList();

// Transaction inquiry
$inquiry = Bee::transactionInquiry([
    'account_number' => '12345',
    'service_id' => 10,
    'input_parameter_list' => [
        ['key' => 'phone', 'value' => '0912345678'],
    ],
]);

// Transaction payment
$payment = Bee::transactionPayment([
    'account_number' => '12345',
    'service_id' => 10,
    'external_id' => 'order-001',
    'amount' => 100,
    'service_charge' => 5,
    'total_amount' => 105,
    'quantity' => 1,
    'inquiry_transaction_id' => $inquiry['data']['transaction_id'],
    'input_parameter_list' => [],
]);

// Get transaction details by ID
$transaction = Bee::getTransaction(123);

// Get transaction by external ID
$transaction = Bee::getTransaction('order-001', 'external_id');

// Get account info
$account = Bee::getAccountInfo();

// Get bills amount (performs inquiry and returns amount)
$bills = Bee::getBillsAmount([
    'service_id' => 10,
    'account_number' => '12345',
]);

// Calculate service charge for an amount
$result = Bee::calculateServiceCharge([
    'service_id' => 10,
    'amount' => 100,
]);
// Returns: ['service_id' => 10, 'amount' => 100, 'service_charge' => 5, 'total_amount' => 105]

// Reverse calculate (from total amount back to base amount)
$result = Bee::calculateServiceChargeReverse([
    'service_id' => 10,
    'amount' => 105, // total amount including charge
]);
// Returns: ['service_id' => 10, 'amount' => 95.45, 'service_charge' => 9.55, 'total_amount' => 105]

$categories = Bee::getCategoryList('ar');
$services = Bee::getServiceList('ar');

use Ghanem\Bee\DTOs\ApiResponse;
use Ghanem\Bee\DTOs\TransactionResult;
use Ghanem\Bee\DTOs\ServiceChargeResult;

// API response DTO
$response = Bee::getCategoryListDto(); // returns ApiResponse
$response->success;    // bool
$response->data;       // array
$response->statusCode; // int
$response->get('categories.0.name'); // dot notation access

// Transaction DTO
$tx = Bee::getTransactionDto(123); // returns TransactionResult
$tx->transactionId; // ?int
$tx->amount;        // ?float
$tx->serviceCharge; // ?float
$tx->totalAmount;   // ?float

$inquiry = Bee::transactionInquiryDto($data);  // TransactionResult
$payment = Bee::transactionPaymentDto($data);  // TransactionResult

// Service charge DTO
$charge = Bee::calculateServiceChargeDto([
    'service_id' => 10,
    'amount' => 100,
]); // returns ServiceChargeResult
$charge->serviceId;     // int
$charge->amount;        // float
$charge->serviceCharge; // float
$charge->totalAmount;   // float

// Clear all cached data
Bee::clearCache();

// Clear specific cache key
Bee::clearCache('category_list_en');

use Ghanem\Bee\Events\BeeWebhookReceived;
use Ghanem\Bee\Events\TransactionStatusUpdated;

// Listen to all webhook events
Event::listen(BeeWebhookReceived::class, function ($event) {
    // $event->event   - event name (e.g. 'transaction.completed')
    // $event->payload - full webhook payload
});

// Listen specifically to transaction status changes
Event::listen(TransactionStatusUpdated::class, function ($event) {
    // $event->transactionId
    // $event->status
    // $event->payload
});

// Dispatch a single payment to the queue
Bee::transactionPaymentAsync([
    'account_number' => '12345',
    'service_id' => 10,
    'amount' => 100,
]);

// Batch multiple transactions
$batch = Bee::batchTransactions([
    ['action' => 'payment', 'data' => ['service_id' => 10, 'amount' => 100]],
    ['action' => 'inquiry', 'data' => ['service_id' => 11, 'account_number' => '123']],
    ['action' => 'payment', 'data' => ['service_id' => 12, 'amount' => 200], 'lang' => 'ar'],
]);

// Batch with callback event
Bee::batchTransactions($transactions, App\Events\TransactionProcessed::class);
bash
php artisan vendor:publish --provider="Ghanem\Bee\BeeServiceProvider" --tag="bee-config"