PHPackages                             alphagov/pay-integration-php - 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. alphagov/pay-integration-php

AbandonedArchivedLibrary[Payment Processing](/categories/payments)

alphagov/pay-integration-php
============================

PHP client for GOV.UK Pay

v1.0.0(9y ago)16.2k5MITPHPPHP &gt;=5.4

Since Dec 4Pushed 4y ago25 watchersCompare

[ Source](https://github.com/alphagov/pay-integration-php)[ Packagist](https://packagist.org/packages/alphagov/pay-integration-php)[ RSS](/packages/alphagov-pay-integration-php/feed)WikiDiscussions master Synced today

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

GOV.UK Pay - pay-integration-php
================================

[](#govuk-pay---pay-integration-php)

PHP client for the GOV.UK Pay API

> As of September 2021, this repository is no longer actively maintained by the GOV.UK Pay team.

#### PSR-7 HTTP

[](#psr-7-http)

The Pay PHP Client is based on a PSR-7 HTTP model. You therefore need to pick your preferred HTTP Client library to use.

We will show examples here using the Guzzle v6 Adapter.

Installing
----------

[](#installing)

The Pay PHP Client can be installed with [Composer](https://getcomposer.org/). Run this command:

```
composer require php-http/guzzle6-adapter alphagov/pay-integration-php
```

Usage
-----

[](#usage)

Assuming you've installed the package via Composer, the Pay PHP Client will be available via the autoloader.

Create a (Guzzle v6 based) instance of the Client using:

```
$client = new \Alphagov\Pay\Client([
    'apiKey'        => '{your api key}',
    'httpClient'    => new \Http\Adapter\Guzzle6\Client
]);
```

You are then able to access the Pay API using `$client`.

If you need to access an environment other than production, you can pass the base URL in via the `baseUrl` key in the constructor:

```
'baseUrl' => '{api base url}'
```

#### Create a Payment

[](#create-a-payment)

The method signature is:

```
createPayment( $amount, $reference, $description, UriInterface $returnUrl )
```

Where

- **$amount** A required *int* holding the payment amount, in pence, in British Pounds (GBP).
- **$reference** A required *string* holding an application side payment reference.
- **$description** A required *string* a description of the payment.
- **$returnUrl** A required *Psr\\Http\\Message\\UriInterface* with the URL the user will be directed back to.

An example request would look like:

```
try {

    $response = $client->createPayment(
        10 * 100, // £10
        'id-123',
        'Payment for x, y and z.',
        new \GuzzleHttp\Psr7\Uri('https://www.example.service.gov.uk/pay/response')
    );

} catch (PayException $e){}
```

**$response** will be an instance of `Alphagov\Pay\Response\Payment`, which is [documented here](#payment).

An instance (or sub-class) of `Alphagov\Pay\Exception\PayException` will be thrown if a Pay error occurs.

#### Lookup a Payment

[](#lookup-a-payment)

The method signature is:

```
getPayment( $payment )
```

Where

- **$payment** is a required *string* holding the (Pay generated) payment id.

An example request would look like:

```
try {

    $response = $client->getPayment( 'hu20sqlact5260q2nanm0q8u93' );

} catch (PayException $e){}
```

**$response** will be an instance of `Alphagov\Pay\Response\Payment`, which is [documented here](#payment); **or** `null` if the payment was not found.

An instance (or sub-class) of `Alphagov\Pay\Exception\PayException` will be thrown if a Pay error occurs.

#### Cancel a Payment

[](#cancel-a-payment)

The method signature is:

```
cancelPayment( $payment )
```

- **$payment** is a required *string* holding the (Pay generated) payment id.

An example request would look like:

```
try {

    $response = $client->cancelPayment( 'hu20sqlact5260q2nanm0q8u93' );

} catch (PayException $e){}
```

**$response** will be bool `true` if the payment was cancelled. Otherwise an instance (or sub-class) of `Alphagov\Pay\Exception\PayException` will be thrown if a Pay error occurs.

#### Refund a Payment

[](#refund-a-payment)

The method signature is:

```
refundPayment( $payment, $amount, $refundAmountAvailable = null )
```

- **$payment** is a required *string* holding the (Pay generated) payment id.
- **$amount** A required *int* holding the amount to be refunded, in pence, in British Pounds (GBP).
- **$refundAmountAvailable** An optional *int* holding the expected amount available for refund, in pence, in British Pounds (GBP).

An example request would look like:

```
try {

    $response = $client->refundPayment(
    	'hu20sqlact5260q2nanm0q8u93',
        10 * 100, // £10
        50 * 100  // £50
    );

} catch (PayException $e){}
```

**$response** will be an instance of `Alphagov\Pay\Response\Refund`, which is [documented here](#refund).

An instance (or sub-class) of `Alphagov\Pay\Exception\PayException` will be thrown if a Pay error occurs.

#### Lookup all Refunds for a Payment

[](#lookup-all-refunds-for-a-payment)

The method signature is:

```
getPaymentRefunds( $payment )
```

Where

- **$payment** is a required *string* holding the (Pay generated) payment id.

An example request would look like:

```
try {

    $response = $client->getPaymentRefunds( 'hu20sqlact5260q2nanm0q8u93' );

} catch (PayException $e){}
```

**$response** will be an instance of `Alphagov\Pay\Response\Refunds`, which will contain an instance of `Alphagov\Pay\Response\Refund` ([docs](#refund)) for each refund processed.

An instance (or sub-class) of `Alphagov\Pay\Exception\PayException` will be thrown if a Pay error occurs.

#### Lookup a single Refund for a Payment

[](#lookup-a-single-refund-for-a-payment)

The method signature is:

```
getPaymentRefund( $payment, $refund )
```

Where

- **$payment** is a required *string* holding the (Pay generated) payment id.
- **$refund** is a required *string* holding the (Pay generated) refund id.

An example request would look like:

```
try {

    $response = $client->getPaymentRefunds(
      'hu20sqlact5260q2nanm0q8u93',
      'j2cg5v7et0424d7shtrt7r0mj'
    );

} catch (PayException $e){}
```

**$response** will be an instance of `Alphagov\Pay\Response\Refund` ([docs](#refund)), or NULL if the refund is not found.

An instance (or sub-class) of `Alphagov\Pay\Exception\PayException` will be thrown if a Pay error occurs.

#### Lookup all Events for a Payment

[](#lookup-all-events-for-a-payment)

The method signature is:

```
getPaymentEvents( $payment )
```

Where

- **$payment** is a required *string* holding the (Pay generated) payment id.

An example request would look like:

```
try {

    $response = $client->getPaymentEvents( 'hu20sqlact5260q2nanm0q8u93' );

} catch (PayException $e){}
```

**$response** will be an instance of `Alphagov\Pay\Response\Events`, which will contain an instance of `Alphagov\Pay\Response\Event` ([docs](#event)) for each event.

An instance (or sub-class) of `Alphagov\Pay\Exception\PayException` will be thrown if a Pay error occurs.

#### Search Payments

[](#search-payments)

The method signature is:

```
searchPayments( array $filters = array() )
```

Where

- **$filters** An optional *array* which applies filters to the request. Zero or more filters can be used. Supported filtered:
    - `reference` *string*
    - `state` *string*
    - `page` *string*
    - `display_size` *string*
    - `from_date` *DateTime*
    - `to_date` *DateTime*

Full filter details can be found here:

An example request would look like:

```
try {

    $response = $client->searchPayments([
    	'from_date' => new \DateTime('2015-08-14T12:35:00Z'),
        'page' => '2',
        'display_size' => '50'
    ]);

} catch (NotifyException $e){}
```

**$response** will be an instance of `Alphagov\Pay\Response\Payments`, which will contain an instance of `Alphagov\Pay\Response\Payment` ([docs](#payment)) for each payment found.

An instance (or sub-class) of `Alphagov\Pay\Exception\PayException` will be thrown if a Pay error occurs.

Responses
---------

[](#responses)

All Response objects except Event have a `getResponse()` which returns a class implementing `Psr\Http\Message\ResponseInterface`, containing the original API response.

### Payment

[](#payment)

An instance of `Alphagov\Pay\Response\Payment`, which contains the decoded JSON response from the Pay API, representing a single payment.

A full list of returned properties can be found here:

Properties can be accessed directly using the `->` operator. For example:

```
$response->payment_id
$response->created_date
// etc...
```

If available, the payment page URL to direct the user to is accessible via:

```
$response->getPaymentPageUrl();
```

This returns either:

- an instance of `Psr\Http\Message\UriInterface` represening the URL; or
- `null` if the URL is unavailable (for example, if the payment is complete).

`Payment` also includes methods for checking the state of the payment:

The payment is *finished*. i.e. the user can no longer interact with the payment page.

```
$response->isFinished()
```

The payment is *successful*.

```
$response->isSuccess()
```

All other standard Pay states can also be checked via:

```
$response->isCreated()
$response->isStarted()
$response->isSubmitted()
$response->isFailed()
$response->isCancelled()
$response->isError()
```

### Refund

[](#refund)

An instance of `Alphagov\Pay\Response\Refund`, which contains the decoded JSON response from the Pay API, representing a single refund.

A full list of returned properties can be found here:

Properties can be accessed directly using the `->` operator. For example:

```
$response->refund_id
$response->status
$response->amount
// etc...
```

### Event

[](#event)

An instance of `Alphagov\Pay\Response\Event`, which contains the decoded JSON response from the Pay API, representing a single event.

A full list of returned properties can be found here:

Properties can be accessed directly using the `->` operator. For example:

```
$response->state
$response->updated
// etc...
```

### Payments, Refunds &amp; Events

[](#payments-refunds--events)

All three of these responses represent collections of their respective response type. They all extend PHP’s `ArrayObject`, thus can be treated as an array.

Both Refunds &amp; Events also support the addition `$response->payment_id` property, containing the payment ID to which they relate.

License
-------

[](#license)

The Pay PHP Client is released under the MIT license, a copy of which can be found in [LICENSE](LICENSE.txt).

###  Health Score

32

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.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 ~0 days

Total

2

Last Release

3394d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/66f4b8fc2718808076569971dddd8a4ffac98533b684f05d1556126ee2bf963f?d=identicon)[NSmithUK](/maintainers/NSmithUK)

---

Top Contributors

[![nsmithuk](https://avatars.githubusercontent.com/u/480908?v=4)](https://github.com/nsmithuk "nsmithuk (10 commits)")[![katstevens](https://avatars.githubusercontent.com/u/3492540?v=4)](https://github.com/katstevens "katstevens (2 commits)")

---

Tags

govuk-payportfolio

### Embed Badge

![Health badge](/badges/alphagov-pay-integration-php/health.svg)

```
[![Health](https://phpackages.com/badges/alphagov-pay-integration-php/health.svg)](https://phpackages.com/packages/alphagov-pay-integration-php)
```

###  Alternatives

[zaporylie/vipps

PHP SDK for Vipps

27384.3k](/packages/zaporylie-vipps)[superfaktura/apiclient

Api client for SuperFaktura | online invoicing tool

20129.8k](/packages/superfaktura-apiclient)[sevaske/php-zatca-xml

An unofficial PHP library for generating ZATCA Fatoora e-invoices. This library facilitates the creation of compliant e-invoices, QR Codes, and certificates, as well as the submission of e-invoices to ZATCA's servers. It provides developers with an easy-to-use, customizable, and robust toolkit to integrate and automate ZATCA e-invoicing processes in PHP applications.

192.6k1](/packages/sevaske-php-zatca-xml)

PHPackages © 2026

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