PHPackages                             jakuborava/ehub-client - 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. jakuborava/ehub-client

ActiveLibrary[API Development](/categories/api)

jakuborava/ehub-client
======================

Publisher API client for EHUB affiliate network

3.1.2(3mo ago)062MITPHPPHP ^8.4CI passing

Since Jan 19Pushed 3mo agoCompare

[ Source](https://github.com/jakuborava/ehub-client)[ Packagist](https://packagist.org/packages/jakuborava/ehub-client)[ Docs](https://github.com/jakuborava/ehub-client)[ GitHub Sponsors]()[ RSS](/packages/jakuborava-ehub-client/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (12)Versions (5)Used By (0)

eHub Laravel Client
===================

[](#ehub-laravel-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4015dde36045e7905e29d2e3381336513ddcf74dc7de65b64360a43997fbb213/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a616b75626f726176612f656875622d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jakuborava/ehub-client)[![GitHub Tests Action Status](https://camo.githubusercontent.com/d87942b17bf94aaffa2bccc07ecdd0b9792cd4bdeafd9d81e705d1cfcbc8ca69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a616b75626f726176612f656875622d636c69656e742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jakuborava/ehub-client/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/54f35f4732ead36a678344b4156567ef225b15e3384df20868672fdf5626b308/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a616b75626f726176612f656875622d636c69656e742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jakuborava/ehub-client/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c51fa90c51ab8b1dc020c9240f9ef3f7ed41109fe5f0727ff95086efdc37189c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a616b75626f726176612f656875622d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jakuborava/ehub-client)

A comprehensive Laravel package for interacting with the eHub Affiliate Network API. This package provides a fluent, type-safe interface for all Publisher endpoints with full DTO support, request objects, and comprehensive error handling.

Features
--------

[](#features)

- ✅ Full support for all Publisher endpoints
- ✅ Type-safe DTOs for all responses
- ✅ Fluent Request objects for building queries
- ✅ Pagination support with metadata
- ✅ Comprehensive exception hierarchy
- ✅ PHP 8.4+ with strict typing
- ✅ PHPStan Level MAX compliant
- ✅ Laravel HTTP Client integration
- ✅ Easy userId switching per request

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

[](#installation)

You can install the package via composer:

```
composer require jakuborava/ehub-client
```

Configuration
-------------

[](#configuration)

You can configure the API key in two ways:

### 1. Environment Variable (Recommended)

[](#1-environment-variable-recommended)

Add your eHub API key to your `.env` file:

```
EHUB_API_KEY=your-api-key-here
```

Then use the client without any parameters:

```
use JakubOrava\EhubClient\EhubClient;

$client = new EhubClient();
```

### 2. Programmatically

[](#2-programmatically)

Pass the API key directly to the client constructor:

```
use JakubOrava\EhubClient\EhubClient;

$client = new EhubClient('your-api-key-here');
```

This is useful when you need to:

- Use different API keys for different requests
- Load the API key from a custom source
- Switch between multiple API keys dynamically

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

The client uses a fluent, hierarchical API design. All methods require a `userId` (publisher ID) to be passed per request, allowing you to easily switch between different publisher accounts.

```
use JakubOrava\EhubClient\EhubClient;

// Initialize with API key from config/env
$client = new EhubClient();

// Or initialize with API key parameter
$client = new EhubClient('your-api-key-here');

$publisherId = 'your-publisher-id';

// Get vouchers
$vouchers = $client->publishers()
    ->vouchers()
    ->list($publisherId);

// Access the results
foreach ($vouchers->items as $voucher) {
    echo $voucher->code;
    echo $voucher->campaignName;
    echo $voucher->url;
}

// Pagination info
echo $vouchers->totalItems;      // Total number of items
echo $vouchers->currentPage;     // Current page number
echo $vouchers->perPage;         // Items per page
echo $vouchers->getTotalPages(); // Total pages
echo $vouchers->hasMorePages();  // Check if more pages exist
```

### Using Request Objects

[](#using-request-objects)

Request objects provide a fluent interface for building queries with pagination, filtering, and sorting:

```
use JakubOrava\EhubClient\Requests\VouchersListRequest;

$request = (new VouchersListRequest())
    ->page(2)
    ->perPage(100)
    ->type('voucher')
    ->isValid(true)
    ->sort('-validFrom')
    ->fields(['id', 'code', 'campaignName', 'url']);

$vouchers = $client->publishers()
    ->vouchers()
    ->list($publisherId, $request);
```

### Switching Between Users

[](#switching-between-users)

Since `userId` is passed per request, you can easily switch between different publisher accounts:

```
$publisher1Vouchers = $client->publishers()
    ->vouchers()
    ->list('publisher-1-id');

$publisher2Vouchers = $client->publishers()
    ->vouchers()
    ->list('publisher-2-id');
```

Available Endpoints
-------------------

[](#available-endpoints)

### Campaigns

[](#campaigns)

List all campaigns accessible to the publisher:

```
use JakubOrava\EhubClient\Requests\CampaignsListRequest;

$request = (new CampaignsListRequest())
    ->page(1)
    ->perPage(50)
    ->name('Campaign Name')
    ->categories([4, 6]) // Finance and E-shops
    ->status('approved')
    ->sort('name');

$campaigns = $client->publishers()
    ->campaigns()
    ->list($publisherId, $request);

foreach ($campaigns->items as $campaign) {
    echo $campaign->id;
    echo $campaign->name;
    echo $campaign->web;
    echo $campaign->cookieLifetime;

    // Access nested collections
    foreach ($campaign->categories as $category) {
        echo $category->name;
    }

    foreach ($campaign->commissionGroups as $group) {
        echo $group->name;
        foreach ($group->commissions as $commission) {
            echo $commission->value . $commission->valueType;
        }
    }
}
```

### Creatives

[](#creatives)

List all creatives (banners, links, etc.) for the publisher:

```
use JakubOrava\EhubClient\Requests\CreativesListRequest;

$request = (new CreativesListRequest())
    ->campaignId('campaign-id')
    ->type('link')
    ->name('Default link')
    ->sort('-id');

$creatives = $client->publishers()
    ->creatives()
    ->list($publisherId, $request);

foreach ($creatives->items as $creative) {
    echo $creative->id;
    echo $creative->campaignId;
    echo $creative->type;
    echo $creative->destinationUrl;
}
```

### Outbound Clicks

[](#outbound-clicks)

Track outbound clicks from your affiliate links:

```
use JakubOrava\EhubClient\Requests\OutboundClicksListRequest;

$request = (new OutboundClicksListRequest())
    ->from('2024-01-01T00:00:00')
    ->to('2024-01-31T23:59:59')
    ->campaignId('campaign-id')
    ->processed(true)
    ->sort('-dateTime');

$clicks = $client->publishers()
    ->outboundClicks()
    ->list($publisherId, $request);

foreach ($clicks->items as $click) {
    echo $click->id;
    echo $click->campaignId;
    echo $click->clickDateTime;
    echo $click->commission;
}
```

### Transactions

[](#transactions)

List and retrieve transaction details:

```
use JakubOrava\EhubClient\Requests\TransactionsListRequest;

// List transactions
$request = (new TransactionsListRequest())
    ->dateInsertedFrom('2024-01-01T00:00:00')
    ->dateInsertedTo('2024-01-31T23:59:59')
    ->campaignId('campaign-id')
    ->status('approved')
    ->payoutStatus('paid')
    ->sort('-dateInserted');

$transactions = $client->publishers()
    ->transactions()
    ->list($publisherId, $request);

foreach ($transactions->items as $transaction) {
    echo $transaction->id;
    echo $transaction->uuid;
    echo $transaction->commission;
    echo $transaction->amount;
    echo $transaction->status;
}

// Get single transaction detail
$transaction = $client->publishers()
    ->transactions()
    ->get($publisherId, 'transaction-id');

echo $transaction->orderId;
echo $transaction->productId;
```

### Vouchers

[](#vouchers)

List vouchers and promotional codes:

```
use JakubOrava\EhubClient\Requests\VouchersListRequest;

$request = (new VouchersListRequest())
    ->type('voucher') // or 'action'
    ->isValid(true)
    ->sort('-validFrom');

$vouchers = $client->publishers()
    ->vouchers()
    ->list($publisherId, $request);

foreach ($vouchers->items as $voucher) {
    echo $voucher->code;
    echo $voucher->campaignName;
    echo $voucher->rules;
    echo $voucher->url; // Affiliate tracking URL
    echo $voucher->destinationUrl;
    echo $voucher->validFrom;
    echo $voucher->validTill;
}
```

Error Handling
--------------

[](#error-handling)

The package throws specific exceptions for different error scenarios:

```
use JakubOrava\EhubClient\Exceptions\AuthenticationException;
use JakubOrava\EhubClient\Exceptions\ValidationException;
use JakubOrava\EhubClient\Exceptions\ApiErrorException;
use JakubOrava\EhubClient\Exceptions\UnexpectedResponseException;

try {
    $vouchers = $client->publishers()
        ->vouchers()
        ->list($publisherId);
} catch (AuthenticationException $e) {
    // Invalid API key
} catch (ValidationException $e) {
    // Invalid request parameters
} catch (ApiErrorException $e) {
    // API returned an error (4xx or 5xx)
    echo $e->getCode(); // HTTP status code
} catch (UnexpectedResponseException $e) {
    // Unexpected response format
}
```

Architecture
------------

[](#architecture)

### DTOs (Data Transfer Objects)

[](#dtos-data-transfer-objects)

All responses are mapped to strictly typed DTOs with `public readonly` properties:

```
$campaign = $campaigns->items->first();

// All properties are typed and readonly
$campaign->id;              // string
$campaign->name;            // string
$campaign->cookieLifetime;  // int|null
$campaign->categories;      // Collection
```

### Request Objects

[](#request-objects)

Request objects use a fluent interface and extend `BaseRequest`:

```
class VouchersListRequest extends BaseRequest
{
    public function type(string $type): self;
    public function isValid(bool $isValid): self;
}
```

All request objects support:

- `page(int $page)` - Set page number
- `perPage(int $perPage)` - Set items per page
- `sort(string $sort)` - Set sort field (prefix with `-` for descending)
- `fields(array $fields)` - Specify which fields to return

### Future: Advertiser Endpoints

[](#future-advertiser-endpoints)

The package architecture is designed to support Advertiser endpoints in the future without breaking changes. The folder structure is prepared:

```
src/Endpoints/
├── PublisherEndpoints/
└── AdvertiserEndpoints/ (future)

```

Credits
-------

[](#credits)

- [Jakub Orava](https://github.com/jakuborava)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance78

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

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 ~14 days

Total

4

Last Release

114d ago

### Community

Maintainers

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

---

Top Contributors

[![jakuborava](https://avatars.githubusercontent.com/u/9501966?v=4)](https://github.com/jakuborava "jakuborava (16 commits)")

---

Tags

laravelJakub Oravaehub-client

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jakuborava-ehub-client/health.svg)

```
[![Health](https://phpackages.com/badges/jakuborava-ehub-client/health.svg)](https://phpackages.com/packages/jakuborava-ehub-client)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k9.9M90](/packages/dedoc-scramble)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M42](/packages/spatie-laravel-pdf)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[simplestats-io/laravel-client

Analytics for Laravel. Track visitors, registrations, and payments. Discover which channels actually drive revenue, not just traffic. Server-side, GDPR compliant, ad-blocker proof.

5019.3k](/packages/simplestats-io-laravel-client)[spatie/laravel-github-webhooks

Handle GitHub webhooks in a Laravel application

93157.3k5](/packages/spatie-laravel-github-webhooks)

PHPackages © 2026

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