0.2.10 • Published 3 years ago

beta-affiliate v0.2.10

Weekly downloads
3
License
MIT
Repository
-
Last release
3 years ago

Beta Affiliate Node SDK

Installation

npm install beta-affiliate --save

Usage

import affiliate from 'beta-affiliate';

affiliate.setConfig({
    apiKey: 'your_api_key',
    baseUrl: 'https://api.affiliate.beta.limited',
})

// or

import {BetaAffiliate} from 'beta-affiliate';

const affiliate = new BetaAffiliate({
    apiKey: 'your_api_key',
    baseUrl: 'https://api.affiliate.beta.limited',
})

Redirecting users

This will create affiliate user if doesn't exists, otherwise update props and return code and user object. Redirect to the affiliate page using login code

const loginData = await affiliate.getLoginCodeByUser({
    email: user.email,
    props: [{name: 'Name', value: user.name, public: true}],
    balance: 0,
});

if (loginData instanceof Error) {
    req.flash('info', 'We cannot connect to your affiliate account at this time');
    return res.redirect('/');
}
return res.redirect('https://affiliate.beta.limited/auth/with-code?pwd=' + loginData.code);

Confirming referrer

You can save referrer code to user object if its a valid referrer code

if (input.referrerCode) {
    const affiliateUser = await affiliate.getUserByCode(input.referrerCode).catch(e => e);
    if (!(affiliateUser instanceof Error) && affiliateUser.email != input.email)
        user.referrerCode = input.referrerCode;
}

Resolving plans:

This will resolve plan prices

const plans = [
    {
        price: 29.99,
        name: 'Monthly Plan',
        planId: 'plan-monthly',
    },
    {
        price: 249.99,
        name: 'Annual Plan',
        planId: 'plan-annual',
    },
];
affiliate.resolvePlans({
    buyerId: user.email,
    code: user.referrerCode,
    plans,
    amountField: 'price',
    discountsField: 'discounts',
})
// Mutates plans object to have discounted price

Resolving discounts

This will return discounts array for given details

const discounts = await affiliate.resolve({
    code: user.referrerCode,
    amount: plan.price,
    buyerId: user.email,
});
0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.12

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago