Skip to content

Tutorial

Setting up a Loyalty Program

This guide shows you how to create a new Loyalty Program. Furthermore, we look at how you can use the Fanpoints SDK to let your users participate in the Loyalty Program.

Creating a new Loyalty Program

Contact us at info@fanpoints.ch to get in touch with us and create a new Loyalty Program.

Accepting Marketing Partners

Open your Loyalty Program and navigate to the Partnerschaften tab. When a partner requests to join your Loyalty Program, you can accept or decline the request. This will allow users to interact with the Loyalty Program at this partner.

Setting up the Fanpoints SDK

Now you’re ready to integrate the Fanpoints SDK into your infrastructure. You can use the SDK to let users enter your Loyalty Program.

Currently, only a server-side typescript SDK is available. It needs to be used in your backend, as user-level authorization is not yet supported. We are working on a client-side SDK that will allow you to use the SDK in your client-side code.

Installing the SDK

You can install the SDK using npm:

Terminal window
npm install @fanpoints/server-js

Getting access tokens

To access the Fanpoints API, you first need to generate access tokens. Go to the dashboard, navigate to your Loyalty Program, click on Einstellungen and then on API Tokens. You can generate a new token there. Each token consists of a client id and a secret.

Configuring a client

All operations are performed on a FanPointsClient object. With the generated access tokens, you can create a client for your Loyalty Program:

import { createClient } from '@fanpoints/server-js';
const client = createClient({
loyaltyProgramConfig: {
loyaltyProgramId: 'the Loyalty Program id', // can be found in the dashboard
clientId: 'the client id',
secret: 'the client secret',
},
});

You can use the ping function to test if the client is working:

client.ping().then(() => {
console.log('The client is working!');
});

Using the Fanpoints SDK

Registering users

You are now ready to register your users in the Loyalty Program. You could decide that all your existing users are automatically registered in the Loyalty Program. You can also let users manually opt-in into the Loyalty Program.

Either way, you can use the following code to register a user in the Loyalty Program:

await client.users.addUser('your user id', '<the users mail address>');

Now the user is registered in the Loyalty Program and can start collecting and spending fan points.

On user ids

Note that you have to specify your own internal user id. The user will get its own Fanpoints user id. You can use both your internal or the Fanpoints user id to interact with the SDK, as translation happens automatically.

You can see this by using the following snippet:

const user = await client.users.getUser('your user id');
/**
* user = {
* mailAddress: 'tobia.ochsner@gmail.com',
* fanPointsUserId: '<the fanpoints id>',
* userId: '<your id>'
* }
*/

Deleting users

In order to delete a user from the Loyalty Program, you can use the following snippet:

await client.users.deleteUser('your user id');

Creating user wallet passes

You can generate Apple Wallet and Google Wallet passes for your users. These allow them to store their User ID and current FanPoints balance on their device. Use the following snippet to create a new pass:

const passes = await client.users.getUserPasses('your user id');
/**
* passes = {
* googleWalletPassUrl: '<some_url_to_google_wallet_pass>',
* appleWalletPassUrl: '<some_url_to_apple_wallet_pass>'
* }
*/

The user can simply open these links to add the pass to their wallet.