- How do I install the Stripe PHP SDK in a Laravel project?
- Run `composer require stripe/stripe-php` in your Laravel project directory. The SDK will autoload via Composer’s PSR-4 autoloader, so no additional configuration is needed beyond requiring the `vendor/autoload.php` file.
- Which Laravel versions does the Stripe PHP SDK support?
- The SDK itself doesn’t enforce Laravel-specific constraints, but it requires PHP 7.2+ (with PHP 7.2/7.3 support dropping soon). It works seamlessly with Laravel 7+ and newer, including PHP 8+ features like typed properties and enums.
- How do I handle breaking changes like deprecated tax IDs in Laravel?
- For deprecated fields like `bm_crn` or `eg_tin`, update your Laravel models to remove or archive these fields. Use migrations to transform legacy data, and replace direct API calls with the SDK’s updated resource classes (e.g., `Account` for V2.Core.Account).
- Can I use the Stripe SDK with Laravel’s Payment Gateway interfaces?
- Yes. The SDK supports Delegated Checkout and payment methods like `bizum` (Spain) and `sunbit`. Extend Laravel’s `PaymentGateway` contract to wrap Stripe’s `PaymentIntent` or `CheckoutSession` classes, handling `requires_action` statuses with Laravel’s redirect helpers.
- How do I configure Stripe webhooks in Laravel to handle new fields like `fleet_data`?
- Update your Laravel webhook event handlers to dynamically parse new fields using `data_get()` or JSON decoding. For example, cast `fleet_data` to a JSON column in your database or use Laravel’s `HasAttributes` trait to handle dynamic payloads.
- What’s the best way to integrate Radar fraud detection with Laravel’s event system?
- Use Laravel’s event system to trigger custom events (e.g., `FraudAlert`) when Radar enums like `risk_level` or `event_type` are updated. Store `Radar.CustomerEvaluation` data in a JSON column (e.g., `risk_signals:json`) and dispatch events like `new FraudAlert($evaluation)`.
- How do I handle nullable fields (e.g., `emptyable(literal('account_funding'))`) in Laravel Eloquent models?
- Define nullable fields in your Eloquent models using PHP 8’s `?string` or `null` types. For example, add `protected ?string $transaction_type;` and use Laravel’s `fillable` array to allow null values. Use the nullsafe operator (`?->`) to avoid `NullPointerException`.
- Are there alternatives to the Stripe PHP SDK for Laravel?
- While the official `stripe/stripe-php` SDK is the most feature-complete, alternatives like `laravel-cashier` (for subscriptions) or `omnipay/stripe` (for payment gateways) exist. However, these often rely on the same underlying SDK or lack support for newer Stripe features like Delegated Checkout or Radar enhancements.
- How do I test Stripe webhooks locally in Laravel?
- Use Laravel’s `HttpTesting` facade to simulate webhook requests. Mock the Stripe SDK’s `Webhook` class to return test payloads, then assert responses using `assertJson()`. For testing preview features (e.g., `payment_record`), use Stripe’s test mode and validate dynamic fields with `assertArrayHasKey()`.
- What are the performance implications of using the Stripe SDK in production?
- The SDK is optimized for performance, using cURL by default for low-latency API calls. For high-throughput Laravel apps, consider caching Stripe API responses (e.g., `Customer` objects) with Laravel’s cache system. Monitor telemetry usage and disable it in production if GDPR compliance is critical.