spatie/laravel-float-sdk
Laravel-friendly SDK for the Float.com API (v3). Configure your API token and user agent, then use the FloatClient to access Float resources from your Laravel app. Not a complete API implementation yet—PRs welcome.
Installation:
composer require spatie/laravel-float-sdk
Publish the config file (if needed):
php artisan vendor:publish --provider="Spatie\FloatSdk\FloatSdkServiceProvider"
Configuration:
Update .env with Float API credentials:
FLOAT_API_KEY=your_api_key_here
FLOAT_API_SECRET=your_api_secret_here
FLOAT_BASE_URL=https://api.float.com/v3
First Use Case: Fetch a client's data:
use Spatie\FloatSdk\Float;
$client = Float::client()->find(123);
src/Spatie/FloatSdk/Float.php for available endpoints..env and config/float-sdk.php for API settings.Client Management:
// Create
$client = Float::client()->create([
'name' => 'John Doe',
'email' => 'john@example.com',
]);
// Update
$client->update(['email' => 'new@example.com']);
// Delete
$client->delete();
Invoices & Payments:
// Fetch invoices
$invoices = Float::invoice()->all(['limit' => 10]);
// Create payment
$payment = Float::payment()->create([
'invoice_id' => 456,
'amount' => 100.00,
'method' => 'bank_transfer',
]);
Webhooks:
Configure webhook endpoints in config/float-sdk.php:
'webhooks' => [
'endpoint' => '/float-webhook',
'events' => ['invoice.paid', 'client.created'],
],
Handle incoming webhooks in a Laravel route:
Route::post('/float-webhook', [FloatWebhookHandler::class, 'handle']);
class FloatClientService {
public function createClient(array $data) {
return Float::client()->create($data);
}
}
try {
$client = Float::client()->find(123);
} catch (\Spatie\FloatSdk\Exceptions\FloatException $e) {
Log::error("Float API Error: " . $e->getMessage());
abort(500);
}
$this->mock(Float::class)->shouldReceive('client')->andReturnSelf();
API Rate Limits:
$client = Cache::remember("float_client_{$id}", now()->addMinutes(5), fn() => Float::client()->find($id));
HTTP_429 responses and implement retries with exponential backoff.Webhook Verification:
X-Float-Signature header:
use Spatie\FloatSdk\Webhook;
$payload = request()->getContent();
$signature = request()->header('X-Float-Signature');
if (!Webhook::verify($payload, $signature)) {
abort(403, 'Invalid signature');
}
Idempotency:
idempotency_key for critical operations (e.g., payments) to avoid duplicates:
$payment = Float::payment()->create([
'invoice_id' => 456,
'idempotency_key' => 'unique-key-123',
]);
FLOAT_DEBUG=true in .env to log raw API responses.Float::extend(function ($client) {
$client->onRequest(function ($request) {
Log::debug('Float Request:', $request->toArray());
});
});
Float::extend(function ($client) {
$client->customEndpoint = function ($method, $path, $data = []) {
return $client->request($method, $path, $data);
};
});
Float::extend(function ($client) {
$client->withMiddleware(function ($request) {
$request->headers->set('X-Custom-Header', 'value');
});
});
event(new FloatWebhookReceived($payload, $signature));
FLOAT_BASE_URL matches Float’s environment (e.g., https://api.float.com/v3 for production).config/float-sdk.php:
'timeout' => 30, // seconds
'verify_ssl' => env('FLOAT_VERIFY_SSL', true),
How can I help you explore Laravel packages today?