コード例 #1
0
$request->setDocType('SalesInvoice');
$input = "bogus";
while ($input != "D" && $input != "P") {
    echo "CancelCode: Enter D for DocDeleted, or P for PostFailed: [D]";
    $input = strtoupper(rtrim(fgets($STDIN)));
    if ($input == '') {
        $input = 'D';
    }
}
$code = CancelCode::$DocDeleted;
if ($input == 'P') {
    $code = CancelCode::$PostFailed;
}
$request->setCancelCode($code);
try {
    $result = $client->cancelTax($request);
    echo 'CancelTax ResultCode is: ' . $result->getResultCode() . "\n";
    if ($result->getResultCode() != "Success") {
        foreach ($result->getMessages() as $msg) {
            echo $msg->getName() . ": " . $msg->getSummary() . "\n";
        }
    }
} catch (SoapFault $exception) {
    $msg = "Exception: ";
    if ($exception) {
        $msg .= $exception->faultstring;
    }
    echo $msg . "\n";
    echo $client->__getLastRequest() . "\n";
    echo $client->__getLastResponse() . "\n";
}
コード例 #2
0
ファイル: avalara.php プロジェクト: sam-akopyan/hamradio
 private function cancelOrder($data, $old_order_status)
 {
     //	vmdebug('my data on cancelOrder ',$data);
     //	if(empty($data->invoice_number)) return false;
     $orderModel = VmModel::getModel('orders');
     $orderDetails = $orderModel->getOrder($data->virtuemart_order_id);
     $calc = $this->getOrderCalc($orderDetails);
     if (!$calc) {
         return false;
     }
     $invoiceNumber = 'onr_' . $orderDetails['details']['BT']->order_number;
     $orderModel->createInvoiceNumber($orderDetails['details']['BT'], $invoiceNumber);
     if (!$invoiceNumber) {
         vmInfo('No invoice created, no reason to cancel at Avatax');
         return false;
     }
     if (is_array($invoiceNumber)) {
         $invoiceNumber = $invoiceNumber[0];
     }
     #
     if (!function_exists('EnsureIsArray')) {
         require VMAVALARA_PATH . DS . 'AvaTax.php';
     }
     // include in all Avalara Scripts
     if (!class_exists('TaxServiceSoap')) {
         require VMAVALARA_CLASS_PATH . DS . 'TaxServiceSoap.class.php';
     }
     if (!class_exists('CancelTaxRequest')) {
         require VMAVALARA_CLASS_PATH . DS . 'CancelTaxRequest.class.php';
     }
     $this->newATConfig($calc);
     $client = new TaxServiceSoap($this->_connectionType);
     $request = new CancelTaxRequest();
     $request->setDocCode($invoiceNumber);
     $request->setDocType(DocumentType::$SalesInvoice);
     $request->setCompanyCode($calc['company_code']);
     // Dashboard Company Code
     if ($calc['committ'] == 0) {
         return false;
     }
     //CancelCode: Enter D for DocDeleted, or P for PostFailed: [D]
     //I do not know the difference, I use always D (I assume this means order got deleted, cancelled, or refund)
     $code = CancelCode::$DocDeleted;
     $request->setCancelCode($code);
     try {
         avadebug('plgVmOnCancelPayment used request', $request);
         $result = $client->cancelTax($request);
         if ($result->getResultCode() != "Success") {
             $msg = '';
             foreach ($result->getMessages() as $rmsg) {
                 $msg .= $rmsg->getName() . ": " . $rmsg->getSummary() . "\n";
             }
             vmError($msg);
         } else {
             vmInfo('CancelTax ResultCode is: ' . $result->getResultCode());
         }
     } catch (SoapFault $exception) {
         $msg = "Exception: ";
         if ($exception) {
             $msg .= $exception->faultstring;
         }
         $msg .= "\n";
         $msg .= $client->__getLastRequest() . "\n";
         $msg .= $client->__getLastResponse() . "\n";
         vmError($msg);
     }
 }
コード例 #3
0
 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;
 }