stripe/stripe-php
Official Stripe PHP SDK for accessing the Stripe API. Install via Composer, configure your API key, and use resource classes that map to Stripe objects and endpoints. Supports PHP 7.2+ (older versions being phased out).
stripe/stripe-php package is a well-maintained, production-ready SDK for Stripe’s API, designed to work effortlessly with Laravel’s dependency injection, service container, and event-driven architecture. Its object-oriented design aligns with Laravel’s Eloquent ORM and service-layer patterns, enabling clean abstraction of Stripe operations (e.g., payments, subscriptions, customers).StripeClient and service-based approach (post-v7.33.0) maps neatly to Laravel’s service providers and facades, allowing for centralized configuration (e.g., API keys, logging) and modular usage across the application.payment_intent.succeeded) via Laravel’s Event facade or dedicated listeners.$stripe->customers->create()) reduces boilerplate, aligning with Laravel’s emphasis on expressive syntax. Laravel’s service container can instantiate the StripeClient once and inject it into controllers/services.Route::post('/stripe-webhook', [StripeWebhookController::class, 'handle']);
The controller can leverage Laravel’s Http and Validator components to process payloads.composer require stripe/stripe-php:^16.0 to future-proof.Stripe\Stripe::setCABundlePath() if custom CA bundles are required.-beta.X) may introduce instability. Use feature flags or Laravel’s environment-based configuration to toggle them..env or a secrets manager (e.g., AWS Secrets Manager)? Use Laravel’s config('services.stripe.key') for centralization.Stripe\Webhook::constructEvent().invalid_request_error) trigger Laravel’s exception handlers or custom logging? Use Laravel’s App\Exceptions\Handler to normalize errors.Testing facade can mock the StripeClient for unit tests.StripeClient in AppServiceProvider:
$this->app->singleton(\Stripe\StripeClient::class, function ($app) {
return new \Stripe\StripeClient(config('services.stripe.key'));
});
Stripe) to simplify usage:
facade_root() { return new \Stripe\StripeClient(config('services.stripe.key')); }
PaymentSucceeded).customers, payments) with foreign keys to Laravel’s primary models (e.g., users).StripeSubscriptionJob).composer require stripe/stripe-php..env and register the StripeClient in Laravel’s service container.file_get_contents() with $stripe->charges->create()).replicating trait or observers).Mockery to test StripeClient interactions.stripe/stripe-php:^15.0 (PHP 7.4+).Stripe\Stripe::setApiVersion() if targeting specific endpoints.StripeClient pattern.try {
$charge = $stripe->charges->create($params);
} catch (\Stripe\Exception\CardException $e) {
// Handle error (e.g., redirect to payment form)
}
composer update workflow with testing.composer.json to avoid unintended major updates:
"stripe/stripe-php": "^16.0"
\Stripe\Stripe::setLogger(new \Monolog\Logger('stripe'));
log() or a dedicated service.getLastResponse() to debug API responses:
$customer = $stripe->customers->create([...]);
logger()->debug($customer->getLastResponse()->headers);
retry helper or a custom decorator:
$stripe->setMaxNetworkRetries(3);
cache() to store rate-limiting or throttling states for Stripe API calls.customers->all() with pagination) to reduce latency.stripe_customer_id) to optimize queries.How can I help you explore Laravel packages today?