コード例 #1
0
        public virtual void CancelTaxDocument(CustomerOrder order)
        {
            LogInvoker <AvalaraLogger.TaxRequestContext> .Execute(log =>
            {
                if (IsEnabled && !string.IsNullOrEmpty(AccountNumber) && !string.IsNullOrEmpty(LicenseKey) &&
                    !string.IsNullOrEmpty(ServiceUrl) &&
                    !string.IsNullOrEmpty(CompanyCode))
                {
                    var request = order.ToAvaTaxCancelRequest(CompanyCode, CancelCode.DocDeleted);
                    if (request != null)
                    {
                        log.docCode = request.DocCode;
                        log.docType = request.DocType.ToString();

                        var taxSvc       = new JsonTaxSvc(AccountNumber, LicenseKey, ServiceUrl);
                        var getTaxResult = taxSvc.CancelTax(request);

                        if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success))
                        {
                            var error = string.Join(Environment.NewLine, getTaxResult.Messages.Select(m => m.Summary));
                            throw new Exception(error);
                        }
                    }
                }
                else
                {
                    throw new Exception("AvaTax credentials not provided or tax calculation disabled");
                }
            })
            .OnError(_logger, AvalaraLogger.EventCodes.TaxCalculationError)
            .OnSuccess(_logger, AvalaraLogger.EventCodes.GetTaxRequestTime);
        }
コード例 #2
0
        private void CancelCustomerOrderTaxes(OrderChangeEvent context)
        {
            if (!context.ModifiedOrder.IsCancelled)
            {
                return;
            }

            SlabInvoker <VirtoCommerceEventSource.TaxRequestContext> .Execute(slab =>
            {
                if (_taxSettings.IsEnabled && !string.IsNullOrEmpty(_taxSettings.Username) && !string.IsNullOrEmpty(_taxSettings.Password) &&
                    !string.IsNullOrEmpty(_taxSettings.ServiceUrl) &&
                    !string.IsNullOrEmpty(_taxSettings.CompanyCode))
                {
                    var order   = context.ModifiedOrder;
                    var request = order.ToAvaTaxCancelRequest(_taxSettings.CompanyCode, CancelCode.DocDeleted);
                    if (request != null)
                    {
                        slab.docCode = request.DocCode;
                        slab.docType = request.DocType.ToString();

                        var taxSvc       = new JsonTaxSvc(_taxSettings.Username, _taxSettings.Password, _taxSettings.ServiceUrl);
                        var getTaxResult = taxSvc.CancelTax(request);

                        if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success))
                        {
                            var error = string.Join(Environment.NewLine, getTaxResult.Messages.Select(m => m.Summary));
                            throw new Exception(error);
                        }
                    }
                }
                else
                {
                    throw new Exception("AvaTax credentials not provided or tax calculation disabled");
                }
            })
            .OnError(VirtoCommerceEventSource.Log, VirtoCommerceEventSource.EventCodes.TaxCalculationError)
            .OnSuccess(VirtoCommerceEventSource.Log, VirtoCommerceEventSource.EventCodes.GetTaxRequestTime);
        }