Exemplo n.º 1
0
        public async Task <ActionResult> Index2()
        {
            var _merchantPFXForTest            = System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/1231181189.p12"));
            var _merchantCertificateDataInPEM  = System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/prod.pem"));
            var _merchantCertificateDataInPEM2 = System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/prod2.pem"));
            var _merchantPrivateKey            = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/private.key"));
            var _merchantCertificatePassword   = "";
            var _merchantId = "test";

            bool test1, test2 = false, test3;

            var bytes = CertificateGenerator.GenerateP12(_merchantPrivateKey, _merchantCertificateDataInPEM, "");

            var client = new SwishClient(SwishEnvironment.Production,
                                         P12CertificateCollectionBytes: bytes,
                                         P12CertificateCollectionPassphrase: _merchantCertificatePassword,
                                         merchantId: _merchantId);

            var paymentStatus = await client.GetPaymentStatus("anything");

            test1 = true;


            var bytes2  = CertificateGenerator.GenerateP12(_merchantPrivateKey, _merchantCertificateDataInPEM2, "");
            var client2 = new SwishClient(SwishEnvironment.Production,
                                          P12CertificateCollectionBytes: bytes2,
                                          P12CertificateCollectionPassphrase: "swish",
                                          merchantId: _merchantId);

            try
            {
                var paymentStatus2 = await client2.GetPaymentStatus("anything");
            }
            catch (Exception ex)
            {
                test2 = true;
            }

            var paymentStatus3 = await client.GetPaymentStatus("anything");

            var client4 = new SwishClient(SwishEnvironment.Production,
                                          P12CertificateCollectionBytes: bytes,
                                          P12CertificateCollectionPassphrase: _merchantCertificatePassword,
                                          merchantId: _merchantId);

            var paymentStatus4 = await client.GetPaymentStatus("anything");

            test3 = true;

            return(test1 && test2 && test3?View() : View("Error"));
        }
        public async Task CertificateAcceptedTest23()
        {
            var bytes = CertificateGenerator.GenerateP12(_merchantPrivateKey, _merchantCertificateDataInPEM, "");

            var client = new SwishClient(SwishEnvironment.Production,
                P12CertificateCollectionBytes: bytes,
                P12CertificateCollectionPassphrase: "",
                merchantId: "123");

            var paymentStatus = await client.GetPaymentStatus("test");

            var client2 = new SwishClient(SwishEnvironment.Production,
                P12CertificateCollectionBytes: bytes,
                P12CertificateCollectionPassphrase: "",
                merchantId: "123");

            var paymentStatus2 = await client2.GetPaymentStatus("test");
        }
        public async Task CertificateAcceptedTest2()
        {
            var bytes = CertificateGenerator.GenerateP12(_merchantPrivateKey, _merchantCertificateDataInPEM, "");

            var client = new SwishClient(SwishEnvironment.Production,
                P12CertificateCollectionBytes: bytes,
                P12CertificateCollectionPassphrase: _merchantCertificatePassword,
                merchantId: _merchantId);

            var paymentStatus = await client.GetPaymentStatus("anything");

            // should be "not found" in the error message, which states that connection is established but obviously transaction was not found
            Assert.NotNull(paymentStatus.ErrorMessage);

            // now test misconfigured client (should throw exception)
            var clientWithWrongPfx = new SwishClient(SwishEnvironment.Production,
                P12CertificateCollectionBytes: _merchantPFXForTest,
                P12CertificateCollectionPassphrase: "swish",
                merchantId: _merchantId);

            try
            {
                var _ = await clientWithWrongPfx.GetPaymentStatus("anything");
            }
            catch (Exception ex)
            {

            }

            // now create working client to check if any of the certificates sticked from last one
            var client2 = new SwishClient(SwishEnvironment.Production,
                P12CertificateCollectionBytes: bytes,
                P12CertificateCollectionPassphrase: _merchantCertificatePassword,
                merchantId: _merchantId);

            var paymentStatus2 = await client.GetPaymentStatus("anything");

            // should be "not found" in the error message, which states that connection is established but obviously transaction was not found
            Assert.NotNull(paymentStatus.ErrorMessage);
        }