PHPackages                             dwmsw/sagepay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. dwmsw/sagepay

ActiveLibrary[Payment Processing](/categories/payments)

dwmsw/sagepay
=============

Sagepay Direct V3 Wrapper

1.9.0(8y ago)67.7k2[1 issues](https://github.com/dwmsw/sagepay/issues)GPL-3.0PHP

Since Nov 5Pushed 8y ago4 watchersCompare

[ Source](https://github.com/dwmsw/sagepay)[ Packagist](https://packagist.org/packages/dwmsw/sagepay)[ Docs](https://github.com/dwmsw/sagepay)[ RSS](/packages/dwmsw-sagepay/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (16)Used By (0)

dwmsw/sagepay
=============

[](#dwmswsagepay)

[![Build Status](https://camo.githubusercontent.com/7faeef2509ca376c59360d87d91e7c5a73e788b01b4da5b5e88d10c8a07dbfff/68747470733a2f2f7472617669732d63692e6f72672f64776d73772f736167657061792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dwmsw/sagepay)[![Code Climate](https://camo.githubusercontent.com/2aeef738b72e20e241187d6ab5efdaf4d676c4b16cfb530354308c37d5a7a1f0/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64776d73772f736167657061792f6261646765732f6770612e737667)](https://codeclimate.com/github/dwmsw/sagepay)[![Test Coverage](https://camo.githubusercontent.com/41d525f71eb0bab7fff64d1c8040e9ea5475dc38afc2a6f31c12678bc0f855a9/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64776d73772f736167657061792f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/dwmsw/sagepay)

Description
-----------

[](#description)

dwmsw/sagepay is a library for interacting with the [Sagepay Direct v3.00 protocol](http://www.sagepay.co.uk/file/12236/download-document/DIRECT_Integration_and_Protocol_Guidelines_010814.pdf)

It aims to make interacting with Sagepay as easy as possible and is available as a [composer](https://getcomposer.org/) package on [packagist](https://packagist.org/packages/dwmsw/sagepay)

This wrapper doesn't include any database implementations, it is purely here to make interacting with the Sagepay API easier and to add a level of validation. All methods that send the data to Sagepay will return the response to you in an associative array, with nothing added or removed.

It has been built this way as to not restrict developers to certain database implementations or structures. We prefer for you to be able to use the data however you like.

\##Installation

Installing via composer is the best way. Run the following from the CLI

`composer require dwmsw/sagepay`

What is implemented?
--------------------

[](#what-is-implemented)

- Payments (with or without tokens)
- Deferred Payments w/ release
- Discounts
- Refunds
- 3D Secure

Basic Usage
-----------

[](#basic-usage)

**Payment**

```
// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();

// New Basket instance
$basket = new dwmsw\sagepay\Basket();
// Add an item to the basket
$basket->addItem(new dwmsw\sagepay\Item('Test Item', 30.00, 6, 1));
// Add another item to the basket
$basket->addItem(new dwmsw\sagepay\Item('Test Item Two', 30.00, 6, 2));
// Add a discount
$basket->addDiscount(new dwmsw\sagepay\Discount(50.00, 'This is a discount'));

// Set the Basket
$sagepay->setBasket($basket);

// Set up the config
$sagepay->setConnectionMode(CONNECTION MODE TEST/LIVE);
$sagepay->setVendorName(YOUR VENDOR NAME);
$sagepay->setCurrency('GBP');
$sagepay->setApplyAvsCv2(1);
$sagepay->setApply3dSecure(0);
$sagepay->setGiftAid(0);

$vendorTxCode = md5(rand(1, 1000));

// TX Specific bits
$sagepay->setVendorTxCode($vendorTxCode);
$sagepay->setDescription('Test Payment');
$sagepay->setCustomerEmail('daryll@digitalwebmedia.co.uk');

// Set up addresses
$BillingAddress = new dwmsw\sagepay\Address();
$BillingAddress->setName('Daryll', 'Doyle');
$BillingAddress->setPhone('46554789658');
$BillingAddress->setAddress('88', 'Test Address', 'Town', 'GB', '412');

// Set Addresses into the class
$sagepay->setBillingAddress($BillingAddress);
// Delivery Address can be a different instance of address if needed
$sagepay->setDeliveryAddress($BillingAddress);

// New card instance
$card = new dwmsw\sagepay\Card();
// Card details
$card->setCardHolder('Mr D Doyle');
$card->setCardType('VISA');
$card->setCardNumber('4929000000006');
$card->setStartDate(false);
$card->setExpiryDate('1216');
$card->setCV2('123');

$sagepay->setCard($card);

$output = $sagepay->register('PAYMENT');

// Do whatever you want with $output
```

To use tokens with payments, you'll initially need to pass the following in your setup:

```
$sagepay->setCreateToken(1);
```

This will tell sagepay to return you a token when payments are successful. You can then use this token, to make further payments.

To make a payment using a token, you don't enter the card details, but instead use the following:

```
// New card instance
$card = new dwmsw\sagepay\Card();
$card->setToken('TOKEN');
$card->setCV2('CV2');

$sagepay->setCard($card);
```

When using a token, the class automatically sets `StoreToken` to `1` to persist the token. Although I will probably add an option to change this at some point!

**DEFERRED**

```
// As above, but use the following line
$output = $sagepay->register('DEFERRED');
```

**RELEASE**

```
// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
// Make the release
$output = $sagepay->release('VPSTxId', 'SecurityKey', 'vendorTxCode', 'TxAuthNo', 'AMOUNT TO RELEASE');

// Do whatever with $output
```

**REFUND**

```
// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
// Make the refund
$output = $sagepay->refund('NEWvendorTxCode', 'AMOUNT TO REFUND', 'OLDVPSTxId', 'OLDvendorTxCode', 'OLDSecurityKey', 'OLDTxAuthNo', 'Refund Message');

// Do whatever with $output
```

**3D Secure**

```
// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
$sagepay->setConnectionMode('test');

// Send the output back to Sagepay
$output = $sagepay->threeDResponse($_POST['MD'], $_POST['PaRes']);
```

To Do
-----

[](#to-do)

- Paypal Integration

Getting Involved
----------------

[](#getting-involved)

- Open an issue with a feature you'd like
- Make a PR
- Write any tests that may be missing!

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 73.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~94 days

Recently: every ~226 days

Total

14

Last Release

2989d ago

Major Versions

0.0.1 → 1.0.02014-11-06

PHP version history (2 changes)0.0.1PHP &gt;=5.3.0

1.6.1PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c4f608be1318c7ca580fff7a037a860abe60a9886a8d12c44be2013c9e20901?d=identicon)[darylldoyle](/maintainers/darylldoyle)

---

Top Contributors

[![darylldoyle](https://avatars.githubusercontent.com/u/968731?v=4)](https://github.com/darylldoyle "darylldoyle (11 commits)")[![amirulahmad](https://avatars.githubusercontent.com/u/78335?v=4)](https://github.com/amirulahmad "amirulahmad (2 commits)")[![markgrice](https://avatars.githubusercontent.com/u/7687774?v=4)](https://github.com/markgrice "markgrice (1 commits)")[![uptoeleven](https://avatars.githubusercontent.com/u/4528042?v=4)](https://github.com/uptoeleven "uptoeleven (1 commits)")

---

Tags

paymentgatewaypaymerchantpurchasesagepaysage pay

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dwmsw-sagepay/health.svg)

```
[![Health](https://phpackages.com/badges/dwmsw-sagepay/health.svg)](https://phpackages.com/packages/dwmsw-sagepay)
```

###  Alternatives

[omnipay/sagepay

Sage Pay driver for the Omnipay PHP payment processing library

561.2M7](/packages/omnipay-sagepay)[lokielse/omnipay-alipay

Alipay gateway for Omnipay payment processing library

587421.0k11](/packages/lokielse-omnipay-alipay)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
