Skip to main content
Lunar’s Stripe addon integrates with Stripe’s Payment Intents API to handle card payments, including support for automatic and manual capture policies, webhooks, and address synchronization.

Installation

Require the Composer package

Publish the configuration

This will publish the configuration under config/lunar/stripe.php.

Publish the views (optional)

The Stripe addon includes helper Blade and Livewire components for use during checkout. To customize these views, publish them.

Enable the driver

Set the driver in config/lunar/payments.php.

Add Stripe credentials

Add the Stripe credentials to config/services.php.
Keys can be found in the Stripe Dashboard.

Configuration

The following options are available in config/lunar/stripe.php.

Status mapping

The default status mapping translates Stripe PaymentIntent statuses to Lunar order statuses.

Backend Usage

Create a PaymentIntent

This method creates a Stripe PaymentIntent from a cart and stores the resulting ID in the cart’s meta data. If a PaymentIntent already exists for the cart, the existing one is returned instead. The following parameters are sent by default:
If the cart has a shipping address, the addon also calls updateShippingAddress() to sync the address to the PaymentIntent. Any additional parameters passed in the $options array are merged with the defaults.

Fetch or create a PaymentIntent

This is a convenience method that fetches the existing PaymentIntent for a cart if one exists, or creates a new one.

Retrieve the PaymentIntent ID from a cart

Alternatively, the PaymentIntent ID can be accessed directly from the cart’s meta data.

Fetch an existing PaymentIntent

Sync an existing PaymentIntent

If a PaymentIntent has been created and the cart contents change, call syncIntent to update the intent with the correct totals.

Update an existing PaymentIntent

To update specific properties on the PaymentIntent without recalculating the cart, use updateIntent.
A PaymentIntent can also be updated directly by ID.

Cancel a PaymentIntent

To cancel a PaymentIntent, provide a valid cancellation reason. The addon includes a PHP enum for the available reasons.
Available cancellation reasons:

Update the shipping address

To sync the cart’s shipping address to the PaymentIntent without manually specifying all fields, use the helper method.

Retrieve a payment method

Charges

Retrieve a specific charge

Get all charges for a PaymentIntent

Capture and Refund

When using the manual capture policy, payments are authorized but not captured immediately. The Lunar payments system can then be used to capture or refund transactions.

Capturing a payment

Refunding a payment

Webhooks

The addon provides a webhook endpoint that can be registered in the Stripe Dashboard. Follow the Stripe webhook guide to set this up. The webhook endpoint is available at:
The path is configurable via the webhook_path option in config/lunar/stripe.php.

Supported events

The webhook listens for the following Stripe events:
  • payment_intent.succeeded
  • payment_intent.payment_failed

Webhook signing secret

Add the webhook signing secret to config/services.php.

Manual order processing

If the webhook is not used, or if an order needs to be processed manually, the payment can be authorized directly.

Livewire Component

The addon includes a Livewire payment form component that handles PaymentIntent creation and Stripe Elements rendering.
To include the Stripe.js script, use the Blade directive in the page layout.

Storefront Examples

API route for PaymentIntents

Set up a backend API route to fetch or create the PaymentIntent.

Vue.js

This example uses Stripe’s Payment Elements. For more information, see the Stripe Elements guide.

Payment component

Extending

Webhook event parameters

To process a PaymentIntent and link it to an order, the addon needs the PaymentIntent ID and an optional order ID. By default, the PaymentIntent ID is extracted from the Stripe event and the order ID is looked up from the PaymentIntent metadata. This behavior can be customized by overriding the ProcessesEventParameters implementation.

Database

The addon creates a stripe_payment_intents table to track PaymentIntents and their relationship to carts and orders.

Events

CartMissingForIntent

Dispatched when a webhook is received for a PaymentIntent, but no matching cart or order can be found.

Testing

The addon includes a mock client for testing without making real Stripe API calls.