ReCharge platform allows you to add recurring subscription products to your BigCommerce store. This guide explains how to integrate ReCharge with Post Affiliate Pro to track these recurring payments.
The BigCommerce integration consists of multiple steps on both ends. First, you need to create an API token in your ReCharge account and set it up in your Post Affiliate Pro account. Then add a tracking code to the ReCharge thank you page and place a click tracking code to your BigCommerce store footer.
To track recurring payments you either need the Recurring Commissions feature or the Lifetime Commissions plugin activated!
Create an API token
As a first step, you’ll need to contact ReCharge to request access to API. See https://support.rechargepayments.com/hc/en-us/articles/360008829993-ReCharge-API-tokens for more details.
Once you are granted API access, you can create your API token. To do so, log in to your Bigcommerce admin panel, go to the Apps section and click on ReCharge Subscriptions so you get to the ReCharge panel. Once there, click on the Integrations tab in the top menu, and then on API tokens. On the right edge of the page. Afterward, click on Create an API token.
Name the API token however you want, add an email where you will be notified if the webhook should be failing, and most importantly make sure you add Read access permission to Orders. If you can also see the Webhooks permission there, please set it to Read and Write access, however this might have been removed and therefore is no longer needed to be set. Save the token and copy its API key.
Configure ReCharge webhook handling plugin
The next step is to log into your Post Affiliate Pro merchant panel, go to Configuration -> Plugins and activate the plugin called ReCharge webhook handling. Once it’s active, click the Configure button and add the Recharge API key on the plugin configuration page.
On this page, you can also configure what exactly will be tracked as Product ID, and you can also choose if you want to track any additional order data in the extra data fields. When you are finished, save the plugin config at the bottom of the page.
Edit your thank you page
Log in to your BigCommerce admin panel, go to the Apps section and click on ReCharge Subscriptions so you get to the ReCharge admin panel. Once there, click the Settings (wrench icon) in the upper right corner and go to the Checkout section. Scroll down to the Thank you page section and paste the following code into the Additional & scripts and trackers field:
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('Account_ID');
var discountMultiplier = 1 - {{total_discounts}} / ({{subtotal_price}} + {{total_discounts}});
{% for item in line_items %}
var itemPrice = {{item.price}} * {{item.quantity}};
var sale{{ loop.index }} = PostAffTracker.createSale();
sale{{ loop.index }}.setTotalCost(itemPrice * discountMultiplier);
var subscriptionId = '{{item.subscription_id}}';
if (subscriptionId != '') {
sale{{ loop.index }}.setOrderID(subscriptionId);
} else {
sale{{ loop.index }}.setOrderID('{{id}}({{ loop.index }})');
}
sale{{ loop.index }}.setProductID('{{item.product_id}}');
sale{{ loop.index }}.setCoupon('{{discount_code}}');
{% endfor %}
PostAffTracker.register();
</script>
If you wish to save customer name or email you can add the following lines:
sale{{ loop.index }}.setData1('{{email}}');
sale{{ loop.index }}.setData2('{{first_name}} {{last_name}}');
under the line:
sale{{ loop.index }}.setCoupon('{{discount_code}}');
You can find more available variables in ReCharge knowledgebase.
Click tracking
Log in to your BigCommerce admin panel, go to the Storefront section and click on the Script manager. In this section click on the Create a Script button in the top right corner. Name the script, set Location on page to Footer, Select pages where script will be added to All pages, change Script type to Script, and insert the click tracking code from your Post Affiliate Pro merchant panel > Tools > Integration > Clicks tracking into the Script contents field and save it.