- How do I install and set up **bitrix24/b24phpsdk** in a Laravel project?
- Install via Composer with `composer require bitrix24/b24phpsdk`, then register the service provider in `config/app.php`. Use the `B24` facade or dependency injection to access clients like `B24::leads()` or `B24::contacts()`. The SDK auto-configures Guzzle under the hood for HTTP requests.
- Does this SDK support Laravel’s service container and facades?
- Yes, the SDK is designed for Laravel’s ecosystem. Bind it as a singleton in `AppServiceProvider` (e.g., `B24Client`) and use facades like `B24::deals()->create()` for fluent syntax. Alternatively, inject `B24ClientInterface` directly into controllers or services.
- What Laravel versions does **bitrix24/b24phpsdk** support?
- The SDK targets Laravel 8.x and 9.x, leveraging features like dependency injection and facades. For Laravel 7.x, check the package’s `composer.json` for compatibility notes or fork the project to adapt to older DI containers.
- How does OAuth authentication work with Laravel’s caching?
- Store OAuth tokens in Laravel’s cache (e.g., `cache()->remember()`) or database for persistence. The SDK handles token refreshes, but you can extend it to dispatch Laravel events (e.g., `B24TokenRefreshed`) or use queue jobs for async refreshes to avoid race conditions.
- Can I map Bitrix24 CRM entities (e.g., Deals) to Laravel Eloquent models?
- Yes, the SDK returns raw API responses, but you can hydrate them into custom DTOs or Eloquent models. Use Laravel’s `fillable` properties or accessors to map fields like `deal_stage` or `contact_id` to your database schema.
- How do I handle Bitrix24 API rate limits in Laravel?
- Leverage Laravel middleware to enforce rate limits. For example, create a middleware that checks `X-RateLimit-Remaining` headers and throttles requests using `throttle()` or `rateLimit()` helpers. The SDK’s Guzzle client supports middleware integration.
- What’s the best way to test this SDK without hitting the Bitrix24 API?
- Use the `B24ClientInterface` to mock dependencies in PHPUnit. Replace the real client with a test double that returns predefined responses. For example, bind a mock in `AppServiceProvider` during testing: `$app->bind(B24ClientInterface::class, fn() => new MockB24Client())...`
- How do I extend the SDK for custom Bitrix24 endpoints not covered by the package?
- Extend the SDK via service providers or traits. Add custom methods to the `B24Client` class or create a new client (e.g., `B24CustomClient`) that extends the base client. Register it in `AppServiceProvider` and use it alongside the default clients.
- What happens if the Bitrix24 API is unavailable? How can I implement retries or fallbacks?
- Use Laravel’s queue system to retry failed API calls. Wrap SDK operations in a `try-catch` block and dispatch a job (e.g., `RetryB24ApiCall`) with exponential backoff. For critical failures, implement a fallback (e.g., cache stale data or notify admins via Laravel Notifications).
- Are there alternatives to this SDK for Bitrix24 integrations in Laravel?
- For lightweight needs, use Guzzle directly with Bitrix24’s API docs. For more structure, consider forking this SDK or using a generic HTTP client like `spatie/laravel-query-builder` with custom Bitrix24 logic. However, this SDK offers Laravel-native abstractions (e.g., facades, events) that alternatives lack.