- How do I install the Mangopay PHP SDK in a Laravel project?
- Run `composer require mangopay4/php-sdk` in your project root. The SDK requires PHP 5.6+ (though Laravel 10+ needs PHP 8.1+), cURL, and OpenSSL. Ensure your `composer.json` includes the dependency, then autoload it via Laravel’s Composer autoloader.
- Does this SDK support Laravel’s service container for dependency injection?
- Yes. Register the `MangoPayApi` class in your Laravel service provider (e.g., `MangoPayServiceProvider`) using `app->bind()` or `app->singleton()`. Bind it to a config-driven instance with environment variables (e.g., `.env` for API keys and sandbox/production mode).
- How do I handle OAuth2 authentication in Laravel with this SDK?
- Configure the SDK’s `TemporaryFolder` for token storage in `config/mangopay.php`. For shared hosting or Docker, replace the default temp folder with Laravel’s filesystem (e.g., `storage/app/mangopay`). Use `MANGOPAY_SANDBOX=true` in `.env` to toggle between sandbox and live environments.
- Can I use this SDK with Laravel’s queue system for async operations?
- No, the SDK lacks native Laravel queue support. Wrap SDK calls in Laravel jobs (e.g., `VerifyBankAccountJob`) and dispatch them via `dispatch()`. Use `retryAfter` middleware for resilience. For webhooks, create a `HandleIncomingWebhook` job to process Mangopay events asynchronously.
- How do I validate Mangopay webhook HMAC signatures in Laravel?
- Create a middleware (e.g., `ValidateMangopaySignature`) that checks the `X-Ma-HMAC-Signature` header against Mangopay’s secret key. Use Laravel’s `app('http')` to access the request payload. Add the middleware to your webhook route (e.g., `Route::post('/mangopay/webhook', ...)->middleware(ValidateMangopaySignature::class)`).
- What’s the best way to manage idempotency for payments in Laravel?
- The SDK lacks built-in idempotency. Create a Laravel middleware (e.g., `MangoPayIdempotency`) to generate and store unique keys (e.g., UUIDs) in Redis or the database. Attach the key to payment requests via the SDK’s `headers` parameter and validate responses to prevent duplicate processing.
- Will this SDK work with Laravel 10+ and PHP 8.1+?
- Yes, but with caveats. The SDK supports PHP 5.6+, but PHP 8.1+ features (e.g., named arguments) aren’t used. No breaking changes exist, but consider wrapping SDK calls in Laravel’s `app()` helper for type safety. Test thoroughly, as the SDK lacks PHP 8.1+ optimizations like return type declarations.
- How do I configure mTLS for PCI compliance in Laravel?
- Set the SDK’s `ClientCertificate` and `ClientPrivateKey` in `config/mangopay.php` using Base64 strings or file paths. Store certificates securely in Laravel’s encrypted storage (e.g., `storage/encrypted/mangopay`). Use environment variables (e.g., `MANGOPAY_CERT_PATH`) to avoid hardcoding paths.
- Are there alternatives to this SDK for Laravel?
- For Mangopay, this is the official PHP SDK. Alternatives include building a custom Guzzle-based wrapper or using a generic HTTP client like `spatie/laravel-guzzle-promise`. However, the official SDK provides Mangopay-specific abstractions (e.g., `Users`, `BankAccounts`) that simplify integration with Laravel’s Eloquent or API resources.
- How do I test Mangopay interactions in Laravel’s testing environment?
- Use Mangopay’s sandbox environment by setting `MANGOPAY_SANDBOX=true` in `.env.testing`. Mock the SDK’s `MangoPayApi` instance in PHPUnit tests with Laravel’s `Mockery` or `createMock()`. Verify responses by asserting against Mangopay’s sandbox API docs (e.g., test users/wallets).