beta-affiliate
TypeScript icon, indicating that this package has built-in type declarations

0.2.10 • Public • Published

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,
});

Readme

Keywords

Package Sidebar

Install

npm i beta-affiliate

Weekly Downloads

50

Version

0.2.10

License

MIT

Unpacked Size

18 kB

Total Files

14

Last publish

Collaborators

  • beta.limited