﻿<?php

#Create Post Information
// Account vars
$vars =  array();

..$vars['IsValidationOnly'] = 'true'; // Use On development Only!;

$vars['Oparation'] = "CLOSE";  // Or "REOPEN"
$vars["UserName"] = "SuppUserName"; // delar user name
$vars["Password"] ="SuppPassword"; // delar password 
$vars["Secret"] = "SuppSecret"; // delar Secret 
$vars['codepage'] = '65001'; // unicode



// ******************
// Terminal Info 
// ******************
// Req :
$vars['TerminalInfo.TerminalNumber'] = '1000'; 

// Send Data To Bill Gold Server
$r = PostVars($vars,'https://secure.cardcom.solutions/Interface/CompanyOperations.aspx');

echo $r;

parse_str($r,$responseArray);
if($responseArray['ResponseCode']==0)
{
  // Save In DB:
    echo "CompanyInternalID: " . $responseArray['CompanyInternalID'];
    echo "TerminalNumber: " . $responseArray['TerminalNumber'];
    echo "APIUserName: " . $responseArray['APIUserName'];
    echo "APISecret: " . $responseArray['APISecret'];
}
else
{
// if($responseArray['ShowErrorToEndUser']==true)
   if(true)
 {
    echo "Show Error To User : " .$responseArray['Description'];
 }
  else
 {
    echo "ResponseCode : " . $responseArray['ResponseCode'];
    echo "Developer  Error ! send email alert : " . $responseArray['Description'];
 }
}


function PostVars($vars,$PostVarsURL)
{
  $urlencoded = http_build_query($vars);
  #init curl connection
  if( function_exists( "curl_init" )) 
  { 
     $CR = curl_init();
    curl_setopt($CR, CURLOPT_URL, $PostVarsURL);
    curl_setopt($CR, CURLOPT_POST, 1);
    curl_setopt($CR, CURLOPT_FAILONERROR, true);
    curl_setopt($CR, CURLOPT_POSTFIELDS, $urlencoded );
    curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($CR, CURLOPT_FAILONERROR,true);
    #actual curl execution perfom
    $r = curl_exec( $CR );
    $error = curl_error ( $CR );
    # some error , send email to developer
    if( !empty( $error )) {

      echo $error;

      die();
    }
   curl_close( $CR );
   return $r;
 }
  else
 {
  echo "No curl_init" ;
  die();
  }
}

?>