- How do I install the dzangocart/client package in a Laravel project?
- Run `composer require dzangocart/client` in your project directory. The package has no Laravel-specific dependencies beyond PHP 7.4+ and Guzzle 3.x, so it integrates seamlessly with Laravel’s service container. Ensure your `composer.json` pins Guzzle to `^3.9` to avoid deprecation warnings.
- Does this package support Laravel’s HTTP client or should I use Guzzle directly?
- While the package uses Guzzle 3.x under the hood, you can wrap it in a Laravel service provider to expose a cleaner facade (e.g., `DzangoCart::cart()->addItem()`). This lets you leverage Laravel’s HTTP macros or queue jobs while keeping the Guzzle dependency isolated.
- What Laravel versions does dzangocart/client officially support?
- The package works with Laravel 5.5+ due to its PHP 7.4+ requirement, but Guzzle 3.x may need polyfills for newer Laravel versions. Test thoroughly on your target Laravel version (8/9/10) and consider upgrading Guzzle to 7+ if compatibility issues arise.
- How do I handle authentication with Dzangocart using this client?
- The client uses the `opichon/pcrypt` library for token handling, which likely requires an API key or JWT. Configure credentials in your `.env` (e.g., `DZANGO_API_KEY`) and pass them to the client constructor. If Dzangocart uses OAuth, you’ll need to extend the client or use Laravel Passport for auth.
- Can I use this package for webhook processing in Laravel?
- Yes, if Dzangocart supports webhooks, create a Laravel queue job to process incoming payloads. Use the client’s middleware to validate signatures (if needed) and dispatch events like `OrderCreated`. Pair with Laravel Horizon for monitoring and retries.
- What’s the best way to structure dzangocart/client in a Laravel app?
- Bind the client as a singleton in a service provider (e.g., `DzangoCartServiceProvider`) to centralize configuration. Use dependency injection to pass the client to controllers or jobs, and consider facades for convenience. Example: `app()->singleton(DzangoCartClient::class, fn($app) => new DzangoCartClient(config('services.dzangocart')));`.
- Are there alternatives to this package for Laravel e-commerce integrations?
- For REST APIs, Laravel’s native `Http::post()` or `Http::macro()` may suffice if you prefer minimal dependencies. If Dzangocart uses GraphQL, consider `php-graphql-client`. For OAuth-heavy workflows, Laravel Sanctum or Passport could reduce coupling. Evaluate based on Dzangocart’s API contract and your project’s security needs.
- How do I handle API failures or rate limits with this client?
- Add Guzzle middleware for retries (e.g., exponential backoff) and configure timeouts in the client. For Laravel, wrap API calls in `try-catch` blocks and log failures. Consider caching responses locally with Laravel Cache or implementing fallback logic for critical paths.
- Does this package support testing Dzangocart integrations in Laravel?
- Yes, mock the `DzangoCartClient` in tests using Laravel’s mocking tools. Use `Http::fake()` to simulate API responses or create a test service provider that returns mock data. For complex flows, test queue jobs and event listeners separately with `Queue::fake()`.
- Why is Guzzle 3.x used instead of a newer version, and can I upgrade it?
- Guzzle 3.x is used for backward compatibility with Dzangocart’s API, but it’s outdated and may lack features like middleware. You can manually upgrade to Guzzle 7+ by forking the package or creating a wrapper. Test thoroughly, as breaking changes may affect request/response handling.