PHPackages                             antavo/loyalty-sdk-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. antavo/loyalty-sdk-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

antavo/loyalty-sdk-php
======================

Antavo Loyalty SDK for PHP

1.0.4(6y ago)230.9k↓31%PHPPHP &gt;=5.5

Since Jan 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/antavo/loyalty-sdk-php)[ Packagist](https://packagist.org/packages/antavo/loyalty-sdk-php)[ RSS](/packages/antavo-loyalty-sdk-php/feed)WikiDiscussions master Synced 1mo ago

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

Antavo Loyalty SDK for PHP
==========================

[](#antavo-loyalty-sdk-for-php)

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Usage](#usage)
    - [Including the Library](#including-the-library)
    - [The REST Client](#the-rest-client)
    - [Customer Token](#customer-token)
    - [Validating Webhook Messages](#validating-webhook-messages)

Requirements
------------

[](#requirements)

- PHP 5.5
- PHP cURL extension

Usage
-----

[](#usage)

### Including the Library

[](#including-the-library)

#### Using the Phar package

[](#using-the-phar-package)

```
require 'phar://antavo-loyalty-sdk.phar';

// Now you can use the classes inside the archive.
```

### The REST client

[](#the-rest-client)

The Antavo API REST client is a small client to perform requests to the API.

It uses two other libraries:

- `Antavo\SignedToken` to handle web tokens.
- `Escher` is a library to sign HTTP requests, also to validate them. It generalizes the signature method used by AWS.
- `Pakard\RestClient` is a small, generic REST client.

#### Creating an instance

[](#creating-an-instance)

```
$client = new Antavo\Loyalty\Sdk\RestClient('REGION', 'API KEY', 'API SECRET');
```

Where:

- `REGION` is part of the credential scope (used to sign the request), it is determined by the account;
- `API KEY` identifies the account itself;
- `API SECRET` used to sign the request.

API endpoint base URL is calculated using `REGION` (though it can be changed via the `setBaseUrl()` method).

#### Sending a request

[](#sending-a-request)

The underlying client has a `send()` method with the following signature:

```
public function send(string $method, string $url, mixed $data = NULL): mixed;
```

It makes possible to perform any kind of REST request:

```
$response = $client->send('GET', '/customer/' . $customer->id);
```

`$response` will hold the parsed JSON response.

```
$response = $client->send(
    'POST',
    '/events',
    [
        'customer' => $customer->id,
        'action' => 'profile',
        'data' => [
            'email' => $customer->email,
        ]
    ]
);
```

#### Shorthands

[](#shorthands)

##### Sending an event

[](#sending-an-event)

```
// Assuming $customer is some kind of model object instance.
$client->sendEvent(
    $customer->id,
    'profile',
    [
        'email' => $customer->email,
        'custom_field' => get_custom_value(),
    ]
);
```

#### Error Handling

[](#error-handling)

Note that the API may return a HTTP status code other than 2xx, in which case the client throws an exception.

Because of that it is strongly recommended to wrap all requests in try-catch:

```
try {
    $result = $client->send('GET', '/customer');
} catch (\Pakard\RestClient\StatusCodeException $e) {
    // You can still retrieve the original (error) response:
    $result = $client->getResponse()->getBody();
}
```

There may occur other kind of exceptions, all descendants of `Pakard\RestClient\Exception`:

- `Pakard\RestClient\ResponseParserException` on malformed response body;
- `Pakard\RestClient\TransportException` on any error produced by the PHP cURL extension.

### Customer Token

[](#customer-token)

`Antavo\Loyalty\Sdk\CustomerToken` is used to create &amp; validate web tokens to authenticate the customer in the embedded loyalty hub.

#### Creating an instance

[](#creating-an-instance-1)

```
// Initializing a new token with the secret and with expiration time.
$token = new Antavo\Loyalty\Sdk\CustomerToken('API SECRET', $expires_in);
```

- `API SECRET` used to attach a hash to the token, so later it can be validated.
- `$expires_in` is an integer value: the number of seconds the token considered valid. 0 means no expiration, values smaller than 30 days (in seconds) considered as time-to-live, anything bigger is taken as a Unix timestamp.

Upon instantiation the token sets itself a default cookie domain from the environment, that can be override via `setCookieDomain()`.

#### Creating a new token

[](#creating-a-new-token)

It can be retrieved by setting a customer ID, then simply casting the token object to string:

```
echo (string) (new Antavo\Loyalty\Sdk\CustomerToken('API SECRET', $expires_in))
    ->setCustomer($customer->id);
```

#### Customer token in cookie

[](#customer-token-in-cookie)

Setting a customer token cookie:

```
$token = (new Antavo\Loyalty\Sdk\CustomerToken('API SECRET', $expires_in))
    ->setCustomer($customer->id);

if (!$token->setCookie()) {
    // Couldn't set the cookie...
}
```

Then unsetting it:

```
$token->unsetCookie();
```

#### Retrieving cookie value

[](#retrieving-cookie-value)

```
$token = new Antavo\Loyalty\Sdk\CustomerToken('API SECRET', $expires_in);

try {
    if (isset($_COOKIE[$token->getCookieName()]) {
        $token->setToken($_COOKIE[$token->getCookieName()]);
    }
} catch (Antavo\SignedToken\Exceptions\Exception $e) {
    // The token is either expired or invalid...
}
```

Validating Webhook Messages
---------------------------

[](#validating-webhook-messages)

There are cases when you need to handle webhook messages sent by Antavo. You can also use the REST client to authenticate such requests:

```
// Creating a REST client with valid region and credentials
// (though credentials won't be used for authentication -- see below).
$client = new Antavo\Loyalty\Sdk\RestClient('REGION', 'API KEY', 'API SECRET');

// Obtaining a configured Escher client from the REST client.
$escher = $client->createEscher();

// Authenticating current request using credential key-value pairs.
$escher->authenticate(
    [
        'API KEY' => 'API SECRET'
    ]
);
```

For further details see the [EscherPHP documentation page](https://github.com/emartech/escher-php#validating-a-request).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% 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 ~49 days

Total

4

Last Release

2532d ago

### Community

Maintainers

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

---

Top Contributors

[![antavo-loyalty](https://avatars.githubusercontent.com/u/15105436?v=4)](https://github.com/antavo-loyalty "antavo-loyalty (26 commits)")[![keszi](https://avatars.githubusercontent.com/u/189106769?v=4)](https://github.com/keszi "keszi (1 commits)")[![wokebuster](https://avatars.githubusercontent.com/u/18571344?v=4)](https://github.com/wokebuster "wokebuster (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/antavo-loyalty-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/antavo-loyalty-sdk-php/health.svg)](https://phpackages.com/packages/antavo-loyalty-sdk-php)
```

###  Alternatives

[guava/filament-icon-picker

A filament plugin that adds an icon picker field.

161531.9k25](/packages/guava-filament-icon-picker)[acquia/drupal-recommended-settings

The composer plugin for adding drupal-recommended-settings for Acquia Cloud.

101.1M4](/packages/acquia-drupal-recommended-settings)[gabrola/email-normalizer

A library that will normalize email addresses for cases when different email addresses all point towards a single email account

1979.8k](/packages/gabrola-email-normalizer)[mf/collections-php

Collections for PHP - It's basically a syntax sugar over classic array structure, which allows you to use it as classic array, but adds some cool features.

10103.3k7](/packages/mf-collections-php)

PHPackages © 2026

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