### Install laravel-stripe via Composer Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Install the package via Composer. Run this in your Laravel project root. ```bash composer require jeffersongoncalves/laravel-stripe ``` -------------------------------- ### Create and archive products and prices Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Creates a product and a recurring price, then archives both. Amounts are in the smallest currency unit (1990 = US$ 19.90). Archiving sets active to false. ```php $product = Stripe::products()->create('Pro Plan', ['description' => 'Everything in one plan']); $price = Stripe::prices()->create( productId: $product['id'], unitAmount: 1990, // US$ 19.90 currency: 'usd', attributes: ['recurring' => ['interval' => 'month']], ); Stripe::products()->archive($product['id']); // active = false Stripe::prices()->archive($price['id']); ``` -------------------------------- ### Manage customers with Stripe facade Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Shows how to create, list, retrieve, update, delete, and find customers by email using the Stripe facade. Note that Stripe does not enforce email uniqueness, so findByEmail returns the first match or null. ```php use JeffersonGoncalves\Stripe\Facades\Stripe; $customer = Stripe::customers()->create('jane@example.com', ['name' => 'Jane Doe']); Stripe::customers()->list(['limit' => 10]); Stripe::customers()->get($customer['id']); Stripe::customers()->update($customer['id'], ['name' => 'Janet Doe']); Stripe::customers()->delete($customer['id']); // First customer with that email, or null — Stripe does not enforce uniqueness $existing = Stripe::customers()->findByEmail('jane@example.com'); ``` -------------------------------- ### Create billing portal session and redirect Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Creates a billing portal session for a customer and redirects to the portal URL. Use this to let customers manage their subscription and billing details. ```php $portal = Stripe::billingPortal()->createSession($customer['id'], 'https://example.com/account'); return redirect()->away($portal['url']); ``` -------------------------------- ### Create, update, cancel, and resume subscriptions Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Creates a subscription, lists active subscriptions for a customer, updates quantity with proration, cancels immediately or at period end, and resumes a canceled subscription. ```php $subscription = Stripe::subscriptions()->create($customer['id'], [ ['price' => $price['id'], 'quantity' => 1], ]); Stripe::subscriptions()->forCustomer($customer['id'], ['status' => 'active']); Stripe::subscriptions()->update($subscription['id'], [ 'items' => [['id' => $subscription['items']['data'][0]['id'], 'quantity' => 3]], 'proration_behavior' => 'always_invoice', ]); Stripe::subscriptions()->cancel($subscription['id']); // immediately Stripe::subscriptions()->cancel($subscription['id'], atPeriodEnd: true); // at period end Stripe::subscriptions()->resume($subscription['id']); // undo the above ``` -------------------------------- ### Work with invoices, payment intents, and events Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Lists paid invoices, pays and voids invoices, creates a payment intent in BRL, captures or cancels it, and lists events of a given type. Capture requires capture_method = manual. ```php Stripe::invoices()->forCustomer($customer['id'], ['status' => 'paid']); Stripe::invoices()->pay('in_123'); Stripe::invoices()->void('in_123'); $intent = Stripe::paymentIntents()->create(2500, 'brl', [ 'customer' => $customer['id'], 'automatic_payment_methods' => ['enabled' => 'true'], ]); Stripe::paymentIntents()->capture($intent['id']); // capture_method = manual Stripe::paymentIntents()->cancel($intent['id']); Stripe::events()->ofType('checkout.session.completed'); ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Runs the test suite for the package. Use this command to execute all tests defined in the project. ```bash composer test ``` -------------------------------- ### Publish Stripe config with artisan vendor:publish Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Publish the package configuration file. Use the tag 'stripe-config' to publish the config. ```bash php artisan vendor:publish --tag=stripe-config ``` -------------------------------- ### Create a Checkout session and redirect Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Creates a Stripe Checkout session for a subscription and redirects the user to the hosted payment page. The success URL includes the {CHECKOUT_SESSION_ID} placeholder. ```php $session = Stripe::checkout()->create( lineItems: [['price' => $price['id'], 'quantity' => 1]], mode: 'subscription', successUrl: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}', attributes: [ 'customer' => $customer['id'], 'cancel_url' => 'https://example.com/cancel', ], ); return redirect()->away($session['url']); ``` -------------------------------- ### Set Stripe credentials in .env Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Set your Stripe credentials in the .env file. Only STRIPE_SECRET is used by the package; STRIPE_KEY is kept for client-side code. Find keys under Developers > API keys and the webhook secret under Developers > Webhooks. ```env STRIPE_KEY=pk_test_... STRIPE_SECRET=sk_test_... STRIPE_WEBHOOK_SECRET=whsec_... ``` -------------------------------- ### Configure Stripe package in config/stripe.php Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Configuration file for the Laravel Stripe package. Defines environment-based settings for secret key, publishable key, base URL, API version, webhook secret, and default limit. The base URL defaults to 'https://api.stripe.com' and the default limit defaults to 10. ```php // config/stripe.php return [ 'secret' => env('STRIPE_SECRET'), 'key' => env('STRIPE_KEY'), 'base_url' => env('STRIPE_BASE_URL', 'https://api.stripe.com'), 'api_version' => env('STRIPE_API_VERSION'), 'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'), 'default_limit' => env('STRIPE_DEFAULT_LIMIT', 10), ]; ``` -------------------------------- ### Handle Stripe webhooks with signature verification Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Sets up a webhook route that verifies the Stripe-Signature header before processing events. The route disables CSRF middleware and returns 204 No Content. ```php use Illuminate\Http\Request; use JeffersonGoncalves\Stripe\Facades\Stripe; Route::post('/stripe/webhook', function (Request $request) { abort_unless(Stripe::webhooks()->verifyRequest($request), 403); $event = $request->json()->all(); match ($event['type']) { 'checkout.session.completed' => /* provision access */ null, 'customer.subscription.deleted' => /* revoke access */ null, 'invoice.payment_failed' => /* notify the customer */ null, default => null, }; return response()->noContent(); })->withoutMiddleware([VerifyCsrfToken::class]); ``` -------------------------------- ### Catch StripeException and inspect error details Source: https://github.com/jeffersongoncalves/laravel-stripe/blob/main/README.md Catches StripeException for non-2xx API responses, checks the error code, and logs the message with the error body. Missing required fields throw InvalidArgumentException before any HTTP call. ```php use JeffersonGoncalves\Stripe\Exceptions\StripeException; try { Stripe::subscriptions()->get('sub_missing'); } catch (StripeException $e) { if ($e->errorCode() === 'resource_missing') { // ... } logger()->error($e->getMessage(), $e->errorBody()); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.