Пример #1
0
        private static async Task CanCreateRefundsCore(SeleniumTester s, TestAccount user, bool multiCurrency, string rateSelection)
        {
            s.GoToHome();
            s.Server.PayTester.ChangeRate("BTC_USD", new Rating.BidAsk(5000.0m, 5100.0m));
            var invoice = await user.BitPay.CreateInvoiceAsync(new NBitpayClient.Invoice()
            {
                Currency = "USD",
                Price    = 5000.0m
            });

            var info     = invoice.CryptoInfo.First(o => o.CryptoCode == "BTC");
            var totalDue = decimal.Parse(info.TotalDue, CultureInfo.InvariantCulture);
            var paid     = totalDue + 0.1m;
            await s.Server.ExplorerNode.SendToAddressAsync(BitcoinAddress.Create(info.Address, Network.RegTest), Money.Coins(paid));

            await s.Server.ExplorerNode.GenerateAsync(1);

            await TestUtils.EventuallyAsync(async() =>
            {
                invoice = await user.BitPay.GetInvoiceAsync(invoice.Id);
                Assert.Equal("confirmed", invoice.Status);
            });

            // BTC crash by 50%
            s.Server.PayTester.ChangeRate("BTC_USD", new Rating.BidAsk(5000.0m / 2.0m, 5100.0m / 2.0m));
            s.GoToInvoice(invoice.Id);
            s.Driver.FindElement(By.Id("refundlink")).Click();
            if (multiCurrency)
            {
                s.Driver.FindElement(By.Id("SelectedPaymentMethod")).SendKeys("BTC" + Keys.Enter);
                s.Driver.FindElement(By.Id("ok")).Click();
            }
            Assert.Contains("$5,500.00", s.Driver.PageSource);    // Should propose reimburse in fiat
            Assert.Contains("1.10000000 ₿", s.Driver.PageSource); // Should propose reimburse in BTC at the rate of before
            Assert.Contains("2.20000000 ₿", s.Driver.PageSource); // Should propose reimburse in BTC at the current rate
            s.Driver.FindElement(By.Id(rateSelection)).Click();
            s.Driver.FindElement(By.Id("ok")).Click();
            Assert.Contains("pull-payments", s.Driver.Url);
            if (rateSelection == "FiatText")
            {
                Assert.Contains("$5,500.00", s.Driver.PageSource);
            }
            if (rateSelection == "CurrentRateText")
            {
                Assert.Contains("2.20000000 ₿", s.Driver.PageSource);
            }
            if (rateSelection == "RateThenText")
            {
                Assert.Contains("1.10000000 ₿", s.Driver.PageSource);
            }
            s.GoToHome();
            s.GoToInvoices();
            s.GoToInvoice(invoice.Id);
            s.Driver.FindElement(By.Id("refundlink")).Click();
            Assert.Contains("pull-payments", s.Driver.Url);
        }
        void LogoutFlow(ServerTester tester, string clientId, SeleniumTester seleniumTester)
        {
            var logoutUrl = new Uri(tester.PayTester.ServerUri,
                                    $"connect/logout?response_type=token&client_id={clientId}");

            seleniumTester.Driver.Navigate().GoToUrl(logoutUrl);
            seleniumTester.GoToHome();
            Assert.Throws <NoSuchElementException>(() => seleniumTester.Driver.FindElement(By.Id("Logout")));
        }
Пример #3
0
        private static async Task CanCreateRefundsCore(SeleniumTester s, TestAccount user, bool multiCurrency, string rateSelection)
        {
            s.GoToHome();
            s.Server.PayTester.ChangeRate("BTC_USD", new Rating.BidAsk(5000.0m, 5100.0m));
            var invoice = await user.BitPay.CreateInvoiceAsync(new Invoice
            {
                Currency = "USD",
                Price    = 5000.0m
            });

            var info     = invoice.CryptoInfo.First(o => o.CryptoCode == "BTC");
            var totalDue = decimal.Parse(info.TotalDue, CultureInfo.InvariantCulture);
            var paid     = totalDue + 0.1m;
            await s.Server.ExplorerNode.SendToAddressAsync(BitcoinAddress.Create(info.Address, Network.RegTest), Money.Coins(paid));

            await s.Server.ExplorerNode.GenerateAsync(1);

            await TestUtils.EventuallyAsync(async() =>
            {
                invoice = await user.BitPay.GetInvoiceAsync(invoice.Id);
                Assert.Equal("confirmed", invoice.Status);
            });

            // BTC crash by 50%
            s.Server.PayTester.ChangeRate("BTC_USD", new Rating.BidAsk(5000.0m / 2.0m, 5100.0m / 2.0m));
            s.GoToStore();
            s.Driver.FindElement(By.Id("BOLT11Expiration")).Clear();
            s.Driver.FindElement(By.Id("BOLT11Expiration")).SendKeys("5" + Keys.Enter);
            s.GoToInvoice(invoice.Id);
            s.Driver.FindElement(By.Id("IssueRefund")).Click();

            if (multiCurrency)
            {
                s.Driver.WaitUntilAvailable(By.Id("RefundForm"), TimeSpan.FromSeconds(1));
                s.Driver.WaitUntilAvailable(By.Id("SelectedPaymentMethod"), TimeSpan.FromSeconds(1));
                s.Driver.FindElement(By.Id("SelectedPaymentMethod")).SendKeys("BTC" + Keys.Enter);
                s.Driver.FindElement(By.Id("ok")).Click();
            }

            s.Driver.WaitUntilAvailable(By.Id("RefundForm"), TimeSpan.FromSeconds(1));
            Assert.Contains("$5,500.00", s.Driver.PageSource);    // Should propose reimburse in fiat
            Assert.Contains("1.10000000 ₿", s.Driver.PageSource); // Should propose reimburse in BTC at the rate of before
            Assert.Contains("2.20000000 ₿", s.Driver.PageSource); // Should propose reimburse in BTC at the current rate
            s.Driver.WaitForAndClick(By.Id(rateSelection));
            s.Driver.FindElement(By.Id("ok")).Click();

            s.Driver.WaitUntilAvailable(By.Id("Destination"), TimeSpan.FromSeconds(1));
            Assert.Contains("pull-payments", s.Driver.Url);
            if (rateSelection == "FiatOption")
            {
                Assert.Contains("$5,500.00", s.Driver.PageSource);
            }
            if (rateSelection == "CurrentOption")
            {
                Assert.Contains("2.20000000 ₿", s.Driver.PageSource);
            }
            if (rateSelection == "RateThenOption")
            {
                Assert.Contains("1.10000000 ₿", s.Driver.PageSource);
            }

            s.GoToInvoice(invoice.Id);
            s.Driver.FindElement(By.Id("IssueRefund")).Click();
            s.Driver.WaitUntilAvailable(By.Id("Destination"), TimeSpan.FromSeconds(1));
            Assert.Contains("pull-payments", s.Driver.Url);
            var client = await user.CreateClient();

            var ppid = s.Driver.Url.Split('/').Last();
            var pps  = await client.GetPullPayments(user.StoreId);

            var pp = Assert.Single(pps, p => p.Id == ppid);

            Assert.Equal(TimeSpan.FromDays(5.0), pp.BOLT11Expiration);
        }