public function tax($type, $params = array())
 {
     $this->_connectToAvalara();
     $client = new TaxServiceSoap(Configuration::get('AVALARATAX_MODE'));
     if ($type == 'commit') {
         $request = new CommitTaxRequest();
     } elseif ($type == 'post') {
         $request = new PostTaxRequest();
         $request->setDocDate($params['DocDate']);
         $request->setTotalAmount($params['TotalAmount']);
         $request->setTotalTax($params['TotalTax']);
     } elseif ($type == 'cancel') {
         $request = new CancelTaxRequest();
         if ($params['CancelCode'] == 'D') {
             $code = CancelCode::$DocDeleted;
         } elseif ($params['CancelCode'] == 'P') {
             $code = CancelCode::$PostFailed;
         } elseif ($params['CancelCode'] == 'V') {
             $code = CancelCode::$DocVoided;
         } else {
             die('Invalid cancel code.');
         }
         $request->setCancelCode($code);
     } elseif ($type == 'history') {
         $request = new GetTaxHistoryRequest();
         $request->setDetailLevel(DetailLevel::$Document);
     }
     if ($type != 'isAuthorized') {
         $request->setDocCode('Order ' . (int) $params['DocCode']);
         $request->setDocType(DocumentType::$SalesInvoice);
         $request->setCompanyCode(Configuration::get('AVALARATAX_COMPANY_CODE'));
     }
     $buffer = array();
     try {
         if ($type == 'commit') {
             $result = $client->commitTax($request);
         } elseif ($type == 'post') {
             $result = $client->postTax($request);
         } elseif ($type == 'cancel') {
             $result = $client->cancelTax($request);
         } elseif ($type == 'isAuthorized') {
             $result = $client->isAuthorized('GetTax');
         } elseif ($type == 'history') {
             $result = $client->getTaxHistory($request);
             $buffer['Invoice'] = $result->getGetTaxRequest()->getDocCode();
             $buffer['Status'] = $result->getGetTaxResult()->getDocStatus();
         }
         $buffer['ResultCode'] = $result->getResultCode();
         if ($result->getResultCode() != SeverityLevel::$Success) {
             foreach ($result->getMessages() as $msg) {
                 $buffer['Messages']['Name'] = Tools::safeOutput($msg->getName());
                 $buffer['Messages']['Summary'] = Tools::safeOutput($msg->getSummary());
             }
         }
     } catch (SoapFault $exception) {
         $buffer['Exception']['FaultString'] = Tools::safeOutput($exception->faultstring);
         $buffer['Exception']['LastRequest'] = Tools::safeOutput($client->__getLastRequest());
         $buffer['Exception']['LastResponse'] = Tools::safeOutput($client->__getLastResponse());
     }
     return $buffer;
 }
require '../Credentials.php';
// where service URL, account, license key are set
$STDIN = fopen('php://stdin', 'r');
$client = new TaxServiceSoap('Development');
$request = new GetTaxHistoryRequest();
$input = "bogus";
// Locate Document by Invoice Number
echo "Enter Invoice Number (Document Code): ";
$input = rtrim(fgets($STDIN));
$request->setDocCode($input);
$request->setCompanyCode('DEFAULT');
// Dashboard Company Code
$request->setDocType(DocumentType::$SalesInvoice);
$request->setDetailLevel(DetailLevel::$Document);
try {
    $result = $client->getTaxHistory($request);
    echo 'GetTaxHistory ResultCode is: ' . $result->getResultCode() . "\n";
    if ($result->getResultCode() != SeverityLevel::$Success) {
        foreach ($result->getMessages() as $msg) {
            echo $msg->getName() . ": " . $msg->getSummary() . "\n";
        }
    } else {
        echo "Invoice Number: " . $result->getGetTaxRequest()->getDocCode();
        echo "Current Status: " . $result->getGetTaxResult()->getDocStatus() . "\n";
    }
} catch (SoapFault $exception) {
    $msg = "Exception: ";
    if ($exception) {
        $msg .= $exception->faultstring;
    }
    echo $msg . "\n";