Overview
Lunar uses a driver-based approach for payments. This means any payment provider can be supported, either through first-party add-ons, community packages, or a custom driver built for the specific needs of a storefront. By default, Lunar ships with anOfflinePayment driver suitable for cash-in-hand or manual payment scenarios. For online payments, a driver for the desired payment provider should be installed or created.
Configuration
Payment configuration is located inconfig/lunar/payments.php. This file defines the default payment type and a list of available payment types, each mapped to a driver.
| Key | Description |
|---|---|
driver | The registered payment driver to use for this type |
authorized | The order status to set when payment is authorized |
setConfig method automatically.
Usage
Getting a payment driver
To retrieve a payment driver instance, pass the desired payment type to thePayments facade. This returns an instance of the driver registered for that type.
Setting the cart
Before authorizing a payment, set the cart on the driver.Passing additional data
Some payment providers require additional data such as payment tokens or intent IDs. Pass this data using thewithData method.
Setting an order
In some cases, it may be necessary to set an existing order on the driver rather than a cart. Theorder method handles this.
Authorizing a payment
Once the driver is configured, call theauthorize method to process the payment. This returns a PaymentAuthorize response.
Method chaining
All setter methods on the driver returnself, allowing for a fluent API.
Response types
Payment drivers return one of three data transfer objects depending on the operation.PaymentAuthorize
authorize method.
| Property | Type | Description |
|---|---|---|
success | bool | Whether the authorization was successful |
message | ?string | An optional message from the provider |
orderId | ?int | The ID of the created or associated order |
paymentType | ?string | The payment type identifier |
PaymentCapture
capture method when capturing a previously authorized payment.
| Property | Type | Description |
|---|---|---|
success | bool | Whether the capture was successful |
message | string | A message from the provider |
PaymentRefund
refund method when refunding a captured payment.
| Property | Type | Description |
|---|---|---|
success | bool | Whether the refund was successful |
message | ?string | An optional message from the provider |
Events
PaymentAttemptEvent
TheLunar\Events\PaymentAttemptEvent is dispatched whenever a payment authorization is attempted. This event receives the PaymentAuthorize response object.
Payment checks
Some payment providers return verification checks related to 3D Secure, address verification, or other fraud prevention measures. These checks are accessible on aLunar\Models\Transaction model via the paymentChecks method.
For details on the Transaction model, order creation, and order management, see the Orders reference.
Available drivers
First party
| Driver | Package |
|---|---|
| Stripe | lunarphp/stripe |