예제 #1
0
파일: Program.cs 프로젝트: lekiscz/openeet
        public static async Task SimpleRegistrationProcessTest()
        {
            // moznost pouziti
            //EetRegisterRequest request = EetRegisterRequest.Builder()
            //   .SetDicPopl("CZ1212121218")
            //   .SetIdProvoz("1")
            //   .SetIdPokl("POKLADNA01")
            //   .SetPoradCis("1")
            //   .SetDatTrzby("2016-09-12T08:43:28+02:00")
            //   .SetCelkTrzba(100.0)
            //   .SetRezim(0)
            //   .SetPkcs12(TestData.EET_CA1_Playground_CZ1212121218)
            //   .SetPkcs12Password("eet")
            //   .Build();

            /* certifikat jako pole byte + heslo
             * EetRegisterRequest request = new EetRequestBuilder()
             * {
             *  DicPopl = "CZ1212121218",
             *  IdProvoz = "1",
             *  IdPokl = "POKLADNA01",
             *  PoradCis = "1",
             *  DatTrzby = DateTime.Now,
             *  CelkTrzba = 100.0,
             *  Rezim = 0,
             *  Pkcs12 = TestData.EET_CA1_Playground_CZ1212121218,
             *  Pkcs12Password = "******"
             * }.Build();
             *
             */

            // certifikat jako X509Certificate2
            //var cert = new X509Certificate2("data\\EET_CA1_Playground-CZ683555118.pfx", "eet");

            // certifikat jako X509Certificate2
            var cert = new X509Certificate2("data\\EET_CA1_Playground-CZ1212121218.p12", "eet", X509KeyStorageFlags.Exportable);

            var request = new EetRequestBuilder()
            {
                DicPopl     = "CZ1212121218",
                IdProvoz    = "1",
                IdPokl      = "POKLADNA01",
                PoradCis    = "1",
                DatTrzby    = DateTime.Now,
                CelkTrzba   = 100.0,
                Rezim       = 0,
                Certificate = cert
            }.Build();


            // for receipt printing in online mode
            string bkp = request.FormatBkp();

            if (bkp == null)
            {
                throw new ApplicationException("BKP is null");
            }

            // for receipt printing in offline mode
            string pkp = request.FormatPkp();

            if (pkp == null)
            {
                throw new ApplicationException("PKP is null");
            }

            // the receipt can be now stored for offline processing

            // try send
            string requestBody = request.GenerateSoapRequest();

            if (requestBody == null)
            {
                throw new ApplicationException("SOAP request is null");
            }
            string response = await request.SendRequestAsync(requestBody, "https://pg.eet.cz:443/eet/services/EETServiceSOAP/v3");

            // via local stunnel
            //string response = request.SendRequest(requestBody, "http://127.0.0.1:27541/eet/services/EETServiceSOAP/v3");

            // TODO: zde by to chtelo dodelat kontrolu jestli prijata zprava nebyla zmenena, jestli souhlasi podpis zpravy, mauzete to nekdo doplnit?

            // extract FIK
            if (response == null)
            {
                throw new ApplicationException("response is null");
            }
            if (response.IndexOf("Potvrzeni fik=", StringComparison.Ordinal) < 0)
            {
                throw new ApplicationException("FIK not found in the response");
            }

            // ready to print online receipt
            Console.WriteLine($"OK, Response: {response}!");
        }
예제 #2
0
        public static async Task SimpleRegistrationProcessTest()
        {
            // moznost pouziti

            /*EetRegisterRequest request = EetRegisterRequest.Builder()
             * .SetDicPopl("CZ1212121218")
             * .SetIdProvoz("1")
             * .SetIdPokl("POKLADNA01")
             * .SetPoradCis("1")
             * .SetDatTrzbys("2016-09-12T08:43:28+02:00")
             * .SetCelkTrzba(100.0)
             * .SetRezim(0)
             * .SetPkcs12(TestData._01000003)
             * .SetPkcs12Password("eet")
             * .Build();*/


            EetRegisterRequest request = new EetRequestBuilder()
            {
                DicPopl        = "CZ1212121218",
                IdProvoz       = "1",
                IdPokl         = "POKLADNA01",
                PoradCis       = "1",
                DatTrzby       = DateTime.Now,
                CelkTrzba      = 100.0,
                Rezim          = 0,
                Pkcs12         = TestData._01000003,
                Pkcs12Password = "******"
            }.Build();

            //for receipt printing in online mode
            string bkp = request.FormatBkp();

            if (bkp == null)
            {
                throw new ApplicationException("BKP is null");
            }

            //for receipt printing in offline mode
            string pkp = request.FormatPkp();

            if (pkp == null)
            {
                throw new ApplicationException("PKP is null");
            }
            //the receipt can be now stored for offline processing

            //try send
            string requestBody = request.GenerateSoapRequest();

            if (requestBody == null)
            {
                throw new ApplicationException("SOAP request is null");
            }
            string response = await request.SendRequestAsync(requestBody, "https://pg.eet.cz:443/eet/services/EETServiceSOAP/v3");

            //via local stunnel
            //string  response = request.SendRequest(requestBody, "http://127.0.0.1:27541/eet/services/EETServiceSOAP/v2");

            // TODO
            //zde by to chtelo dodelat kontrolu jestli prijata zprava nebyla zmenena, jestli souhlasi podpis zpravy
            //mauzete to nekdo doplnit ?


            //extract FIK
            if (response == null)
            {
                throw new ApplicationException("response is null");
            }
            if (response.IndexOf("Potvrzeni fik=", StringComparison.Ordinal) < 0)
            {
                throw new ApplicationException("FIK not found in the response");
            }
            //ready to print online receipt
            Console.WriteLine(@"OK!"); //a bit brief :-) but enough
                                       //set minimal business data & certificate with key loaded from pkcs12 file
        }
예제 #3
0
        public void BuildTest()
        {
            EetRegisterRequest request = new EetRequestBuilder()
            {
                DicPopl         = "CZ1212121218",
                IdProvoz        = "1",
                IdPokl          = "POKLADNA01",
                PoradCis        = "1",
                DatTrzby        = DateTime.Now,
                CelkTrzba       = 100.0,
                Rezim           = RezimEnum.Standardni,
                Pkcs12          = TestData._01000003,
                Pkcs12Password  = "******",
                CerpZuct        = 1,
                CestSluz        = 2,
                Dan1            = 3,
                Dan2            = 4,
                Dan3            = 5,
                DatOdesl        = DateTime.Now,
                DicPoverujiciho = "CZ1212121219",
                Overeni         = OvereniEnum.Overovaci,
                PouzitZboz1     = 6,
                PouzitZboz2     = 7,
                PouzitZboz3     = 8,
                PrvniZaslani    = PrvniZaslaniEnum.Opakovane,
                UrcenoCerpZuct  = 9,
                ZaklDan1        = 10,
                ZaklDan2        = 11,
                ZaklDan3        = 12,
                ZaklNepodlDph   = 13
            }.Build();

            Assert.IsNotNull(request.Certificate);

            new EetRequestBuilder()
            {
                DicPopl         = "CZ1212121218",
                IdProvoz        = "1",
                IdPokl          = "POKLADNA01",
                PoradCis        = "1",
                DatTrzby        = DateTime.Now,
                CelkTrzba       = 100.0,
                Rezim           = RezimEnum.Standardni,
                Pkcs12          = TestData._01000003,
                CerpZuct        = 1,
                CestSluz        = 2,
                Dan1            = 3,
                Dan2            = 4,
                Dan3            = 5,
                DatOdesl        = DateTime.Now,
                DicPoverujiciho = "CZ1212121219",
                Overeni         = OvereniEnum.Overovaci,
                PouzitZboz1     = 6,
                PouzitZboz2     = 7,
                PouzitZboz3     = 8,
                PrvniZaslani    = PrvniZaslaniEnum.Opakovane,
                UrcenoCerpZuct  = 9,
                ZaklDan1        = 10,
                ZaklDan2        = 11,
                ZaklDan3        = 12,
                ZaklNepodlDph   = 13
            }.Build();
        }
예제 #4
0
        public void SetMethodsTests()
        {
            var dt = DateTime.Now;

            dt = dt.AddTicks(-(dt.Ticks % TimeSpan.TicksPerSecond)); // remove millisecons
            var guid        = Guid.NewGuid();
            var bytes       = new byte[] { 23, 121, 97, 40, 174, 210, 187, 158, 35, 1, 255, 151, 10, 117, 101, 106, 223, 43, 1, 29 };
            var bytesString = "17796128-AED2BB9E-2301FF97-0A75656A-DF2B011D";
            var pkpString   = @"AA==";
            var pkpBytes    = Convert.FromBase64String(pkpString);

            EetRequestBuilder builder = new EetRequestBuilder();

            Assert.IsNull(builder.Certificate);
            Assert.AreSame(builder, builder.SetCertificate(new X509Certificate2()));
            Assert.IsNotNull(builder.Certificate);

            Assert.IsNull(builder.Key);
            Assert.AreSame(builder, builder.SetKey(new RSACryptoServiceProvider()));
            Assert.IsNotNull(builder.Key);

            Assert.AreSame(builder, builder.SetDatOdesl(dt));
            Assert.AreEqual(builder.DatOdesl, dt);
            builder.SetDatOdesl(default(DateTime));
            Assert.AreSame(builder, builder.SetDatOdesl(dt.ToString("yyyy-MM-dd'T'HH:mm:sszzz")));
            Assert.AreEqual(builder.DatOdesl, dt);

            Assert.AreEqual(builder.PrvniZaslani, PrvniZaslaniEnum.Prvni);      // Default value
            Assert.AreSame(builder, builder.SetPrvniZaslani(PrvniZaslaniEnum.Opakovane));
            Assert.AreEqual(builder.PrvniZaslani, PrvniZaslaniEnum.Opakovane);
            Assert.AreSame(builder, builder.SetPrvniZaslani(true));
            Assert.AreEqual(builder.PrvniZaslani, PrvniZaslaniEnum.Prvni);

            Assert.AreSame(builder, builder.SetUuidZpravy(guid));
            Assert.AreEqual(builder.UuidZpravy, guid);

            Assert.AreSame(builder, builder.SetUuidZpravy(guid.ToString()));
            Assert.AreEqual(builder.UuidZpravy, guid);

            Assert.AreEqual(builder.Overeni, OvereniEnum.Produkcni);            // Default value
            Assert.AreSame(builder, builder.SetOvereni(OvereniEnum.Overovaci));
            Assert.AreEqual(builder.Overeni, OvereniEnum.Overovaci);
            Assert.AreSame(builder, builder.SetOvereni(false));
            Assert.AreEqual(builder.Overeni, OvereniEnum.Produkcni);

            Assert.AreSame(builder, builder.SetDicPopl("dicPopl"));
            Assert.AreEqual(builder.DicPopl, "dicPopl");

            Assert.AreSame(builder, builder.SetDicPoverujiciho("dicPover"));
            Assert.AreEqual(builder.DicPoverujiciho, "dicPover");

            Assert.AreSame(builder, builder.SetIdProvoz("idProvoz"));
            Assert.AreEqual(builder.IdProvoz, "idProvoz");

            Assert.AreSame(builder, builder.SetIdPokl("idPokl"));
            Assert.AreEqual(builder.IdPokl, "idPokl");

            Assert.AreSame(builder, builder.SetPoradCis("poradCisl"));
            Assert.AreEqual(builder.PoradCis, "poradCisl");

            Assert.AreSame(builder, builder.SetDatTrzby(dt));
            Assert.AreEqual(builder.DatTrzby, dt);
            builder.SetDatOdesl(default(DateTime));
            Assert.AreSame(builder, builder.SetDatTrzby(dt.ToString("yyyy-MM-dd'T'HH:mm:sszzz")));
            Assert.AreEqual(builder.DatTrzby, dt);

            Assert.AreSame(builder, builder.SetCelkTrzba(5.0));
            Assert.AreEqual(builder.CelkTrzba, 5.0);
            Assert.AreSame(builder, builder.SetCelkTrzba("1,0"));
            Assert.AreEqual(builder.CelkTrzba, 1.0);

            Assert.AreSame(builder, builder.SetZaklNepodlDph(5.0));
            Assert.AreEqual(builder.ZaklNepodlDph, 5.0);
            Assert.AreSame(builder, builder.SetZaklNepodlDph("1,0"));
            Assert.AreEqual(builder.ZaklNepodlDph, 1.0);

            Assert.AreSame(builder, builder.SetZaklDan1(5.0));
            Assert.AreEqual(builder.ZaklDan1, 5.0);
            Assert.AreSame(builder, builder.SetZaklDan1("1,0"));
            Assert.AreEqual(builder.ZaklDan1, 1.0);

            Assert.AreSame(builder, builder.SetDan1(5.0));
            Assert.AreEqual(builder.Dan1, 5.0);
            Assert.AreSame(builder, builder.SetDan1("1,0"));
            Assert.AreEqual(builder.Dan1, 1.0);

            Assert.AreSame(builder, builder.SetZaklDan2(5.0));
            Assert.AreEqual(builder.ZaklDan2, 5.0);
            Assert.AreSame(builder, builder.SetZaklDan2("1,0"));
            Assert.AreEqual(builder.ZaklDan2, 1.0);

            Assert.AreSame(builder, builder.SetDan2(5.0));
            Assert.AreEqual(builder.Dan2, 5.0);
            Assert.AreSame(builder, builder.SetDan2("1,0"));
            Assert.AreEqual(builder.Dan2, 1.0);

            Assert.AreSame(builder, builder.SetZaklDan2(5.0));
            Assert.AreEqual(builder.ZaklDan2, 5.0);
            Assert.AreSame(builder, builder.SetZaklDan2("1,0"));
            Assert.AreEqual(builder.ZaklDan2, 1.0);

            Assert.AreSame(builder, builder.SetDan3(5.0));
            Assert.AreEqual(builder.Dan3, 5.0);
            Assert.AreSame(builder, builder.SetDan3("1,0"));
            Assert.AreEqual(builder.Dan3, 1.0);

            Assert.AreSame(builder, builder.SetCestSluz(5.0));
            Assert.AreEqual(builder.CestSluz, 5.0);
            Assert.AreSame(builder, builder.SetCestSluz("1,0"));
            Assert.AreEqual(builder.CestSluz, 1.0);

            Assert.AreSame(builder, builder.SetPouzitZboz1(5.0));
            Assert.AreEqual(builder.PouzitZboz1, 5.0);
            Assert.AreSame(builder, builder.SetPouzitZboz1("1,0"));
            Assert.AreEqual(builder.PouzitZboz1, 1.0);

            Assert.AreSame(builder, builder.SetPouzitZboz2(5.0));
            Assert.AreEqual(builder.PouzitZboz2, 5.0);
            Assert.AreSame(builder, builder.SetPouzitZboz2("1,0"));
            Assert.AreEqual(builder.PouzitZboz2, 1.0);

            Assert.AreSame(builder, builder.SetPouzitZboz3(5.0));
            Assert.AreEqual(builder.PouzitZboz3, 5.0);
            Assert.AreSame(builder, builder.SetPouzitZboz3("1,0"));
            Assert.AreEqual(builder.PouzitZboz3, 1.0);

            Assert.AreSame(builder, builder.SetUrcenoCerpZuct(5.0));
            Assert.AreEqual(builder.UrcenoCerpZuct, 5.0);
            Assert.AreSame(builder, builder.SetUrcenoCerpZuct("1,0"));
            Assert.AreEqual(builder.UrcenoCerpZuct, 1.0);

            Assert.AreSame(builder, builder.SetCerpZuct(5.0));
            Assert.AreEqual(builder.CerpZuct, 5.0);
            Assert.AreSame(builder, builder.SetCerpZuct("1,0"));
            Assert.AreEqual(builder.CerpZuct, 1.0);

            Assert.AreEqual(builder.Rezim, RezimEnum.Standardni);       // Default value
            Assert.AreSame(builder, builder.SetRezim(RezimEnum.Zjednoduseny));
            Assert.AreEqual(builder.Rezim, RezimEnum.Zjednoduseny);
            Assert.AreSame(builder, builder.SetRezim("0"));
            Assert.AreEqual(builder.Rezim, RezimEnum.Standardni);

            Assert.AreSame(builder, builder.SetBkp(bytes));
            Assert.IsTrue(builder.Bkp.SequenceEqual(bytes));
            Assert.AreSame(builder, builder.SetBkp("00000000-00000000-00000000-00000000-00000000"));
            Assert.AreSame(builder, builder.SetBkp(bytesString));
            Assert.IsTrue(builder.Bkp.SequenceEqual(bytes));

            Assert.AreSame(builder, builder.SetPkp(bytes));
            Assert.IsTrue(builder.Pkp.SequenceEqual(bytes));
            Assert.AreSame(builder, builder.SetPkp("BB=="));
            Assert.AreSame(builder, builder.SetPkp(pkpString));
            Assert.IsTrue(builder.Pkp.SequenceEqual(pkpBytes));

            Assert.AreSame(builder, builder.SetPkcs12("SomeText.txt"));
            Assert.IsTrue(builder.Pkcs12.SequenceEqual(new byte[] { 239, 187, 191, 48 }));
            Assert.AreSame(builder, builder.SetPkcs12(bytes));
            Assert.IsTrue(builder.Pkcs12.SequenceEqual(bytes));

            Assert.AreSame(builder, builder.SetPkcs12Password(pkpString));
            Assert.AreEqual(builder.Pkcs12Password, pkpString);
        }
예제 #5
0
        public void InvalidIntRezimTests()
        {
            var builder = new EetRequestBuilder();

            builder.SetRezim(2);
        }