<?

/**
 *
 * INDEXU
 * Copyright(C), Nicecoder, 2000-2006, All Rights Reserved.
 *
 * INDEXU(tm) is protected by Indonesia and International copyright laws.
 * Unauthorized use or distribution of INDEXU(tm) is strictly prohibited,
 * violators will be prosecuted. To obtain a license for using INDEXU(tm),
 * please register at Nicecoder home page at http://www.nicecoder.com
 *
 * Author:
 *    Dody Rachmat Wicaksono (dody@nicecoder.com)
 *    M. Zuber (zubby@nicecoder.com)
 *
 */

  include "../application.php";
  include "authorizenet.inc.php";
  
  ignore_user_abort(true);
  set_time_limit(300);

  define('AUTHORIZENET_RETURN', 1);

  $referers = array("www.authorize.net", "authorize.net");
  $valid_referer = FALSE;
  if ($_SERVER['HTTP_REFERER']) {
    while (list(, $host) = @each($referers)) {
      if (eregi($host, $_SERVER['HTTP_REFERER'])) {
        $valid_referer = TRUE;
      }
    }
  }
  else {
    $valid_referer = TRUE;
  }

  if (!$valid_referer) {
    exit;
  }

  if ($_POST['x_response_code'] != '1') {
    echo "<script>document.location='$_POST[cancel_url]&err=1'</script>";
    exit;
  }

  // get the custom value
  $raw            = explode('&', urldecode($_POST['custom']));
  $val_username   = $raw[0];
  $val_type       = $raw[1];
  $val_id         = $raw[2];

  // mark invoice as paid
  MarkAsPaid($val_id);

  echo "<script>document.location='$_POST[return_url]'</script>";

?>