Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Stripe Php Laravel Package

stripe/stripe-php

The official Stripe PHP library provides convenient access to the Stripe API from PHP applications, with dynamically initialized resource classes compatible across many API versions. Requires PHP 7.2+ and curl, json, and mbstring. Install via Composer: composer require stripe/stripe-php.

View on GitHub
Deep Wiki
Context7

Stripe PHP is the official PHP client library for the Stripe API, giving PHP applications convenient, idiomatic access to payments, subscriptions, and financial infrastructure. Install it via Composer (composer require stripe/stripe-php) or manually, and it autoloads a rich set of resource classes that initialize dynamically from API responses—keeping it compatible across many Stripe API versions.

  • Official SDK with pre-defined classes for charges, customers, invoices, subscriptions, and more
  • Dynamic resource initialization for broad Stripe API version compatibility
  • Composer & manual installation support with init.php fallback
  • Pluggable HTTP clients (cURL by default, custom clients allowed)
  • Requires PHP 7.2+ with curl, json, and mbstring extensions
Frequently asked questions about Stripe Php
How do I integrate the Stripe PHP SDK into a Laravel application?
Install via Composer with `composer require stripe/stripe-php`, then bind the `StripeClient` to Laravel’s service container in a provider. Use the `StripeClient` class (v7.33.0+) for modern Laravel service patterns, or wrap legacy `Stripe::setApiKey()` calls in a service layer for better testability.
What’s the best way to handle Stripe webhooks in Laravel?
Use Laravel middleware to validate Stripe signatures, then dispatch events or queue jobs for processing. For example, create a `StripeWebhookMiddleware` to verify signatures, then handle events in a `StripeWebhookHandler` class. Always use `Webhook::constructEvent()` for validation.
Does the Stripe PHP SDK support Laravel’s dependency injection?
Yes. Register the `StripeClient` as a singleton in your service provider (e.g., `app[StripeClient] = fn() => new StripeClient(config('stripe.key'))`). This enables loose coupling and easy mocking in tests. Avoid instantiating `StripeClient` directly in controllers.
How do I mock Stripe API responses in Laravel tests?
Use Laravel’s `Http::fake()` to mock HTTP responses for Stripe API calls. For webhook testing, simulate payloads with `Webhook::constructEvent()` and validate signatures. Libraries like `stripe-mock` can also help simulate Stripe API responses locally.
What Laravel versions and PHP versions does the Stripe PHP SDK support?
The SDK supports PHP 7.2+ (though 7.2/7.3 are being phased out). For Laravel, it works with all modern versions (LTS 8.x, 9.x, 10.x). Always pin a specific SDK version in `composer.json` (e.g., `^16.0`) to avoid unexpected breaking changes during upgrades.
How can I optimize Stripe API performance in Laravel?
Cache frequent Stripe API calls (e.g., customer details) using Laravel’s cache layer or Redis. Configure `CurlClient` timeouts (e.g., 10s for connect, 30s for total) in production to prevent hanging requests. Offload long-running operations (e.g., refunds) to Laravel queues.
What’s the difference between the legacy `Stripe::setApiKey()` and the modern `StripeClient`?
The legacy `Stripe::setApiKey()` is a global static method, which can lead to tight coupling and testing difficulties. The modern `StripeClient` (introduced in v7.33.0) is an instantiable class that works better with Laravel’s service container and dependency injection. Migrate by replacing static calls with a service-bound `StripeClient`.
How do I store Stripe customer/subscription data in Laravel’s database?
Add columns like `stripe_customer_id` (string) and `stripe_subscription_status` (enum) to your Eloquent models. Use observers or jobs to sync Stripe data with your database. For example, create a `StripeCustomerObserver` to update local records when Stripe webhooks trigger events.
Are there security best practices for using Stripe in Laravel?
Store `STRIPE_SECRET_KEY` and `STRIPE_WEBHOOK_SECRET` in Laravel’s `.env` file. Always validate webhook signatures using `Webhook::constructEvent()`. Use Stripe’s idempotency keys for critical operations (e.g., charges) to prevent duplicate processing. Avoid logging sensitive Stripe data.
What alternatives exist for Stripe integration in Laravel?
For Laravel, the official `stripe/stripe-php` SDK is the most robust option. Alternatives include custom HTTP clients (e.g., Guzzle) for direct API calls, but these lack Stripe’s built-in resource classes and webhook validation. Libraries like `laravel-cashier` (for subscriptions) are higher-level but depend on the Stripe SDK.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
vento/laravel-airbrake
wfeller/laravel-batch
maco-studios/mage-os-installer
busarm/armie
siberfx/laravel-logger
kfteam1991/dcat-admin
dashed/dashed-laposta
dashed/dashed-ecommerce-montaportal
dashed/dashed-ecommerce-etsy
neohq/string-blade-compiler
log1x/acf-composer
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager