Exemplo n.º 1
0
        public GovTalkMessage CreateGovTalkMessageForDataRequest(string senderId, string senderValue, bool testInLive)
        {
            if (!String.IsNullOrEmpty(senderId) && !String.IsNullOrEmpty(senderValue))
            {
                //define classtype
                string classType   = !testInLive ? "HMRC-VAT-DEC" : "HMRC-VAT-DEC-TIL";
                string gatewayTest = !testInLive ? "0" : "1";

                GovTalkMessage govTalkMessage = new GovTalkMessage();
                govTalkMessage.EnvelopeVersion =
                    ConfigurationManager.AppSettings["GovTalkMessageEnvelopeVersion"];
                //header
                GovTalkMessageHeader header = new GovTalkMessageHeader();
                //header message details
                GovTalkMessageHeaderMessageDetails messageDetails = new GovTalkMessageHeaderMessageDetails();
                messageDetails.Class                   = classType;
                messageDetails.Qualifier               = GovTalkMessageHeaderMessageDetailsQualifier.request;
                messageDetails.Function                = GovTalkMessageHeaderMessageDetailsFunction.list;
                messageDetails.Transformation          = GovTalkMessageHeaderMessageDetailsTransformation.XML;
                messageDetails.FunctionSpecified       = true;
                messageDetails.TransformationSpecified = true;
                messageDetails.CorrelationID           = "";
                messageDetails.GatewayTest             = gatewayTest;
                //sender details
                GovTalkMessageHeaderSenderDetails senderDetails          = new GovTalkMessageHeaderSenderDetails();
                GovTalkMessageHeaderSenderDetailsIDAuthentication idauth = new GovTalkMessageHeaderSenderDetailsIDAuthentication();
                idauth.SenderID = senderId;
                GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication aauth = new GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication();
                aauth.Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.clear;
                aauth.Role   = "principal";
                aauth.Item   = senderValue;
                GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication[] authentications = new GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication[1];
                authentications[0]             = aauth;
                idauth.Authentication          = authentications;
                senderDetails.IDAuthentication = idauth;
                header.MessageDetails          = messageDetails;
                header.SenderDetails           = senderDetails;
                //govtalk details
                GovTalkMessageGovTalkDetails      govTalkDetails = new GovTalkMessageGovTalkDetails();
                GovTalkMessageGovTalkDetailsKey[] keys           = new GovTalkMessageGovTalkDetailsKey[1];
                govTalkDetails.Keys = keys;
                //govtalk body
                GovTalkMessageBody body = new GovTalkMessageBody();
                govTalkMessage.Body           = body;
                govTalkMessage.Header         = header;
                govTalkMessage.GovTalkDetails = govTalkDetails;
                return(govTalkMessage);
            }
            return(null);
        }
Exemplo n.º 2
0
        public GovTalkMessage CreateGovTalkMessage(Sender sender, Business business, PeriodData periodData, VAT100 vatData, bool testInLive)
        {
            string classType   = !testInLive ? "HMRC-VAT-DEC" : "HMRC-VAT-DEC-TIL";
            string gatewayTest = !testInLive ? "0" : "1";

            //Gov Talk message
            GovTalkMessage govTalkMessage = new GovTalkMessage();
            //Gov Talk header
            GovTalkMessageHeader header = new GovTalkMessageHeader();
            //sender details
            GovTalkMessageHeaderSenderDetails senderDetails          = new GovTalkMessageHeaderSenderDetails();
            GovTalkMessageHeaderSenderDetailsIDAuthentication idauth = new GovTalkMessageHeaderSenderDetailsIDAuthentication();

            idauth.SenderID = sender.HMRCUserId;
            GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication aauth = new GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication();

            aauth.Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.clear;
            aauth.Role   = "principal";
            aauth.Item   = sender.HMRCPassword;
            GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication[] authentications = new GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication[1];
            authentications[0]             = aauth;
            idauth.Authentication          = authentications;
            senderDetails.IDAuthentication = idauth;
            senderDetails.EmailAddress     = sender.Email;
            //message details
            GovTalkMessageHeaderMessageDetails messagedetails = new GovTalkMessageHeaderMessageDetails();

            messagedetails.Class                   = classType;
            messagedetails.Qualifier               = GovTalkMessageHeaderMessageDetailsQualifier.request;
            messagedetails.Function                = GovTalkMessageHeaderMessageDetailsFunction.submit;
            messagedetails.FunctionSpecified       = true;
            messagedetails.CorrelationID           = "";
            messagedetails.Transformation          = GovTalkMessageHeaderMessageDetailsTransformation.XML;
            messagedetails.GatewayTest             = gatewayTest;
            messagedetails.TransformationSpecified = true;
            header.MessageDetails                  = messagedetails;
            header.SenderDetails                   = senderDetails;
            //Gov Talk details
            GovTalkMessageGovTalkDetails govTalkDetails = new GovTalkMessageGovTalkDetails();
            //keys
            GovTalkMessageGovTalkDetailsKey key = new GovTalkMessageGovTalkDetailsKey();

            key.Type  = ConfigurationManager.AppSettings["GovTalkDetailsKeyType"];
            key.Value = business.VATRegNo.ToString();
            GovTalkMessageGovTalkDetailsKey[] keys = new GovTalkMessageGovTalkDetailsKey[1];
            keys[0] = key;
            //Channel routing
            GovTalkMessageGovTalkDetailsChannelRoutingChannel channel = new GovTalkMessageGovTalkDetailsChannelRoutingChannel();

            channel.Version         = ConfigurationManager.AppSettings["ChannelVersion"];
            channel.Product         = ConfigurationManager.AppSettings["ChannelProduct"];
            channel.ItemElementName = ItemChoiceType.URI;
            channel.Item            = ConfigurationManager.AppSettings["ChannelUri"];
            GovTalkMessageGovTalkDetailsChannelRouting channelRouting = new GovTalkMessageGovTalkDetailsChannelRouting();

            channelRouting.Channel = channel;
            GovTalkMessageGovTalkDetailsChannelRouting[] channelRoutings = new GovTalkMessageGovTalkDetailsChannelRouting[1];
            channelRoutings[0]            = channelRouting;
            govTalkDetails.Keys           = keys;
            govTalkDetails.ChannelRouting = channelRoutings;

            //Gov Talk Body
            GovTalkMessageBody body = new GovTalkMessageBody();
            //populate body content with ir68 data
            //IR68 ir68 = new IR68(periodData, vatData);         //commented out to use method instead of object instantiation with period/vat data
            //IRenvelope iRenvelope = ir68.CreateIREnvelopeBody(sender, business);

            IRenvelope iRenvelope = CreateIRenvelopeBody(sender, business, periodData, vatData);
            //serialse ir object data into xml elements and add to Gov Talk body
            //XElement xe = XElement.Parse(SerializeIrEnvelope(iRenvelope));
            XElement   xe       = XElement.Parse(IREnvelopeToXDocument(iRenvelope).ToString());
            XmlElement xelement = ToXmlElement(xe);

            XmlElement[] xmlElements = new XmlElement[1];
            xmlElements[0] = xelement;
            body.Any       = xmlElements;
            govTalkMessage.EnvelopeVersion = ConfigurationManager.AppSettings["GovTalkMessageEnvelopeVersion"];
            govTalkMessage.Header          = header;
            govTalkMessage.GovTalkDetails  = govTalkDetails;
            govTalkMessage.Body            = body;
            return(govTalkMessage);
        }