ghanem/dtone
Laravel package providing a clean interface to the DT One DVS API. Configure sandbox/production credentials via .env, optional request retries, and use the Dtone facade to browse services, countries, and operators with paginated DTO responses.
Installation:
composer require ghanem/dtone
php artisan vendor:publish --provider="Ghanem\Dtone\DtoneServiceProvider" --tag="config"
Configure .env:
Add your API keys (production/sandbox) and set DTONE_IS_PRODUCTION to true/false.
DTONE_KEY=your_prod_key
DTONE_SECRET=your_prod_secret
DTONE_IS_PRODUCTION=false
First Use Case: Fetch a customer list (example from API docs):
use Ghanem\Dtone\Facades\Dtone;
$customers = Dtone::customers()->list();
dd($customers);
Ghanem\Dtone\Facades\Dtone (primary entry point).config/dtone.php (customize endpoints, retries, or logging).API Resource Operations: Use fluent methods for CRUD operations. Example:
// Create a customer
$customer = Dtone::customers()->create([
'name' => 'John Doe',
'email' => 'john@example.com',
]);
// Update a customer
$customer->update(['email' => 'new@example.com']);
// Delete a customer
$customer->delete();
Pagination:
Handle paginated responses with paginate():
$customers = Dtone::customers()->paginate(10);
foreach ($customers as $customer) {
// Process each customer
}
Webhooks:
Validate incoming DT One webhooks using the validateWebhook helper:
use Ghanem\Dtone\Helpers\Webhook;
if (Webhook::validate($request->all())) {
// Process webhook payload
}
Error Handling:
Wrap API calls in try-catch blocks:
try {
$response = Dtone::payments()->list();
} catch (\Ghanem\Dtone\Exceptions\DtoneException $e) {
Log::error('DT One API Error: ' . $e->getMessage());
// Fallback logic
}
Service Layer: Create a dedicated service class to abstract DT One logic:
class DtoneCustomerService {
public function __construct(private Dtone $dtone) {}
public function fetchActiveCustomers() {
return $this->dtone->customers()->list(['status' => 'active']);
}
}
Event-Driven: Trigger Laravel events on DT One webhook payloads:
event(new CustomerCreated($customerData));
Testing:
Use the sandbox environment (DTONE_IS_PRODUCTION=false) for tests:
$this->app->singleton(Dtone::class, function ($app) {
return new Dtone(config('dtone.sandbox'));
});
Environment Switching:
DTONE_IS_PRODUCTION can lead to unexpected API calls to production..env.local file for environment-specific overrides.Rate Limiting:
.env:
DTONE_RETRIES=3
DTONE_RETRY_DELAY=500
Webhook Validation:
Webhook::validate() and log failed validations for debugging.Deprecated Methods:
Logging:
Enable debug mode in config/dtone.php:
'debug' => env('DTONE_DEBUG', false),
Logs will appear in storage/logs/laravel.log.
API Responses: Inspect raw responses for debugging:
$response = Dtone::customers()->list();
dd($response->original); // Raw HTTP response
Custom Endpoints: Extend the package by adding new API endpoints:
// In a service provider
$this->app->extend(Dtone::class, function ($dtone) {
$dtone->extend('customers/bulk', function ($api) {
return new CustomBulkCustomerApi($api);
});
return $dtone;
});
Middleware: Add middleware to modify requests/responses:
Dtone::middleware(function ($request) {
$request->header('X-Custom-Header', 'value');
});
Testing: Mock the DT One API in tests:
$this->mock(Dtone::class, function ($mock) {
$mock->shouldReceive('customers')
->andReturnSelf()
->shouldReceive('list')
->andReturn(['data' => []]);
});
DTONE_RETRY_DELAY (in milliseconds) for aggressive/fine-tuned retries.config/dtone.php:
'timeout' => 30, // seconds
How can I help you explore Laravel packages today?