Download the PHP package antavo/loyalty-sdk-php without Composer

On this page you can find all versions of the php package antavo/loyalty-sdk-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package loyalty-sdk-php

Antavo Loyalty SDK for PHP

Table of Contents

Requirements

Usage

Including the Library

Using the Phar package

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

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

The REST client

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

It uses two other libraries:

Creating an instance

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

Where:

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

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

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

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:

Customer Token

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

Creating an instance

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

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

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

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

$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

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.


All versions of loyalty-sdk-php with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
antavo/escher-php Version ^0.2.13
pakard/rest-client-php Version ^1.0
antavo/signed-token Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package antavo/loyalty-sdk-php contains the following files

Loading the files please wait ....