touchestate-sdk/php-sdk
Official PHP SDK for TouchEstate. Provides client classes and helpers to integrate TouchEstate services into Laravel or any PHP app, with straightforward API calls, authentication support, and reusable components for building real estate workflows.
Installation
composer require touchestate-sdk/php-sdk
Add the SDK to your config/app.php providers (if using Laravel):
'providers' => [
// ...
TouchEstate\SDK\TouchEstateServiceProvider::class,
],
Configuration Publish the config file:
php artisan vendor:publish --provider="TouchEstate\SDK\TouchEstateServiceProvider"
Update .env with your API credentials:
TOUCHESTATE_API_KEY=your_api_key_here
TOUCHESTATE_API_SECRET=your_api_secret_here
TOUCHESTATE_API_URL=https://api.touchestate.com/v1
First Use Case: Fetching a Property
use TouchEstate\SDK\Facades\TouchEstate;
$property = TouchEstate::property()->find(123);
dd($property);
TouchEstate::resource()->action() (e.g., property()->find()).TouchEstateServiceProvider.vendor/touchestate-sdk/php-sdk/src/Resources/ for request/response models.Create a Property Listing
$property = TouchEstate::property()->create([
'title' => 'Modern Apartment',
'address' => '123 Main St',
'price' => 500000,
'bedrooms' => 2,
]);
Update a Listing
$updated = TouchEstate::property()->update(123, [
'price' => 499000,
'status' => 'pending',
]);
Delete a Listing
$deleted = TouchEstate::property()->delete(123);
$listings = TouchEstate::property()->query()
->where('price', '<', 300000)
->where('bedrooms', '>=', 2)
->limit(10)
->get();
// Upload an image
$media = TouchEstate::media()->upload('path/to/image.jpg', [
'property_id' => 123,
'type' => 'image',
]);
// Get media for a property
$images = TouchEstate::media()->forProperty(123)->get();
Subscribe to property status changes:
$webhook = TouchEstate::webhook()->create([
'url' => 'https://your-app.com/touchestate/webhook',
'events' => ['property.updated', 'property.published'],
]);
Bind SDK to a Controller
use TouchEstate\SDK\Contracts\PropertyRepository;
class PropertyController extends Controller
{
public function __construct(private PropertyRepository $propertyRepo) {}
public function index()
{
$properties = $this->propertyRepo->all();
return view('properties.index', compact('properties'));
}
}
Handle API Exceptions Globally
Override the exception handler in App\Exceptions\Handler.php:
public function register()
{
$this->reportable(function (TouchEstateException $e) {
// Log or notify
});
}
Rate Limiting Implement exponential backoff for retries:
TouchEstate::setRetryPolicy(new RetryPolicy(3, 500)); // 3 retries, 500ms delay
Caching Responses Cache frequent queries (e.g., property listings):
$properties = Cache::remember('touchestate_properties', 3600, function () {
return TouchEstate::property()->all();
});
Testing Use the SDK’s mocking capabilities:
$mock = Mockery::mock(TouchEstate::class);
$mock->shouldReceive('property()->find')->andReturn($fakeProperty);
Logging Enable debug logging for API calls:
TouchEstate::setDebug(true);
Authentication Failures
401 Unauthorized errors if TOUCHESTATE_API_KEY/SECRET are misconfigured..env and regenerate keys in TouchEstate dashboard.TouchEstate::setDebug(true);
Rate Limits
429 Too Many Requests if exceeding API limits (default: 60 calls/minute).TouchEstate::setRetryPolicy(new RetryPolicy(5, 1000));
Data Validation
title, price) are missing.$validated = $request->validate([
'title' => 'required|string',
'price' => 'required|numeric',
]);
Webhook Delays
idempotency_keys in webhook payloads to handle duplicates.Timezone Mismatches
$createdAt = $property->created_at->setTimezone('UTC');
Batch Operations Use bulk endpoints for efficiency:
$updated = TouchEstate::property()->updateMany([
123 => ['price' => 499000],
456 => ['price' => 550000],
]);
Webhook Verification Verify incoming webhook signatures:
use TouchEstate\SDK\WebhookVerifier;
$verifier = new WebhookVerifier($request->header('X-Signature'));
if (!$verifier->verify($request->getContent())) {
abort(403);
}
Environment-Specific Config Use Laravel’s config caching to avoid republishing configs:
php artisan config:cache
SDK Extensions Extend the SDK for custom resources:
// app/Providers/TouchEstateServiceProvider.php
public function boot()
{
TouchEstate::extend('custom_resource', function ($app) {
return new CustomResourceRepository();
});
}
Performance
->paginate(20) for large datasets.$property = TouchEstate::property()->find(123, ['id', 'title', 'price']);
Error Handling Catch specific exceptions:
try {
$property = TouchEstate::property()->find(123);
} catch (PropertyNotFoundException $e) {
abort(404);
} catch (TouchEstateException $e) {
Log::error($e->getMessage());
abort(500);
}
Local Development Use a local proxy (e.g., Laravel Valet) to mock API responses during development:
// config/touchestate.php
'url' => env('TOUCHESTATE_API_URL', 'http://touchestate.test'),
Documentation Gaps
src/Requests/ and src/Resources/ directories for undocumented endpoints.PropertyRequest.php for available query parameters.Idempotency Use idempotency keys for safe retries:
$property = TouchEstate::property()->create($data, [
'idempotency_key' => 'unique_key_123',
]);
Testing Webhooks Use the SDK’s webhook testing endpoint:
$testResponse = TouchEstate::webhook()->test('property.updated', $payload);
How can I help you explore Laravel packages today?