Installation
Require the Composer package
Publish the configuration
This will publish the configuration underconfig/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 inconfig/lunar/payments.php.
Add Stripe credentials
Add the Stripe credentials toconfig/services.php.
Configuration
The following options are available inconfig/lunar/stripe.php.
| Key | Default | Description |
|---|---|---|
webhook_path | stripe/webhook | The URI path for the Stripe webhook endpoint |
policy | automatic | Determines the capture policy. automatic captures payment immediately; manual authorizes first and captures later |
sync_addresses | true | When enabled, billing and shipping addresses stored on the Stripe PaymentIntent are synced to the order |
status_mapping | See below | Maps Stripe PaymentIntent statuses to Lunar order statuses |
actions.store_charges | StoreCharges::class | The action class responsible for storing charge data as transactions |
Status mapping
The default status mapping translates Stripe PaymentIntent statuses to Lunar order statuses.Backend Usage
Create a PaymentIntent
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
Retrieve the PaymentIntent ID from a cart
Fetch an existing PaymentIntent
Sync an existing PaymentIntent
If a PaymentIntent has been created and the cart contents change, callsyncIntent to update the intent with the correct totals.
Update an existing PaymentIntent
To update specific properties on the PaymentIntent without recalculating the cart, useupdateIntent.
Cancel a PaymentIntent
To cancel a PaymentIntent, provide a valid cancellation reason. The addon includes a PHP enum for the available reasons.| Enum Case | Value |
|---|---|
CancellationReason::ABANDONED | abandoned |
CancellationReason::DUPLICATE | duplicate |
CancellationReason::REQUESTED_BY_CUSTOMER | requested_by_customer |
CancellationReason::FRAUDULENT | fraudulent |
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 themanual 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:webhook_path option in config/lunar/stripe.php.
Supported events
The webhook listens for the following Stripe events:payment_intent.succeededpayment_intent.payment_failed
Webhook signing secret
Add the webhook signing secret toconfig/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.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 theProcessesEventParameters implementation.
Database
The addon creates astripe_payment_intents table to track PaymentIntents and their relationship to carts and orders.
| Field | Type | Description |
|---|---|---|
id | id | Primary key |
cart_id | foreignId | Associated cart |
order_id | foreignId nullable | Associated order |
intent_id | string | Stripe PaymentIntent ID |
status | string nullable | Current PaymentIntent status |
event_id | string nullable | Stripe event ID |
processing_at | timestamp nullable | |
processed_at | timestamp nullable | |
created_at | timestamp | |
updated_at | timestamp |