<?php
require('includes/application_top.php');

/*
if (!strstr($HTTP_REFERER, 'buysafe.com'))
{
  header("HTTP/1.0 500 Internal Server Error");
  header("BuySafeSuccess = FALSE");
  exit;
}
*/

if ($HTTP_POST_VARS['PassCode'] != md5(MODULE_BUYSAFE_BUYSAFE_CART_PREFIX))
{
  header("HTTP/1.0 500 Internal Server Error");
  header("BuySafeSuccess = FALSE");
  exit;
}

tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $HTTP_POST_VARS['SealData'] . "' where configuration_key = 'MODULE_BUYSAFE_BUYSAFE_SEAL_AUTHENTICATION_DATA'");
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $HTTP_POST_VARS['StoreData'] . "' where configuration_key = 'MODULE_BUYSAFE_BUYSAFE_STORE_AUTHENTICATION_DATA'");

$class = 'buysafe';
$buysafe_directory = DIR_FS_CATALOG_MODULES . 'buySAFE/';
$file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
if (file_exists($buysafe_directory . $class . $file_extension))
{
  include($buysafe_directory . $class . $file_extension);
  $buysafe = new $class;
  $buysafe_param['private_token'] = $HTTP_POST_VARS['StoreData'];
  $buysafe_result = $buysafe->call_api('GetbuySAFEDateTime', $buysafe_param);
  if ($buysafe_result['buySAFEDateTime'])
  {
    header("HTTP/1.0 200 OK");
    header("BuySafeSuccess = TRUE");
    exit;
  }
}

header("HTTP/1.0 500 Internal Server Error");
header("BuySafeSuccess = FALSE");
?>