How to configure Fleio in order to sell reseller packages

Enable reseller feature

Enable 'billing.reseller' feature. Please see How to enable Reseller feature

Fleio settings.py changes

In settings.py we need to allow reseller domains to connect to fleio-backend. For this we need to apply the following changes in /var/webapps/fleio/project/fleio/settings.py file:

Uncomment the following lines and replace the reseller domains urls in the RESELLER_DOMAINS dictionary:

NEW_MIDDLEWARE = list(MIDDLEWARE)
NEW_MIDDLEWARE.insert(1, 'corsheaders.middleware.CorsMiddleware')
NEW_MIDDLEWARE.insert(1, 'fleio.csrf_reseller_pass.CsrfMid')
MIDDLEWARE = tuple(NEW_MIDDLEWARE)
RESELLER_DOMAINS = {
    'resllerdomain1.tld': {
        'url': 'http://resllerdomain1.tld',
        'cookie_domain': 'resllerdomain1.tld',
     },
    'backend.resllerdomain1.tld': {
        'url': 'http://resllerdomain1.tld',
        'cookie_domain': 'resllerdomain1.tld',
     },
    'resllerdomain2.tld': {
        'url': 'http://resllerdomain2.tld',
        'cookie_domain': 'resllerdomain2.tld',
     },
    'backend.resllerdomain2.tld': {
        'url': 'http://resllerdomain2.tld',
        'cookie_domain': 'resllerdomain2.tld',
     },
}
CORS_ORIGIN_WHITELIST = (
    'http://fleio-master.tld',
)
CORS_ALLOW_CREDENTIALS = True
CSRF_TRUSTED_ORIGINS = ['fleio-master.tld']
for domain in RESELLER_DOMAINS:
   CORS_ORIGIN_WHITELIST += (RESELLER_DOMAINS[domain]['url'],)
   CSRF_TRUSTED_ORIGINS.append(domain)
   ALLOWED_HOSTS.append(domain)

For each new domain you will have to add a new entry in the RESELLER_DOMAINS, with the following syntax:

'resllerdomain3.tld': {
    'url': 'http://resllerdomain3.tld',
    'cookie_domain': 'resllerdomain3.tld',
 },
'backend.resllerdomain3.tld': {
    'url': 'http://resllerdomain3.tld',
    'cookie_domain': 'resllerdomain3.tld',
 },

Also, for each reseller domain that you configure you need to also configure a new domain in nginx, for backend. See Add nginx configuration.

Add nginx configuration

Add nginx configuration file for your reseller’s backend url. Backend url must be a valid subdomain that will point to the same IP as for your master installation.

vim /etc/nginx/sites-enabled/backend.resllerdomain1.tld.conf

server {
    listen      80;
    client_max_body_size 5000m;
    #EDIT HERE
    server_name backend.resllerdomain1.tld;

    location /static {
        alias /var/webapps/fleio/env/lib/python3.6/site-packages/django/contrib/admin/static;
    }

    location /static/stripe {
        alias /var/webapps/fleio/project/fleio/billing/gateways/stripe/static/stripe;
    }

    location /static/rest_framework {
    alias /var/webapps/fleio/env/lib/python3.6/site-packages/rest_framework/static/rest_framework/;
    }

    # Finally, send all non-media requests to the Django server.
    location /backend/ {
        uwsgi_pass  django;
        include uwsgi_params;
    }

    location /images {
        alias /var/webapps/fleio/frontend/site/images/;
        break;
    }

    location /js {
        alias /var/webapps/fleio/frontend/site/js/;
        expires max;
        break;
    }

    location /vendor {
        alias /var/webapps/fleio/frontend/site/vendor/;
        expires max;
        break;
    }

    location /styles {
        alias /var/webapps/fleio/frontend/site/styles/;
        expires max;
        break;
    }

     location /reseller {
         root /var/webapps/fleio/frontend/site/;
         expires -1;
         try_files $uri $uri/ /reseller/index.html;
     }

    location /staff {
        alias /var/webapps/fleio/frontend/site/staff/;
        expires -1;
        try_files $uri $uri/ /staff/index.html;
    }

    location / {
        alias /var/webapps/fleio/frontend/site/;
        expires -1;
        try_files $uri $uri/ /index.html;
    }
}

Restart services

The final step is to restart the services. Please see Restarting Fleio. After that, you will have to continue with How to install reseller frontend.