public string sendRequestXML(string ticket, string strHCPResponse, string strCompanyFileName, string qbXMLCountry, int qbXMLMajorVers, int qbXMLMinorVers)
        {
            try
            {
                if (!IoC.Resolve <IQBService>().QBIsEnabled || !Ticket.Equals(ticket) || !IsTicketActive)
                {
                    return(String.Empty);
                }

                QBEntity entity = IoC.Resolve <IQBService>().GetQBEntityForSynchronization();
                if (entity == null)
                {
                    return(String.Empty);
                }

                XmlDocument req = null;
                switch (entity.EntityType)
                {
                case EntityTypeEnum.Customer:
                    req = String.IsNullOrEmpty(entity.QBEntityId) ? QBXMLHelper.CreateCustomerAddRq(entity) : QBXMLHelper.CreateCustomerModRq(entity);
                    break;

                case EntityTypeEnum.Invoice:
                    req = String.IsNullOrEmpty(entity.QBEntityId) ? QBXMLHelper.CreateInvoiceAddRq(entity) : QBXMLHelper.CreateInvoiceModRq(entity);
                    break;

                case EntityTypeEnum.ReceivePayment:
                    req = QBXMLHelper.CreateReceivePaymentAddRq(entity);
                    break;

                case EntityTypeEnum.TxnVoid:
                    req = QBXMLHelper.CreateTxnVoidRq(entity);
                    break;

                case EntityTypeEnum.TxnDel:
                    req = QBXMLHelper.CreateTxnDelRq(entity);
                    break;

                default:
                    return(String.Empty);
                }

                if (req == null)
                {
                    return(String.Empty);
                }

                QBXMLHelper.SetRequestId(req, entity.EntityId);

                return(req.OuterXml);
            }
            catch (Exception ex)
            {
                IoC.Resolve <ILogService>().InsertLog(LogTypeEnum.CommonError, ex.Message, ex);
                return(String.Empty);
            }
        }
        public int receiveResponseXML(string ticket, string response, string hresult, string message)
        {
            try
            {
                if (!IoC.Resolve <IQBService>().QBIsEnabled || !Ticket.Equals(ticket) || !IsTicketActive)
                {
                    return(-1);
                }

                if (!String.IsNullOrEmpty(hresult))
                {
                    IoC.Resolve <ILogService>().InsertLog(LogTypeEnum.CommonError, message, hresult);
                    return(-1);
                }

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(response);

                int      requestId = QBXMLHelper.GetRequestId(xml);
                QBEntity entity    = IoC.Resolve <IQBService>().GetQBEntityById(requestId);
                if (entity == null)
                {
                    return(-1);
                }

                int statusCode = QBXMLHelper.GetStatusCode(xml);
                switch (statusCode)
                {
                case 0:
                case 530:
                case 531:
                case 550:
                case 560:
                case 570:
                {
                    string qbId   = entity.QBEntityId;
                    string seqNum = entity.SeqNum;
                    switch (QBXMLHelper.GetResponseType(xml))
                    {
                    case "TxnVoidRs":
                    case "TxnDelRs":
                        qbId = QBXMLHelper.GetTxnID(xml);
                        break;

                    case "ReceivePaymentAddRs":
                    case "InvoiceAddRs":
                        qbId   = QBXMLHelper.GetTxnID(xml);
                        seqNum = QBXMLHelper.GetSeqNum(xml);
                        break;

                    case "CustomerAddRs":
                        qbId   = QBXMLHelper.GetListID(xml);
                        seqNum = QBXMLHelper.GetSeqNum(xml);
                        break;

                    case "CustomerModRs":
                    case "InvoiceModRs":
                        seqNum = QBXMLHelper.GetSeqNum(xml);
                        break;
                    }

                    entity.QBEntityId = qbId;
                    entity.SynStateId = (int)SynStateEnum.Success;
                    entity.SeqNum     = seqNum;
                    entity.UpdatedOn  = DateTime.UtcNow;
                    IoC.Resolve <IQBService>().UpdateQBEntity(entity);
                }
                break;

                case 3175:
                {
                    IoC.Resolve <ILogService>().InsertLog(LogTypeEnum.CommonError, QBXMLHelper.GetStatusMessage(xml), statusCode.ToString());
                }
                break;

                default:
                {
                    IoC.Resolve <ILogService>().InsertLog(LogTypeEnum.CommonError, QBXMLHelper.GetStatusMessage(xml), statusCode.ToString());

                    entity.SynStateId = (int)SynStateEnum.Failed;
                    entity.UpdatedOn  = DateTime.UtcNow;
                    IoC.Resolve <IQBService>().UpdateQBEntity(entity);
                }
                break;
                }
                return(0);
            }
            catch (Exception ex)
            {
                IoC.Resolve <ILogService>().InsertLog(LogTypeEnum.CommonError, ex.Message, ex);
                return(-1);
            }
        }
Beispiel #3
0
        public int receiveResponseXML(string ticket, string response, string hresult, string message)
        {
            try
            {
                if (!QBManager.QBIsEnabled || !Ticket.Equals(ticket) || !IsTicketActive)
                {
                    return(-1);
                }

                if (!String.IsNullOrEmpty(hresult))
                {
                    LogManager.InsertLog(LogTypeEnum.CommonError, message, hresult);
                    return(-1);
                }

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(response);

                int      requestId = QBXMLHelper.GetRequestId(xml);
                QBEntity entity    = QBManager.GetQBEntityById(requestId);
                if (entity == null)
                {
                    return(-1);
                }

                int statusCode = QBXMLHelper.GetStatusCode(xml);
                switch (statusCode)
                {
                case 0:
                case 530:
                case 531:
                case 550:
                case 560:
                case 570:
                    string qbId   = entity.QBEntityId;
                    string seqNum = entity.SeqNum;
                    switch (QBXMLHelper.GetResponseType(xml))
                    {
                    case "TxnVoidRs":
                    case "TxnDelRs":
                        qbId = QBXMLHelper.GetTxnID(xml);
                        break;

                    case "ReceivePaymentAddRs":
                    case "InvoiceAddRs":
                        qbId   = QBXMLHelper.GetTxnID(xml);
                        seqNum = QBXMLHelper.GetSeqNum(xml);
                        break;

                    case "CustomerAddRs":
                        qbId   = QBXMLHelper.GetListID(xml);
                        seqNum = QBXMLHelper.GetSeqNum(xml);
                        break;

                    case "CustomerModRs":
                    case "InvoiceModRs":
                        seqNum = QBXMLHelper.GetSeqNum(xml);
                        break;
                    }
                    QBManager.UpdateQBEntity(entity.EntityId, qbId, entity.EntityType, entity.NopEntityId, SynStateEnum.Success, seqNum);
                    break;

                case 3175:
                    LogManager.InsertLog(LogTypeEnum.CommonError, QBXMLHelper.GetStatusMessage(xml), statusCode.ToString());
                    break;

                default:
                    LogManager.InsertLog(LogTypeEnum.CommonError, QBXMLHelper.GetStatusMessage(xml), statusCode.ToString());
                    QBManager.UpdateQBEntity(entity.EntityId, entity.QBEntityId, entity.EntityType, entity.NopEntityId, SynStateEnum.Failed, entity.SeqNum);
                    break;
                }
                return(0);
            }
            catch (Exception ex)
            {
                LogManager.InsertLog(LogTypeEnum.CommonError, ex.Message, ex);
                return(-1);
            }
        }