hamdy/dtone
Laravel package that integrates DT One’s DVS API into your Laravel app, providing a simple foundation for connecting to DT One services (e.g., digital value and voucher workflows) with a package-based setup.
Installation
composer require mohamedhamdy5/dtone
Publish the config file:
php artisan vendor:publish --provider="Hamdy\Dtone\DtoneServiceProvider"
Configuration
Edit .env with your DT One API credentials:
DTONE_API_KEY=your_api_key_here
DTONE_API_SECRET=your_api_secret_here
DTONE_BASE_URL=https://api.dtone.com
First Use Case Initialize the client in a service or controller:
use Hamdy\Dtone\Facades\Dtone;
$client = Dtone::client();
Fetch a test response (verify connectivity):
$response = $client->get('/v1/accounts');
API Client Initialization Use the facade for simplicity:
$client = Dtone::client(['timeout' => 30]);
Or inject the service directly into a service provider:
$this->app->bind('dtone.client', function ($app) {
return new \Hamdy\Dtone\DtoneClient($app['config']['dtone']);
});
Handling API Responses Wrap API calls in a service layer for consistency:
class DtoneService {
protected $client;
public function __construct(DtoneClient $client) {
$this->client = $client;
}
public function fetchAccount($accountId) {
return $this->client->get("/v1/accounts/{$accountId}");
}
}
Webhook Integration Validate and process DT One webhooks in a middleware:
public function handle(Request $request, Closure $next) {
$payload = $request->getContent();
$signature = $request->header('X-Dtone-Signature');
if (!Dtone::validateWebhook($payload, $signature)) {
abort(403, 'Invalid webhook signature');
}
return $next($request);
}
Error Handling Centralize error responses:
try {
$response = $client->post('/v1/transactions', $data);
} catch (\Hamdy\Dtone\Exceptions\DtoneException $e) {
Log::error("DT One API Error: " . $e->getMessage());
return response()->json(['error' => 'Payment failed'], 400);
}
Authentication Failures
DTONE_API_KEY and DTONE_API_SECRET are correctly set in .env.Dtone::client()->get('/v1/accounts')->dump();
Webhook Validation
validateWebhook() method:
Dtone::validateWebhook($payload, $signature);
.env).Rate Limiting
use Symfony\Component\HttpClient\RetryableHttpClient;
$client = new RetryableHttpClient(
Dtone::client()->getHttpClient(),
[
'max_retries' => 3,
'delay' => 1000,
'multiplier' => 2,
]
);
Endpoint Changes
Enable Debug Mode
Set DTONE_DEBUG=true in .env to log raw API requests/responses.
Inspect Headers Add custom headers for debugging:
$client->withHeaders(['X-Debug' => 'true']);
Mocking for Tests Use Laravel’s HTTP client mocking:
$this->mock(DtoneClient::class, function ($mock) {
$mock->shouldReceive('get')->andReturn(['data' => 'mocked']);
});
Custom HTTP Client
Override the default Guzzle client in config/dtone.php:
'http_client' => \App\Services\CustomHttpClient::class,
Response Transformers
Extend the DtoneResponse class to modify responses:
class CustomDtoneResponse extends \Hamdy\Dtone\DtoneResponse {
public function transform() {
return parent::transform()->merge(['custom_field' => 'value']);
}
}
Bind it in a service provider:
$this->app->bind(\Hamdy\Dtone\DtoneResponse::class, CustomDtoneResponse::class);
Event Listeners Dispatch custom events for webhooks:
event(new \App\Events\DtoneWebhookReceived($payload));
How can I help you explore Laravel packages today?