PHPackages                             dhavalsagepaypiapi/sagepay-pi-api - 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. dhavalsagepaypiapi/sagepay-pi-api

ActiveLibrary[API Development](/categories/api)

dhavalsagepaypiapi/sagepay-pi-api
=================================

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

00PHP

Since Jan 31Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#laravel-sagepaypi)

SagePayPi

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

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 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.

### 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 (10 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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