Exemplo n.º 1
0
        public void ParsePkpTest()
        {
            var pkpString = @"AA==";
            var pkpBytes  = Convert.FromBase64String(pkpString);

            Assert.IsTrue(pkpBytes.SequenceEqual(EetRegisterRequest.ParsePkp(pkpString)));
        }
Exemplo n.º 2
0
        public void FormatPkpTest()
        {
            var pkpString = @"AA==";
            var pkpBytes  = Convert.FromBase64String(pkpString);

            Assert.AreEqual(pkpString, EetRegisterRequest.FormatPkp(pkpBytes));
        }
Exemplo n.º 3
0
        public static void simpleRegistrationProcessTest()
        {
            EetRegisterRequest request = EetRegisterRequest.builder()
                                         .dic_popl("CZ1212121218")
                                         .id_provoz("1")
                                         .id_pokl("POKLADNA01")
                                         .porad_cis("1")
                                         .dat_trzby("2016-06-30T08:43:28+02:00")
                                         .celk_trzba(100.0)
                                         .rezim(0)
                                         .pkcs12(TestData.EET_CA1_Playground_CZ1212121218)
                                         .pkcs12password("eet")
                                         .dumpDataPath(".")
                                         .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 = request.sendRequest(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");

            //extract FIK
            if (response == null)
            {
                throw new ApplicationException("response is null");
            }
            if (response.IndexOf("Potvrzeni fik=") < 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
        }
Exemplo n.º 4
0
        /*
         *  <Data dic_popl="CZ1212121218" id_provoz="1" id_pokl="POKLADNA01" porad_cis="1" dat_trzby="2016-06-30T08:43:28+02:00" celk_trzba="100.00" rezim="0"/>
         *  <pkp cipher="RSA2048" digest="SHA256" encoding="base64">Ddk2WTYu8nzpQscH7t9n8cBsGq4k/ggCwdfkPjM+gHUHPL8P7qmnWofzeW2pAekSSmOClBjF141yN+683g0aXh6VvxY4frBjYhy4XB506LDykIW0oAv086VH7mR0utA8zGd7mCI55p3qv1M/oog/2yG0DefD5mtHIiBG7/n7jgWbROTatJPQYeQWEXEoOJh9/gAq2kuiK3TOYeGeHwOyFjM2Cy3UVal8E3LwafP49kmGOWjHG+cco0CRXxOD3b8y4mgBqTwwC4V8e85917e5sVsaEf3t0hwPkag+WM1LIRzW+QwkkgiMEwoIqCAkhoF1eq/VcsML2ZcrLGejAeAixw==</pkp>
         *  <bkp digest="SHA1" encoding="base16">AC502107-1781EEE4-ECFD152F-2ED08CBA-E6226199</bkp>
         */
        public static void signAndSend()
        {
            EetRegisterRequest data = EetRegisterRequest.builder()
                                      .dic_popl("CZ1212121218")
                                      .id_provoz("1")
                                      .id_pokl("POKLADNA01")
                                      .porad_cis("1")
                                      .dat_trzby("2016-06-30T08:43:28+02:00")
                                      .celk_trzba(100.0)
                                      .pkcs12(TestData._01000003)
                                      .pkcs12password("eet")
                                      .rezim(0)
                                      .build();

            if (data == null)
            {
                throw new Exception("failed - data null");
            }
            Console.WriteLine("business data created");

            String pkp         = EetRegisterRequest.formatPkp(data.pkp);
            String bkp         = EetRegisterRequest.formatBkp(data.bkp);
            String expectedPkp = "Ddk2WTYu8nzpQscH7t9n8cBsGq4k/ggCwdfkPjM+gHUHPL8P7qmnWofzeW2pAekSSmOClBjF141yN+683g0aXh6VvxY4frBjYhy4XB506LDykIW0oAv086VH7mR0utA8zGd7mCI55p3qv1M/oog/2yG0DefD5mtHIiBG7/n7jgWbROTatJPQYeQWEXEoOJh9/gAq2kuiK3TOYeGeHwOyFjM2Cy3UVal8E3LwafP49kmGOWjHG+cco0CRXxOD3b8y4mgBqTwwC4V8e85917e5sVsaEf3t0hwPkag+WM1LIRzW+QwkkgiMEwoIqCAkhoF1eq/VcsML2ZcrLGejAeAixw==";
            String expectedBkp = "AC502107-1781EEE4-ECFD152F-2ED08CBA-E6226199";

            if (!pkp.Equals(expectedPkp))
            {
                throw new Exception("failed - PKP differs");
            }
            if (!bkp.Equals(expectedBkp))
            {
                throw new Exception("failed - BKP differs");
            }
            Console.WriteLine("Codes validated");

            String signed = data.generateSoapRequest();

            Console.WriteLine("SOAP request created");

            //assertTrue(validateXmlDSig(signed, data.getCertificate()));
            String response = data.sendRequest(signed, "https://pg.eet.cz:443/eet/services/EETServiceSOAP/v2");

            //via local stunnel
            //String response=data.sendRequest(signed, "http://127.0.0.1:27541/eet/services/EETServiceSOAP/v2");

            if (response.IndexOf("Potvrzeni fik=") < 0)
            {
                throw new ApplicationException("FIK not found in the response");
            }
            Console.WriteLine("FIK received:" + response.Substring(response.IndexOf("Potvrzeni fik=") + 15, 36));
        }
Exemplo n.º 5
0
        public static async Task SignAndSend()
        {
            EetRegisterRequest data = new EetRequestBuilder()
                                      .SetDicPopl("CZ1212121218")
                                      .SetIdProvoz("1")
                                      .SetIdPokl("POKLADNA01")
                                      .SetPoradCis("1")
                                      .SetDatTrzby(DateTime.Now)
                                      .SetCelkTrzba(100.0)
                                      .SetPkcs12(TestData.EET_CA1_Playground_CZ1212121218)
                                      .SetPkcs12Password("eet")
                                      .SetRezim(0)
                                      .Build();

            if (data == null)
            {
                throw new Exception("Failed - data null");
            }
            Console.WriteLine(@"Business data created");

            string pkp         = EetRegisterRequest.FormatPkp(data.Pkp);
            string bkp         = EetRegisterRequest.FormatBkp(data.Bkp);
            string expectedPkp = "Ddk2WTYu8nzpQscH7t9n8cBsGq4k/ggCwdfkPjM+gHUHPL8P7qmnWofzeW2pAekSSmOClBjF141yN+683g0aXh6VvxY4frBjYhy4XB506LDykIW0oAv086VH7mR0utA8zGd7mCI55p3qv1M/oog/2yG0DefD5mtHIiBG7/n7jgWbROTatJPQYeQWEXEoOJh9/gAq2kuiK3TOYeGeHwOyFjM2Cy3UVal8E3LwafP49kmGOWjHG+cco0CRXxOD3b8y4mgBqTwwC4V8e85917e5sVsaEf3t0hwPkag+WM1LIRzW+QwkkgiMEwoIqCAkhoF1eq/VcsML2ZcrLGejAeAixw==";
            string expectedBkp = "AC502107-1781EEE4-ECFD152F-2ED08CBA-E6226199";

            if (!pkp.Equals(expectedPkp))
            {
                throw new Exception("Failed - PKP differs");
            }
            if (!bkp.Equals(expectedBkp))
            {
                throw new Exception("Failed - BKP differs");
            }
            Console.WriteLine(@"Codes validated");

            string signed = data.GenerateSoapRequest();

            Console.WriteLine(@"SOAP request created");

            string response = await data.SendRequestAsync(signed, "https://pg.eet.cz:443/eet/services/EETServiceSOAP/v3");

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

            if (response.IndexOf("Potvrzeni fik=", StringComparison.Ordinal) < 0)
            {
                throw new ApplicationException("FIK not found in the response");
            }
            Console.WriteLine(@"FIK received:" + response.Substring(response.IndexOf("Potvrzeni fik=", StringComparison.Ordinal) + 15, 36));
        }
Exemplo n.º 6
0
 public void ParseBkpFail1Test()
 {
     EetRegisterRequest.ParseBkp("FBB4FC51-4C82C7E4-F080FD88-54C9DCB2");
 }
Exemplo n.º 7
0
        public void ParseBkpTest()
        {
            var bkp = EetRegisterRequest.ParseBkp("FBB4FC51-4C82C7E4-F080FD88-54C9DCB2-F26443E7");

            Assert.IsTrue(bkp.SequenceEqual(new byte[] { 251, 180, 252, 81, 76, 130, 199, 228, 240, 128, 253, 136, 84, 201, 220, 178, 242, 100, 67, 231 }));
        }
Exemplo n.º 8
0
        public void FormatBkpTest()
        {
            var bkp = EetRegisterRequest.FormatBkp(new byte[] { 251, 180, 252, 81, 76, 130, 199, 228, 240, 128, 253, 136, 84, 201, 220, 178, 242, 100, 67, 231 });

            Assert.AreEqual(bkp, "FBB4FC51-4C82C7E4-F080FD88-54C9DCB2-F26443E7");
        }
Exemplo n.º 9
0
 public void BuilderTest()
 {
     Assert.IsNotNull(EetRegisterRequest.Builder());
 }
Exemplo n.º 10
0
 public void RemoveUnusedPlaceholdersTest()
 {
     Assert.AreEqual(EetRegisterRequest.RemoveUnusedPlaceholders(" <Data celk_trzba=\"100.00\" cerp_zuct=\"${cerp_zuct}\">"), " <Data celk_trzba=\"100.00\">");
 }
Exemplo n.º 11
0
 public void FormatAmountTest()
 {
     Assert.AreEqual(EetRegisterRequest.FormatAmount(5.0), "5.00");
 }
Exemplo n.º 12
0
 public void ParseBkpFail2Test()
 {
     EetRegisterRequest.ParseBkp("FBB4XXXX-4C82C7E4-F080FD88-54C9DCB2-F26443E7");
 }