<?php
// Check for affiliate cookie..
if (isset($_COOKIE['{COOKIE}'])) {
  // Prepare array..
  $data = array(
    'apikey' => '{API_KEY}',
    'affiliate' => $_COOKIE['{COOKIE}'],
    'commission' => array(
      'product' => '{PRODUCT_ID}',
      'saletotal' => 'SALE TOTAL HERE..',
      'commtotal' => 'COMMISSION TOTAL HERE..',
      'notes' => '',
      'ip' => (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '')
    )
  );
  // Send to API..
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, '{SITE_FOLDER}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
  }
}
?>