1. Go to this page and download the library: Download ghanem/dtone 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 / dtone example snippets
use Ghanem\Dtone\Facades\Dtone;
// List all services (returns PaginatedResponse of Service DTOs)
$services = Dtone::services($page, $per_page);
$services->getData(); // array of Service DTOs
$services->getMeta()->getTotal(); // total count
// Get a service by ID
$service = Dtone::serviceById(1);
$service->getId();
$service->getName();
// List all countries
$countries = Dtone::countries($page, $per_page);
// Get a country by ISO code
$country = Dtone::countryByIsoCode('US');
$country->getIsoCode(); // 'US'
$country->getName(); // 'United States'
$country->getRegions(); // array
// List all operators (optionally filter by country)
$operators = Dtone::operators('US', $page, $per_page);
// Get an operator by ID
$operator = Dtone::operatorById(5);
$operator->getId();
$operator->getName();
$operator->getCountry(); // Country DTO
$operator->getCountry()->getName(); // nested access
// Lookup operators by mobile number
$result = Dtone::lookupOperatorsByMobileNumber('+1234567890');
// List products with filters
$products = Dtone::products(
$type, // e.g. 'FIXED_VALUE_RECHARGE'
$service_id, // e.g. 1
$country_iso_code, // e.g. 'US'
$benefit_types, // e.g. ['Airtime']
$page,
$per_page
);
// Get a product by ID
$product = Dtone::productById(99);
$product->getId();
$product->getType();
$product->getService(); // Service DTO
$product->getOperator(); // Operator DTO
$product->getAttribute('prices'); // raw array for nested fields
// List active campaigns
$campaigns = Dtone::campaigns($page, $per_page);
// Get a campaign by ID
$campaign = Dtone::campaignById(7);
$campaign->getId();
$campaign->getName();
// List promotions
$promotions = Dtone::promotions($page, $per_page);
// Get a promotion by ID
$promotion = Dtone::promotionById(3);
$promotion->getOperator(); // Operator DTO or null
// List all benefit types
$benefitTypes = Dtone::benefitTypes($page, $per_page);
$balances = Dtone::balances(); // array of Balance DTOs
foreach ($balances as $balance) {
$balance->getAmount(); // 150.50
$balance->getCurrency(); // 'USD'
}
// List transactions
$transactions = Dtone::transactions($page, $per_page);
// Get a transaction by ID
$transaction = Dtone::transactionById(456);
$transaction->getId();
$transaction->getStatus();
$transaction->getExternalId();
$transaction->getAttribute('product'); // raw array
// Create a transaction (async)
$transaction = Dtone::createTransaction(
'external-id-123', // external_id
99, // product_id
['mobile_number' => '+1234567890'], // credit_party_identifier
false // auto_confirm (default: false)
);
// Create a transaction (sync - waits for completion)
$transaction = Dtone::createTransactionSync(
'external-id-123',
99,
['mobile_number' => '+1234567890'],
true // auto_confirm
);
// Confirm a transaction (async)
$confirmed = Dtone::confirmTransaction($transaction_id);
// Confirm a transaction (sync - waits for completion)
$confirmed = Dtone::confirmTransactionSync($transaction_id);
// Cancel a transaction
$cancelled = Dtone::cancelTransaction($transaction_id);
// Lookup operators by mobile number
$operators = Dtone::lookupOperatorsByMobileNumber('+1234567890');
// Statement inquiry
$statement = Dtone::statementInquiry(
99, // product_id
['account_number' => '123456'] // credit_party_identifier
);
// Get remaining benefits for a credit party
$benefits = Dtone::creditPartyBenefits(
99, // product_id
['mobile_number' => '+1234567890'] // credit_party_identifier
);
// Get status for a credit party
$status = Dtone::creditPartyStatus(
99, // product_id
['mobile_number' => '+1234567890'] // credit_party_identifier
);
$response = Dtone::services(1, 10);
$response->getData(); // array of DTOs
$response->getMeta()->getTotal(); // total items
$response->getMeta()->getTotalPages(); // total pages
$response->getMeta()->getPage(); // current page
$response->getMeta()->getPerPage(); // items per page
$response->getMeta()->getNextPage(); // next page number
$response->getMeta()->getPrevPage(); // previous page number
use Ghanem\Dtone\Notifications\DtoneChannel;
use Ghanem\Dtone\Notifications\DtoneMessage;
use Illuminate\Notifications\Notification;
class SendAirtimeNotification extends Notification
{
public function via($notifiable)
{
return [DtoneChannel::class];
}
public function toDtone($notifiable)
{
return DtoneMessage::create(99) // product_id
->externalId('order-123') // optional external ID
->toMobileNumber('+1234567890') // recipient
->autoConfirm(); // auto-confirm the transaction
}
}
DtoneMessage::create($productId) // create with product ID
->externalId('ext-123') // set external ID (auto-generated if not set)
->toMobileNumber('+1234567890') // set mobile number recipient
->to(['account_number' => '123456']) // or set custom identifier
->autoConfirm() // enable auto-confirm
->sync(); // use synchronous API (default: async)
use Illuminate\Support\Facades\Notification;
Notification::route(DtoneChannel::class, null)
->notify(new SendAirtimeNotification());
use Ghanem\Dtone\Request;
Request::clearCache(); // clear all DT One cache
Request::clearCache('services'); // clear specific endpoint cache