PHPackages                             dhavalsagepaypi/sagepay-pi - 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. [API Development](/categories/api)
4. /
5. dhavalsagepaypi/sagepay-pi

ActiveLibrary[API Development](/categories/api)

dhavalsagepaypi/sagepay-pi
==========================

Opayo PI (formerly SagePay PI) PHP API that uses PSR7, PSR17, PSR18 standards.

v1.0.2(2y ago)050MITPHPPHP &gt;=7.2

Since Jan 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/dhavalbhavsar/sagepay-pi)[ Packagist](https://packagist.org/packages/dhavalsagepaypi/sagepay-pi)[ Docs](https://gitlab.com/lumnn/sagepay-pi)[ RSS](/packages/dhavalsagepaypi-sagepay-pi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (13)Versions (4)Used By (0)

Laravel SagePayPi
=================

[](#laravel-sagepaypi)

SagePayPi (Opayo)

Insiperd by [sagepay-pi](https://gitlab.com/lumnn/sagepay-pi)

Update
======

[](#update)

Issue with error resolve with response error.

Opayo PI PHP Client
===================

[](#opayo-pi-php-client)

[![pipeline status](https://camo.githubusercontent.com/324c6a89a74cb27bc95d3aeebad25022de02220563f9e4d6dc6ce2303439c892/68747470733a2f2f6769746c61622e636f6d2f6c756d6e6e2f736167657061792d70692f6261646765732f6d61737465722f706970656c696e652e737667)](https://gitlab.com/lumnn/sagepay-pi/-/commits/master)[![coverage report](https://camo.githubusercontent.com/04433f1abab12e2a86caf9ba0ced79c8cb2b684df57178d46db644d489d0ee25/68747470733a2f2f6769746c61622e636f6d2f6c756d6e6e2f736167657061792d70692f6261646765732f6d61737465722f636f7665726167652e737667)](https://gitlab.com/lumnn/sagepay-pi/-/commits/master)[![Licence MIT](https://camo.githubusercontent.com/5131df51bacc9fc8a134a439cb1919a81bc8d886ad715d7122e14aa56c3db0c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c756d6e6e2f736167657061792d7069)](https://camo.githubusercontent.com/5131df51bacc9fc8a134a439cb1919a81bc8d886ad715d7122e14aa56c3db0c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c756d6e6e2f736167657061792d7069)[![PHPStan - Level 9](https://camo.githubusercontent.com/83dd3d35cebed0eab9ee97ff1a5849c1344cda6a8ee9cac2cda20f5aa55b67bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/83dd3d35cebed0eab9ee97ff1a5849c1344cda6a8ee9cac2cda20f5aa55b67bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e7376673f7374796c653d666c6174)

> PHP client for Opayo PI (formerly Sagepay PI) payment API.

Installation
------------

[](#installation)

`composer require dhavalsagepaypi/sagepay-pi`

You'll also need packages providing:

- `psr/http-message-implementation` (PSR7)
- `psr/http-factory-implementation` (PSR17)
- `psr/http-client-implementation` (PSR18)

Before Using
------------

[](#before-using)

Generally I'd recommend looking into `tests/` directory and [Opayo PI API Reference](https://developer-eu.elavon.com/docs/opayo/spec/api-reference-0).

This library aims to be as close as it's possible to API docs in terms of implementation.

Every interface used by this library has default implementation in same namespace.

Methods Reference
-----------------

[](#methods-reference)

API endpoints and their library methods:

### Obtain Merchant Session Key

[](#obtain-merchant-session-key)

**`POST /merchant-session-keys/`**
`Lumnn\SagePayPi\SagePayPi::getMerchantSessionKey(): string`

Will return previously created key if it's not expired or used. Not neccessarily needed for anything as library handles the generation and authentication

### Validate MSK

[](#validate-msk)

**`GET /merchant-session-keys/{merchantSessionKey}`**
`Lumnn\SagePayPi\SagePayPi::validateMerchantSessionKey(string $merchantSessionKey): bool`

Will return bool whether key is valid

### Create Card Identifier

[](#create-card-identifier)

**`POST /card-identifiers`**
`Lumnn\SagePayPi\Card\Cards::createIdentifier(CardDetailsInterface $card): CardIdentifierInterface`

### Link Reusable Security Code

[](#link-reusable-security-code)

**`POST /card-identifiers/{cardIdentifier}/security-code`**
`Lumnn\SagePayPi\Card\Cards::linkReusableSecurityCode(CardIdentifierInterface $cardIdentifier, string $securityCode): void`

### Create Transaction (Payment/Refund/Repeat)

[](#create-transaction-paymentrefundrepeat)

**`POST /transactions`**
`Lumnn\SagePayPi\Transacton\Transactions::create(TransactionRequestInterface $transaction, array $options = []): AbstractResponse`

*Depending on `$transaction` class this will either create payment, refund or repeat transaction*

- **`@param $transaction`** - can be either of following:

    - `Lumnn\SagePayPi\Transaction\PaymentRequestInterface`
    - `Lumnn\SagePayPi\Transaction\RefundRequestInterface`
    - `Lumnn\SagePayPi\Transaction\RepeatRequestInterface`
- **`@param $options['save_card']`** - *optional, `bool`, default: `false`*
    whether save card for future usages. Only when creating payments, not for refund or repeat transactions
- **`@return AbstractResponse`** - All possible respones are in `Lumnn\SagePayPi\Transaction\Resopnse` namespace and are created by `Lumnn\SagePayPi\Transaction\Response\ResponseFactory`

### Retrieve Transaction

[](#retrieve-transaction)

**`GET /transactions/{transactionId}`**
`Lumnn\SagePayPi\Transacton\Transactions::get(string $transactionId): AbstractResponse`

### Create 3D Secure Object (3DSv1)

[](#create-3d-secure-object-3dsv1)

**`POST /transactions/{transactionId}/3d-secure`**
`Lumnn\SagePayPi\Transacton\Transactions::create3DSv1(string $transactionId, string $paRes): string`

Returns status string

### Create 3D Secure Challenge (3DSv2)

[](#create-3d-secure-challenge-3dsv2)

**`POST /transactions/{transactionId}/3d-secure-challenge`**
`Lumnn\SagePayPi\Transacton\Transactions::create3DSChallenge(string $transactionId, string $cRes): PaymentResponse`

Returns PaymentResponse

### Create an Instruction

[](#create-an-instruction)

**`POST /transactions/{transactionId}/instructions`**
*not implemented*

Examples
--------

[](#examples)

### Constructing client and using resources

[](#constructing-client-and-using-resources)

The `SagePayPi` class is a basic client that is able to perform authenticated requests to API.

It's also in charge of merchant session key and authenticating requests.

Generally, unless you want to speak directly with API it's only required for instantiating other resource classes.

```
use Lumnn\SagePayPi\SagePayPi;

$sagepay = new SagePayPi(
    'vendor',
    'integration_key',
    'integration_password',
    SagePayPi::TEST_ENDPOINT // or SagePayPi::LIVE_ENDPOINT, or ommit for live one
);
```

After getting a client you can instantiate resource classes

```
use Lumnn\SagePayPi\Card\Cards;
use Lumnn\SagePayPi\Transaction\Transactions;

$cards = new Cards($sagepay);
$transactions = new Transactions($sagepay);
```

### Creating Card Identifier

[](#creating-card-identifier)

This example creates a credit card representation and POST-s that to Opayo for retrieving the card identifier.

This step can (should?) be done in customer browser to avoid deling with credit card details directly. Documentation:

```
use Lumnn\SagePayPi\Card\CardDetails;
use Lumnn\SagePayPi\Card\Cards;

$cards = new Cards($sagepay);
$card = new CardDetails();
$card
    ->setCardNumber("1234123412341234")
    ->setCardholderName('Test Name')
    ->setExpiryDate('1223') // December 2023
    ->setSecurityCode('123');

$cardIdentifier = $cards->createIdentifier($card);
```

### Processing Telephone Payment (without 3D Secure)

[](#processing-telephone-payment-without-3d-secure)

```
use Lumnn\SagePayPi\Transaction\PaymentRequest;
use Lumnn\SagePayPi\Transaction\Transactions;

// $sagepay - from previous example
// $cardIdentifier - from previous examples
// $address - just intantiated and populated Address class. It's a simple getter setter class

$transactions = new Transactions($sagepay);

$paymentRequest = new PaymentRequest();
$paymentRequest
    ->setAmount(1000)
    ->setCurrency('GBP')
    ->setDescription('One testing service of SagePay Pi PHP Library')
    ->setBillingDetails($address)
    ->setCardIdentifier($cardIdentifier)
    ->setCustomerEmail('test@example.org')
    ->setEntryMethod(PaymentRequestInterface::ENTRY_TELEPHONE_ORDER)
    ->setTransactionType(PaymentRequestInterface::TYPE_PAYMENT)
    ->setVendorTxCode('php_lib_test'.time());

$payment = $this->transactions->createPayment($paymentRequest);
```

### 3D Secure Payment

[](#3d-secure-payment)

```
use Lumnn\SagePayPi\Transaction\PaymentRequest;
use Lumnn\SagePayPi\Transaction\Transactions;
use Lumnn\SagePayPi\Transaction\Request\StrongCustomerAuthentication;
use Lumnn\SagePayPi\Transaction\Request\StrongCustomerAuthenticationInterface;
use Lumnn\SagePayPi\Transaction\Response\ThreeDSv2AuthResponse;

// $sagepay - from previous example
// $cardIdentifier - from previous examples
// $address - just intantiated and populated Address class. It's a simple getter setter class

$transactions = new Transactions($sagepay);

$paymentRequest = new PaymentRequest();
$paymentRequest
    ->setAmount(1000)
    ->setCurrency('GBP')
    ->setDescription('One testing service of SagePay Pi PHP Library')
    ->setBillingDetails($address)
    ->setCardIdentifier($cardIdentifier)
    ->setCustomerEmail('test@example.org')
    ->setEntryMethod(PaymentRequestInterface::ENTRY_ECOMMERCE)
    ->setApply3DSecure(PaymentRequestInterface::SECURITY_CHECK_FORCE)
    ->setVendorTxCode('php_lib_test_3dv2'.time());

$strongCustomerAuth = new StrongCustomerAuthentication();

$notificationURL = 'http://127.0.0.1:8080';

$strongCustomerAuth
    ->setNotificationURL($notificationURL)
    ->setBrowserIP('127.0.0.1')
    ->setBrowserAcceptHeader('*/*')
    ->setBrowserJavascriptEnabled(true)
    ->setBrowserJavaEnabled(false)
    ->setBrowserLanguage('en-US')
    ->setBrowserColorDepth('32')
    ->setBrowserScreenHeight('1080')
    ->setBrowserScreenWidth('1920')
    ->setBrowserTZ('0')
    ->setBrowserUserAgent('Mozilla/5.0 (Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0')
    ->setChallengeWindowSize('Small')
    ->setTransType(StrongCustomerAuthenticationInterface::TRANSACTION_TYPE_GOODS_AND_SERVICE_PURCHASE);

$paymentRequest->setStrongCustomerAuthentication($strongCustomerAuth);

$threeDSv2AuthResponse = $this->transactions->createPayment($paymentRequest);

// for simplicity in this example. However it's not guaranteed it's going to be 3Ds v2 challenge
if (!$payment instanceof ThreeDSv2AuthResponse) {
    throw new \Exception("Response invalid in this example");
}

$acsUrl = $threeDSv2AuthResponse->getAcsUrl();
$acsParams = [
    'creq' => $threeDSv2AuthResponse->getCReq(),
];

// at this point you should redirect customer to acsUrl with creq param
// it will then come back with cRes value. The cRes value will be POST-ed to
// your $notificationURL

$cRes = $_POST['cRes'];

$completedPayment = $transactions->create3DSChallenge($threeDSv2AuthResponse->getId(), $cRes);
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~400 days

Total

3

Last Release

764d ago

PHP version history (2 changes)v1.0.1PHP &gt;=7.4

v1.0.2PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5fbc9a969ac2e7790e24d884498a871155ca94ba99cfc9e9f2a3c26a3af6a9a?d=identicon)[hdbhavsar91](/maintainers/hdbhavsar91)

---

Top Contributors

[![dhavalbhavsar](https://avatars.githubusercontent.com/u/22841292?v=4)](https://github.com/dhavalbhavsar "dhavalbhavsar (11 commits)")

---

Tags

apipaymentsagepayopayoopayo pisagepay pi

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k22.6M232](/packages/openai-php-client)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

963.1M35](/packages/getbrevo-brevo-php)[deeplcom/deepl-php

Official DeepL API Client Library

2616.2M66](/packages/deeplcom-deepl-php)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35636.1k2](/packages/telnyx-telnyx-php)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)

PHPackages © 2026

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