PHPackages                             covergenius/xcover-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. [API Development](/categories/api)
4. /
5. covergenius/xcover-php

ActiveLibrary[API Development](/categories/api)

covergenius/xcover-php
======================

XCover API SDK for PHP

v2.1.0(2y ago)741.5k↓14.3%1MITPHPPHP ^7.4.0||^8.0CI passing

Since Jan 3Pushed 2y ago6 watchersCompare

[ Source](https://github.com/CoverGenius/xcover-php)[ Packagist](https://packagist.org/packages/covergenius/xcover-php)[ Docs](https://www.covergenius.com/xcover/)[ RSS](/packages/covergenius-xcover-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (7)Versions (11)Used By (0)

 [![](xcover-logo.svg)](xcover-logo.svg)

 [![](https://github.com/CoverGenius/xcover-php/workflows/CI/badge.svg)](https://github.com/CoverGenius/xcover-php/workflows/CI/badge.svg) [![](https://github.com/CoverGenius/xcover-php/workflows/Lint/badge.svg)](https://github.com/CoverGenius/xcover-php/workflows/Lint/badge.svg) [![](https://github.com/CoverGenius/xcover-php/workflows/Composer/badge.svg)](https://github.com/CoverGenius/xcover-php/workflows/Composer/badge.svg) [![](https://github.com/CoverGenius/xcover-php/workflows/Semgrep/badge.svg)](https://github.com/CoverGenius/xcover-php/workflows/Semgrep/badge.svg) [![](https://github.com/CoverGenius/xcover-php/workflows/Static%20Analysis/badge.svg)](https://github.com/CoverGenius/xcover-php/workflows/Static%20Analysis/badge.svg)

 [![Latest Stable Version](https://camo.githubusercontent.com/cbf55f95be8c5fe5c3fa8d618250af1a1f66b65698190361b6ee5ec52cf40533/687474703a2f2f706f7365722e707567782e6f72672f436f76657247656e6975732f78636f7665722d7068702f763f7374796c653d706c6173746963)](https://packagist.org/packages/CoverGenius/xcover-php) [![PHP Version Require](https://camo.githubusercontent.com/b1434656066002adaaaa96358f2294b5da597150cbc2ddfa674e564dbc30f2fe/687474703a2f2f706f7365722e707567782e6f72672f436f76657247656e6975732f78636f7665722d7068702f726571756972652f7068703f7374796c653d706c6173746963)](https://packagist.org/packages/CoverGenius/xcover-php) [![License](https://camo.githubusercontent.com/669bb95ea25baf11903e1d230cf2a69974b811d46ac20d90091395bd543543b3/687474703a2f2f706f7365722e707567782e6f72672f436f76657247656e6975732f78636f7665722d7068702f6c6963656e73653f7374796c653d706c6173746963)](https://packagist.org/packages/CoverGenius/xcover-php)

XCover SDK for PHP
==================

[](#xcover-sdk-for-php)

XCover SDK simplifies [XCover API](https://www.covergenius.com/api/docs/xcover/) integration in PHP applications.
The library is based on Guzzle 7 HTTP client and offers the following features:

- AuthMiddleware performs authentication
- JsonResponseMiddleware provides convenient `json` method on the Guzzle responses
- HTTP abstraction in XCover class
- Automatic response status code validation and custom exception classes

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

[](#installation)

XCover SDK is available on [Packagist](https://packagist.org/packages/covergenius/xcover-php) and the recommended way of installing it is via [Composer](https://getcomposer.org/).

V1 releases are for PHP 7.2 or higher (but less than 8)

V2 releases are for PHP 7.4 as well as 8.0 and higher

```
composer require covergenius/xcover-php
```

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

```
use XCoverClient\Config;
use XCoverClient\XCover;

// Instantiate client
$client = new XCover(new Config([
  'baseUrl' => env('BASE_URL'),
  'apiPrefix' => env('API_PREFIX'),
  'apiKey' => env('API_KEY'),
  'apiSecret' => env('API_SECRET'),
  'partner' => env('PARTNER_CODE'),
]));

// Quote request
$quoteResponse = $client->createQuote(
    [
        'request' => [
            [
                'policy_type' => 'event_ticket_protection',
                'policy_type_version' => 1,
                'policy_start_date' => '2019-12-01T17:59:00.831+00:00',
                'event_datetime' => '2019-12-25T21:00:00+00:00',
                'event_name' => 'Ariana Grande',
                'event_location' => 'The O2',
                'number_of_tickets' => 2,
                'total_ticket_price' => 100,
                'resale_ticket' => false,
                'event_country' => 'GB'
            ]
        ],
        'currency' => 'GBP',
        'customer_country' => 'GB',
        'customer_region' => 'London',
        'customer_language' => 'en'
    ]
);
$quotePackage = $quoteResponse->json();

// Quote package array will contain all information required to display the insurance offering
echo $quotePackage['id']; // 'JWFFM-M3W3Y-INS'
echo $quotePackage['total_price']; // 5.00
echo $quotePackage['quotes'][0]['price']; // 5.00
echo $quotePackage['quotes'][0]['tax']['total_tax']; // 1.00
echo $quotePackage['quotes'][0]['tax']['total_tax_formatted']; // '£ 1.00'
echo $quotePackage['quotes'][0]['content']['title']; // 'Ticket Protection'
echo $quotePackage['quotes'][0]['content']['description']; // 'Covers the purchase cost of tickets (up to a maximum of £500) if you are unable to attend a booked event as result of an unexpected circumstance.'
echo $quotePackage['quotes'][0]['pds_url']; // 'https://xcover.com/en/pds/JWFFM-M3W3Y-INS?policy_type=event_ticket_protection_v1'

// To report insurance booking
echo $quotePackage['quotes'][0]['id']; // '40e9859d-9a2c-47fb-a0a1-5d121fc68fdd'
$bookingResponse = $client->createBooking($quotePackage['id'],
    [
        'quotes' => [
            [
                 'id' => '40e9859d-9a2c-47fb-a0a1-5d121fc68fdd',
            ]
        ],
        'policyholder' => [
            'first_name' => 'John',
            'last_name' => 'Doe',
            'email' => 'john.doe@gmail.com',
            'age' => 30,
            'country' => 'GB'
        ]
]
);

// Booking has the same id as quote package and a similar structure
$booking = $bookingResponse->json();

echo $booking['id']; // 'JWFFM-M3W3Y-INS'
echo $booking['status']; // 'CONFIRMED'
echo $booking['total_price']; // 5.00
```

Please refer to `tests/XCoverTest.php` file for more examples.

XCover class provides methods for all operations listed in [XCover API Documentation](https://www.covergenius.com/api/docs/xcover/).

### Customising Guzzle client

[](#customising-guzzle-client)

To customise Guzzle configuration you can pass custom client instance in XCover constructor.

Guzzle 6 client instance is immutable so you need to prepare it beforehand and add all mandatory config options, e.g:

```
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use XCoverClient\Config;
use XCoverClient\Middleware\AuthMiddleware;
use XCoverClient\Middleware\JsonResponseMiddleware;
use XCoverClient\XCover;

// Add XCover mandatory middlewares
$handlerStack = HandlerStack::create();
$handlerStack->push(
  new AuthMiddleware([
      'apiKey' => $this->config->apiKey(),
      'apiSecret' => $this->config->apiSecret(),
  ]),
  'auth'
);
$handlerStack->push(new JsonResponseMiddleware, 'json_response');

// You can add your custom middlewares here

// You can add your custom options to the Guzzle's Client constructor below
$client =  new Client([
  'handler' => $handlerStack,
  'headers' => [
      'Content-Type' => 'application/json',
      'X-Api-Key' => $this->config->apiKey(),
  ],
]);

// Now pass it to XCover constructor as second argument
$client = new XCover(new Config([
  'baseUrl' => env('BASE_URL'),
  'apiPrefix' => env('API_PREFIX'),
  'apiKey' => env('API_KEY'),
  'apiSecret' => env('API_SECRET'),
  'partner' => env('PARTNER_CODE'),
]), $client);
```

It is also possible to extend XCover Class and override `createDefaultClient` function.

### TODO

[](#todo)

There are a few features which we will add in the future releases:

- Async calls using Guzzle's promises
- CircuitBreaker middleware
- BYO HTTP Client

Testing
-------

[](#testing)

PHPUnit with PHP-VCR are used to run tests.

Tests are run on every push and pull request to the repository.

Run the below command to run tests

```
composer test
```

Code Style
----------

[](#code-style)

[PHP\_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) is used for coding standard. We currently follow PSR-1 and PSR-2 as a standard.

Lint checks are run on every push and pull request.

Run the below command to check for any code style issues.

```
composer lint
```

You can view the php-cs rules at [phpcs.xml](phpcs.xml)

Static Analysis
---------------

[](#static-analysis)

[PHPStan](https://github.com/phpstan/phpstan) is used for static analysis of code. PHPStan is a PHP Static Analysis Tool. PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code.

Static Analysis is run on every push and pull request

run the command below to check the code with PHPStan

```
composer analyse
```

Changelog
---------

[](#changelog)

You can view the changelog at [CHANGELOG.md](CHANGELOG.md)

Security
--------

[](#security)

You can iew the security policy at [SECURITY.md](SECURITY.md)

Licence
-------

[](#licence)

You can view license information at [LICENSE](LICENSE)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 70.8% 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 ~157 days

Total

10

Last Release

915d ago

Major Versions

v1.x-dev → v2.0.02022-02-16

PHP version history (2 changes)v1.0.0PHP &gt;=7.1.0

v2.0.1PHP ^7.4.0||^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2955754?v=4)[Max](/maintainers/specialtactics)[@specialtactics](https://github.com/specialtactics)

![](https://www.gravatar.com/avatar/842f2fe17a177b8b03cb7c22af005de66aec1783ef4d9e183fa4f4e88e7fa722?d=identicon)[artem\_covergenius](/maintainers/artem_covergenius)

---

Top Contributors

[![sf-cg](https://avatars.githubusercontent.com/u/99694531?v=4)](https://github.com/sf-cg "sf-cg (17 commits)")[![tyomo4ka](https://avatars.githubusercontent.com/u/510194?v=4)](https://github.com/tyomo4ka "tyomo4ka (6 commits)")[![semgrep-bot](https://avatars.githubusercontent.com/u/170460994?v=4)](https://github.com/semgrep-bot "semgrep-bot (1 commits)")

---

Tags

apiinsurancexcover

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/covergenius-xcover-php/health.svg)

```
[![Health](https://phpackages.com/badges/covergenius-xcover-php/health.svg)](https://phpackages.com/packages/covergenius-xcover-php)
```

###  Alternatives

[openai-php/laravel

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

3.7k7.6M74](/packages/openai-php-laravel)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[get-stream/stream-chat

A PHP client for Stream Chat (https://getstream.io/chat/)

301.8M2](/packages/get-stream-stream-chat)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)

PHPackages © 2026

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