/**
  * @brief Connect to Avalara to make sure everything is OK
  */
 private function _testConnection()
 {
     $this->_connectToAvalara();
     try {
         $client = new TaxServiceSoap(Configuration::get('AVALARATAX_MODE'));
         $connectionTest = $client->ping();
         if ($connectionTest->getResultCode() == SeverityLevel::$Success) {
             try {
                 $authorizedTest = $client->isAuthorized('GetTax');
                 if ($authorizedTest->getResultCode() == SeverityLevel::$Success) {
                     $expirationDate = $authorizedTest->getexpires();
                 }
             } catch (SoapFault $exception) {
             }
             return array('<img src="../img/admin/ok.gif" alt="" /><strong style="color: green;">' . $this->l('Connection Test performed successfully.') . '</strong><br /><br />' . $this->l('Ping version is:') . ' ' . Tools::safeOutput($connectionTest->getVersion()) . (isset($expirationDate) ? '<br /><br />' . $this->l('License Expiration Date:') . ' ' . Tools::safeOutput($expirationDate) : ''), '#D6F5D6');
         }
     } catch (SoapFault $exception) {
         return array('<img src="../img/admin/forbbiden.gif" alt="" /><b style="color: #CC0000;">' . $this->l('Connection Test Failed.') . '</b><br /><br />' . $this->l('Either the Account or License Key is incorrect. Please confirm the Account and License Key before testing the connection again.') . '<br /><br /><strong style="color: #CC0000;">' . $this->l('Error(s):') . ' ' . Tools::safeOutput($exception->faultstring) . '</strong>', '#FFD8D8');
     }
 }
Beispiel #2
0
 function ping($calc)
 {
     $html = '';
     $this->newATConfig($calc);
     if (!class_exists('TaxServiceSoap')) {
         require VMAVALARA_CLASS_PATH . DS . 'TaxServiceSoap.class.php';
     }
     $client = new TaxServiceSoap($this->_connectionType);
     try {
         if (!class_exists('PingResult')) {
             require VMAVALARA_CLASS_PATH . DS . 'PingResult.class.php';
         }
         $result = $client->ping("TEST");
         vmInfo('Avalara Ping ResultCode is: ' . $result->getResultCode());
         if (!class_exists('SeverityLevel')) {
             require VMAVALARA_CLASS_PATH . DS . 'SeverityLevel.class.php';
         }
         if ($result->getResultCode() != SeverityLevel::$Success) {
             foreach ($result->Messages() as $msg) {
                 $html .= $msg->Name() . ": " . $msg->Summary() . "<br />";
             }
         } else {
             vmInfo('Avalara used Ping Version is: ' . $result->getVersion());
         }
     } catch (SoapFault $exception) {
         $err = "Exception: ping ";
         if ($exception) {
             $err .= $exception->faultstring;
         }
         $err .= '<br />';
         $err .= 'last request: ' . $client->__getLastRequest() . '<br />';
         $err .= 'last response: ' . $client->__getLastResponse() . '<br />';
         vmError($err);
         avadebug('AvaTax the ping throws exception ', $exception);
     }
     return $html;
 }
<?php

require '../../AvaTax4PHP/AvaTax.php';
// include in all Avalara Scripts
require '../Credentials.php';
// where service URL, account, license key are set
$client = new TaxServiceSoap('Development');
try {
    $result = $client->ping("");
    echo 'Ping ResultCode is: ' . $result->getResultCode() . "\n";
    if ($result->getResultCode() != SeverityLevel::$Success) {
        foreach ($result->Messages() as $msg) {
            echo $msg->Name() . ": " . $msg->Summary() . "\n";
        }
    } else {
        echo 'Ping Version is: ' . $result->getVersion() . "\n\n";
    }
} catch (SoapFault $exception) {
    $msg = "Exception: ";
    if ($exception) {
        $msg .= $exception->faultstring;
    }
    echo $msg . "\n";
    echo $client->__getLastRequest() . "\n";
    echo $client->__getLastResponse() . "\n";
}