API - Commissions

Overview
Send commission data to your Maian Affiliate system. Please read carefully.
Commission Value
For flexibility you can create the commission value at the time you ping the Maian Affiliate API. This is set in the 'commtotal' field as specified below. You can also set a custom affiliate percentage override for affiliates in your Maian Affiliates system, this allows you to set higher earning percentages for affiliates who earn more money.

If a percentage is set at the Maian Affiliate level, this takes priority. In the case of a custom level, you don't need to pass a 'commtotal' value as the Maian Affiliate system will auto calculate the percentage based on the 'saletotal' value. If you do pass a 'commtotal' value and there is a custom level set for an affiliate, the 'commtotal' value is ignored and recalculated by the Maian Affiliate system. Examples:

1 You pass 'commtotal' value of '9.99' and there is no custom commission level set for an affiliate. Commission is 9.99.

2 You pass 'commtotal' value of '9.99' and there IS a custom commission level set for an affiliate. Commission is set percentage of saletotal.
API Data Structure
The following data should be transmitted with your commission calls (shown as standard JSON array):
{
  "apikey": "YOUR API KEY",
  "affiliate": "AFFILIATE CODE",
  "commission": {
    "product": "PRODUCT ID",
    "saletotal": "SALE TOTAL",
    "commtotal": "COMMISSION VALUE",
    "notes": "OPTIONAL NOTES HERE",
    "ip": "SALE IP ADDRESS"
  },
  "emails": {
    "affiliate": "yes",
    "admin": "no"
  },
  "custom": {}
}

apikey = Your api key as set in the settings. This must be included with all calls.
affiliate = Affiliate code, this would come from the cookie that is set (see below).
commission = Commission array containing the following:

product = Product ID corresponding to product in your Maian Affiliate system.
saletotal = Sale total. No currency symbols or commas. Examples: 9.99, 45.78, 1245.76 etc
commtotal = Commission total. No currency symbols or commas. Examples: 9.99, 45.78, 1245.76 etc. Does not need to be included if custom commission set for affiliate. See note above.
notes = Optional notes. Not seen by affiliate. These are logged in the database and are viewable in your Maian Affiliate admin area.
ip = Sale IP address.
emails = Email array if you wish to suppress emails from being sent. By default, emails are on, so you only need to include these if you wish to deactivate any emails. In the above example, the admin email is not sent.
custom = Option custom array. Key / value pairs that are included in the email sent to the webmaster. These are not logged in the system. This is optional and does not need to be included unless you require it.
API Response
You should handle the responses accordingly if required.

An error response will be as follows:
{
  "status": "error",
  "message": "ERROR MESSAGE"
}


If successful the API sends back additional data if you need to do further processing. A successful response will be as follows:
{
  "status": "ok",
  "data": {
    "commissionID": "26",
    "affiliateID": "1",
    "productID": "3",
    "sale": "24.99",
    "commission": "2.49",
    "affiliateName": "John Harris",
    "affiliateEmail": "example@gmail.com",
    "affiliateSetCommission": "10%"
  }
}


The data array is only sent back on a successful response. "affiliateSetCommission" is blank if no custom commission is set. The ID numbers correspond to the ID numbers in your Maian Affiliate system.
Full PHP Code Example
The following is a full code example. Change values accordingly for your own setup. You'll need to modify your ecommerce code to ping the Maian Affiliates API with the correct values after a sale. Also, remember to use the same cookie name you used when sending referrals.
<?php
// Check for affiliate cookie..
if (isset($_COOKIE['msw_aff_2018151810_code'])) {
  // Prepare array..
  $data = array(
    'apikey' => 'YOUR API KEY HERE..',
    'affiliate' => $_COOKIE['msw_aff_2018151810_code'],
    'commission' => array(
      'product' => 'PRODUCT ID HERE..',
      'saletotal' => 'SALE TOTAL HERE..',
      'commtotal' => 'COMMISSION TOTAL HERE..',
      'notes' => 'OPTIONAL NOTES HERE..',
      'ip' => (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '')
    ),
    // Optional emails array..
    'emails' => array(
      'affiliate' => 'yes',
      'admin' => 'no'
    ),
    // Optional custom array..
    'custom' => array(
      'date' => date('j F Y'),
      'something' => 'value'
    )
  );
  // Send to API..
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://www.path-to-your-maian-affiliate-setup.com/index.php');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json'
  ));
  curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  $r = json_decode(curl_exec($ch), true);
  curl_close($ch);
  // Do something with response..
  if (isset($r['status'])) {
    switch($r['status']) {
      case 'error':
        // echo $r['message'];
        break;
      case 'ok':
        // print_r($r['data']);
        break;
    }
  } else {
    // Check logs folder in Maian Affiliates, something went wrong
  }
}
?>


You can copy and paste the above code if you need to. You should change the api key, product ID and commission values and make sure the CURLOPT_URL path is correct.
Where Do I Add Commission Code on my Websites?
Your commission API code should go directly after a sale is processed in your ecommerce system, so you'll need to locate the relevant code and update the API values accordingly. Some integration code may be available on the Maian Affiliate website.
Debugging
If you enable the API log data will be logged in the "logs" folder each time there is a call from the API. Refer to this for help. You should disable the log when you are ready to go live. Note that general errors, referral errors and commissions errors are all logged separately.
Back to API