Skip to main content
Lunar’s Opayo addon integrates with Opayo’s (formerly SagePay) payment API to handle card payments, including 3D Secure authentication and saved card tokens.
This addon is currently in alpha. While every step is taken to ensure it works as intended, it will not be considered out of alpha until additional tests have been added.

Installation

Require the Composer package

Configure the service

Add the Opayo credentials to config/services.php.

Publish the configuration

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

Publish the views (optional)

The Opayo addon includes Blade and Livewire components for checkout. To customize these views, publish them.

Enable the driver

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

Configuration

The following options are available in config/lunar/opayo.php. The Opayo API endpoint is determined by the services.opayo.env value.

Backend Usage

Get a merchant session key

A merchant session key is required before tokenizing card details on the client side.

Authorize a payment

Capture a deferred payment

When using the deferred policy, payments must be captured separately after authorization.

Refund a payment

Retrieve a transaction

Fetch transaction details from the Opayo API. This method includes retry logic with up to 4 attempts.

3D Secure Authentication

When authorizing a payment, Opayo may require 3D Secure (3DS) authentication. The authorization response indicates whether a challenge is needed.

Handling the 3DS response

The ThreeDSecureResponse contains the following properties:

Completing the 3DS challenge

After the customer completes the 3DS challenge on the storefront, authorize the payment again with the challenge response data. For 3DS 2.x:
For 3DS 1.x:
For more information on 3D Secure with Opayo, see:

Saved Cards

Authenticated users can save their card details for future purchases. The addon stores card tokens (not actual card details) in the opayo_tokens table.
Saved payments must be enabled on the Opayo account before this feature can be used.

Saving a card

Pass the saveCard data key when authorizing a payment.
After a successful authorization, a new entry is created in the opayo_tokens table associated with the authenticated user. If a token already exists with the same last four digits for that user, it is replaced.

Using a saved card

To pay with a previously saved card, pass the token as the card_identifier and set reusable to true.
Responses are then handled the same as any other transaction, including 3D Secure challenges if required.

HasOpayoTokens trait

Add the HasOpayoTokens trait to the User model to access saved card tokens.
This provides an opayoTokens relationship.

Token fields

Livewire Component

The addon includes a Livewire payment form component that handles merchant key retrieval, card tokenization, and 3D Secure challenges.
The component emits the following events:

Including the scripts

Use the Blade directive to include both the compiled Opayo JavaScript and the Sagepay vendor script in the page layout.
To include only the Sagepay vendor script (if the compiled JavaScript is already loaded separately):

AVS/CVC Checks

The addon captures Address Verification System (AVS) and Card Verification Code (CVC) check results from Opayo. These are stored in the transaction metadata and can be accessed through the payment checks method.