Sage Pay integration for Craft Commerce 3.3+

3.0.0 2021-04-20 16:53 UTC

This package is auto-updated.

Last update: 2022-01-02 05:08:24 UTC


Sage Pay for Craft Commerce icon

Sage Pay for Craft Commerce

This plugin provides a Sage Pay integration for Craft Commerce.


This plugin requires Craft 3.6 and Craft Commerce 3.3 or later.


You can install this plugin from the Plugin Store or with Composer.

From the Plugin Store

Go to the Plugin Store in your project’s Control Panel and search for Sage Pay for Craft Commerce”. Then click on the “Install” button in its modal window.

With Composer

Open your terminal and run the following commands:

# go to the project directory
cd /path/to/my-project.test

# tell Composer to load the plugin
composer require craftcms/commerce-sagepay

# tell Craft to install the plugin
./craft install/plugin commerce-sagepay


To add a Sage Pay payment gateway, go to Commerce → Settings → Gateways, create a new gateway, and set the gateway type to either “Sage Pay Direct” or “Sage Pay Server”.

Tip: The Vendor and Referrer ID gateway settings can be set to environment variables. See Environmental Configuration in the Craft docs to learn more about that.

Using the legacy basket format

Sage Pay has two formats for submit basket data — Basket and BasketXML. The Basket is a legacy format, but is the only way to integrate with Sage 50 Accounts.

To use the legacy format, simply turn on the appropriate setting in the gateway settings. To complete your integration with Sage 50 Accounts you can use the following event:

use \craft\commerce\omnipay\base\Gateway as BaseGateway;

Event::on(BaseGateway::class, BaseGatewa::EVENT_AFTER_CREATE_ITEM_BAG, function(ItemBagEvent $itemBagEvent) {
    $orderLineItems = $itemBagEvent->order->getLineItems();

     * @var $item Item
    foreach ($itemBagEvent->items as $key => $item) {

        if (!isset($orderLineItems[$key])) {

        $orderLineItem  = $orderLineItems[$key];

        // Make sure that the description and price are the same as we are relying upon the order
        // of the Order Items and The OmniPay Item Bag to be the same
        if ($orderLineItem->getDescription() != $item->getDescription()) {

        if ($orderLineItem->price != $item->getPrice()) {

        $sku = $orderLineItem->getSku();

        // Place the SKU within [] as the Product Record for the Sage 50 Accounts Integration
        $description = '[' . $sku . ']' . $item->getDescription();