Chargebee

Automate your subscription billing with Chargebee's plug & play billing software

Integration with Chargebee is achieved by setting a redirect URL with params and placing the sale tracking script into the thank you page using a simple JavaScript logic.

1.

First step
The first step would be to find the needed section where you can set the redirect URL. Login to your Chargebee and navigate to Product Catalog> Plans and edit each plan you want to integrate. Each plan has its own redirect URL, just make sure to use these params in it:
?pap=1&productID={{plan.id}}&customer={{customer.id}}&orderID={{subscription.id}}&price={{invoice.amount}}

2.

Sale tracking
Put the following code into the redirect URL you defined in each plan:

<script id="pap_x2s6df8d" src="http://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
if (getParameterByName('pap') == '1') {

PostAffTracker.setAccountId('Account_ID');
var sale = PostAffTracker.createSale();

sale.setTotalCost(getParameterByName('price'));
sale.setProductID(getParameterByName('productID'));
sale.setOrderID(getParameterByName('orderID'));
sale.setData1(getParameterByName('customer'));
PostAffTracker.register();
}
</script>

3.

Webhooks
Chargebee gives us an option to use webhooks which we can use to track recurring commissions. To setup a webhook, first enable the Chargebee plugin in your merchant panel. Then navigate to your Chargebee account into Settings> Configure Chargebee and find section 'API keys and webhooks' Enter the section and then navigate to Webhooks. Add a new webhook using the button there. USe the following URL for the webhook:
https://URL_TO_PostAffiliatePro/plugins/Chargebee/chargebee.php - save it and you are done.

It is now integrated. Every time a customer enters the order confirmation page, the tracking code is called, and it will register a sale for referring affiliate.