- How do I install the online-payments/sdk-php package in a Laravel project?
- Use Composer to install the package with `composer require online-payments/sdk-php`. Then, configure your API credentials in Laravel’s `.env` file (e.g., `PAYMENT_API_KEY`) and bind the SDK to Laravel’s service container in a service provider.
- Which Laravel versions does this SDK officially support?
- The package is designed for Laravel 10.x and 11.x, but verify compatibility with your specific version. Test thoroughly with Laravel’s LTS releases to avoid potential integration issues, especially if the SDK relies on newer PHP features.
- Can I use this SDK with Laravel’s HTTP client or Guzzle instead of the built-in client?
- Yes, the SDK likely supports dependency injection for HTTP clients. Replace its default client with Laravel’s HTTP client or GuzzleHttp by binding a custom client in the service container, enabling middleware like retries or logging.
- How should I handle webhooks from Online Payments in Laravel?
- Use Laravel’s route model binding or middleware to validate webhook signatures (if the SDK doesn’t handle this). Dispatch events (e.g., `PaymentSucceeded`) for async processing via queues, and store critical webhook data in a database for idempotency.
- Does the SDK support async payment processing with Laravel queues?
- The SDK itself may not enforce async operations, but you can wrap its methods in a job (e.g., `PaymentJob`) extending `ShouldQueue`. Offload long-running operations like refunds or captures to queues for better performance.
- How do I configure the SDK’s API credentials securely in Laravel?
- Store sensitive credentials like `PAYMENT_API_KEY` in Laravel’s `.env` file. Use Laravel’s `config()` helper or environment variables to pass these to the SDK’s client during initialization, avoiding hardcoded values.
- What’s the best way to test this SDK in Laravel?
- Mock the SDK’s HTTP client using Laravel’s `MockHttpClient` for unit tests. For integration tests, use a sandbox environment (if provided by Online Payments) or stub responses. Test edge cases like failed payments and webhook retries.
- Can I integrate this SDK with Laravel’s authorization policies?
- Yes, use Laravel’s `Gate` or `Policy` classes to restrict access to payment methods (e.g., `charge()`). Define policies in `app/Policies/PaymentPolicy.php` and attach them to models or roles for granular control.
- How does the SDK handle errors or failed payment requests?
- The SDK should throw exceptions for API errors or validation failures. Catch these exceptions in Laravel’s middleware or controllers and log them. For retries, use Laravel’s `retry()` helper or queue jobs with exponential backoff.
- Are there alternatives to this SDK for Laravel payment integrations?
- For Laravel, consider official provider SDKs like `stripe/stripe-php` or `paypal/rest-api-sdk-php`. Open-source alternatives include `omnipay/omnipay` for multi-gateway support. Evaluate based on features, maintenance, and Laravel compatibility.