dopee/transip-api
PHP/Laravel package providing a TransIP API client to automate domain and hosting tasks. Integrate TransIP services in your app: manage domains, DNS, and related resources via a simple, programmatic interface.
Installation
composer require dopee/transip-api
Add the package to your config/app.php providers and aliases if not auto-discovered.
First Use Case: Fetching Domain Info
use Dopee\TransipApi\Client;
$client = new Client([
'username' => env('TRANSIP_USERNAME'),
'password' => env('TRANSIP_PASSWORD'),
]);
$domain = $client->domains->get('example.com');
Key Files to Review
src/Dopee/TransipApi/Client.php – Main client class.src/Dopee/TransipApi/Resources/ – API resource definitions (e.g., Domains, Nameservers).src/Dopee/TransipApi/Exceptions/ – Custom exceptions for error handling.Domain Management
// Fetch all domains
$domains = $client->domains->all();
// Create a new domain
$newDomain = $client->domains->create([
'name' => 'newexample.com',
'period' => 1, // 1 year
]);
// Update DNS records
$client->domains->dns->set('example.com', [
'records' => [
['name' => 'www', 'type' => 'A', 'data' => '192.0.2.1'],
],
]);
Nameserver Management
// Get nameservers for a domain
$nameservers = $client->domains->nameservers->get('example.com');
// Add a nameserver
$client->domains->nameservers->add('example.com', 'ns1.example.com');
Order Management (e.g., SSL Certificates)
// List orders
$orders = $client->orders->all();
// Get order details
$order = $client->orders->get(12345);
Environment Configuration
Store credentials in .env:
TRANSIP_USERNAME=your_username
TRANSIP_PASSWORD=your_password
Load them via Laravel’s config/services.php:
'transip' => [
'username' => env('TRANSIP_USERNAME'),
'password' => env('TRANSIP_PASSWORD'),
],
Then inject the client:
$client = new Client(config('services.transip'));
Service Providers Bind the client to Laravel’s container for dependency injection:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton(Client::class, function ($app) {
return new Client(config('services.transip'));
});
}
Task Scheduling Use Laravel’s scheduler to automate domain checks or renewals:
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$domains = resolve(Client::class)->domains->all();
// Logic to check expirations, etc.
})->daily();
}
Deprecated API
$client->getLastResponse()) and extend the package if needed (see Extension Points below).Rate Limiting
use GuzzleHttp\Exception\RequestException;
try {
$client->domains->get('example.com');
} catch (RequestException $e) {
if ($e->getCode() === 429) {
sleep(2); // Retry after delay
retry();
}
}
Authentication Failures
try {
$client->domains->all();
} catch (\Dopee\TransipApi\Exceptions\AuthException $e) {
Log::error('TransIP auth failed: ' . $e->getMessage());
// Notify admin or trigger alert.
}
Enable Debug Mode
Pass debug: true to the client to log raw requests/responses:
$client = new Client([...], true);
Check Laravel logs (storage/logs/laravel.log) for details.
Inspect Raw Responses
Use $client->getLastResponse() to debug API issues:
$response = $client->domains->get('example.com');
if ($response->failed()) {
dd($client->getLastResponse());
}
Accept: application/json). Override them if needed:
$client = new Client([...], false, [
'headers' => ['Accept' => 'application/xml'],
]);
Custom API Endpoints
Extend the Client class to add unsupported endpoints:
class CustomClient extends Client
{
public function customEndpoint($data)
{
return $this->request('POST', '/custom/endpoint', $data);
}
}
Resource Extensions
Add new resources by extending Dopee\TransipApi\Resources\Resource:
namespace App\Transip;
use Dopee\TransipApi\Resources\Resource;
class CustomResource extends Resource
{
protected $endpoint = 'custom';
// ...
}
Mocking for Testing Use Laravel’s mocking to test without hitting the API:
$mockClient = Mockery::mock(Client::class);
$mockClient->shouldReceive('domains->get')
->with('example.com')
->andReturn((object) ['name' => 'example.com']);
How can I help you explore Laravel packages today?