Esempio n. 1
0
 public MainService(IWebHostEnvironment appEnvironment)
 {
     this.appEnvironment = appEnvironment;
     telegramClient      = new TelegramBotClient("1669889973:AAFJ-s9KHXY2UASJFuCVeaRE3FxDzpsOBZ0");
     qiwiClient          = BillPaymentsClientFactory.Create(
         secretKey: "eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6ImRvb2c0aC0wMCIsInVzZXJfaWQiOiI3OTk2MDE4MTMyMiIsInNlY3JldCI6ImVjMjMwYjQ2Y2RmNWMwNGEyZGExMzg1MjY2MjFkYmExMmEyMGQyZTgzY2QyZTA4NThkMWY0OTAzMDM3NjRjNWEifX0="
         );
 }
Esempio n. 2
0
    // создаю форму о для покупки предмета
    private void CheckStatus()
    {
        pay = Convert.ToDecimal(payment);
        BillPaymentsClient client = BillPaymentsClientFactory.Create(
            secretKey: "eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6IjU5Z29icC0wMCIsInVzZXJfaWQiOiI3OTI3NDI1NTQ1MCIsInNlY3JldCI6ImZiZmM1YmQ4NDViYTU0YTlhNmZmYmNlMzQ4OTQ3Mzc3OTk0ZThiN2FhNDg5YjZjYTk0ODU1NjRkNzkxNTA1MjUifX0="
            );

        var form = client.CreateBill(
            info: new CreateBillInfo
        {
            BillId = Guid.NewGuid().ToString(),
            Amount = new MoneyAmount
            {
                ValueDecimal = pay,
                CurrencyEnum = CurrencyEnum.Rub
            },
            Comment            = textNameItem.text,
            ExpirationDateTime = DateTime.Now.AddDays(45),
            Customer           = new Customer
            {
                Email   = "*****@*****.**",
                Account = Guid.NewGuid().ToString(),
                Phone   = "792751287912"
            },
        }
            );

        print(form.PayUrl.ToString());
        Process.Start(form.PayUrl.ToString());
        //using (StreamWriter sw = new StreamWriter(Application.streamingAssetsPath + "/Report.txt", true, System.Text.Encoding.Default))
        //{
        //    sw.Write(textNameItem.text);
        //}

        string status = "";

        while (true)
        {
            var responseStatus = client.GetBillInfo(billId: form.BillId);
            if (responseStatus.Status.ValueString == "PAID")
            {
                //if (status == "PAID")
                //{
                // получаю путь к txt
                string path = Application.streamingAssetsPath + "/Report.txt";

                using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default))
                {
                    sw.Write(textNameItem.text);
                }
                //}
                status = form.Status.ValueString;
                break;
            }
        }
    }
Esempio n. 3
0
        public void TestAppendSuccessUrl(string successUrl)
        {
            // Prepare
            var baseBillResponse = new BillResponse
            {
                PayUrl = PayUri
            };
            // Test
            var billResponse = BillPaymentsClient.AppendSuccessUrl(baseBillResponse, new Uri(successUrl));
            var query        = HttpUtility.ParseQueryString(billResponse.PayUrl.Query);

            // Assert
            Assert.AreEqual(successUrl, query["successUrl"]);
        }
Esempio n. 4
0
        public string Pay(User user, Purchase purchase)
        {
            BillPaymentsClient client = BillPaymentsClientFactory.Create(secretKey: "eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6InNkbmNjaC0wMCIsInVzZXJfaWQiOiI3NzAxMzk4OTM5NiIsInNlY3JldCI6ImVjMDc5Y2RlNmYwNTMzZTMyNDM1MzFkMDQ0ZmJhNzM2NTc0ZWI2NWZkNDUzZmUzYWViNTFmMzUzNzI1MjNhNDQifX0=");


            BillResponse form = client.CreateBill(
                info: new CreateBillInfo
            {
                BillId = Guid.NewGuid().ToString(),
                Amount = new MoneyAmount
                {
                    ValueDecimal = 1.0m,
                    CurrencyEnum = CurrencyEnum.Kzt
                },
                Comment            = "Сумма счета",
                ExpirationDateTime = DateTime.Now.AddDays(2),
                Customer           = new Customer
                {
                    Email   = user.Email,
                    Account = Guid.NewGuid().ToString(),
                    Phone   = user.Phone
                },
            }
                );

            BillResponse responseStatus = client.GetBillInfo(billId: form.BillId);
            string       status         = responseStatus.Status.ValueString;

            Process myProcess = new Process();

            myProcess.StartInfo.UseShellExecute = true;
            myProcess.StartInfo.FileName        = responseStatus.PayUrl.AbsoluteUri;
            myProcess.Start();


            int timer      = 0;
            int timeForPay = 100000;
            int oneSecond  = 1000;

            while (true)
            {
                try
                {
                    responseStatus = client.GetBillInfo(billId: form.BillId);
                    status         = responseStatus.Status.ValueString;
                }
                catch
                {
                    status = Status.WAITING.ToString();
                }
                if (timer == timeForPay)
                {
                    status = Status.REJECTED.ToString();
                }
                Console.WriteLine(timer);
                Thread.Sleep(oneSecond * 5);
                timer += oneSecond * 5;
                if (status == Status.PAID.ToString())
                {
                    return(status);
                }
                else if (status == Status.REJECTED.ToString())
                {
                    client.CancelBill(billId: form.BillId);
                    return(status);
                }
            }
        }
Esempio n. 5
0
        public bool ToPay(decimal MoneyAmount)
        {
            //MoneyAmount заменяется на 1 тенге
            MoneyAmount = 1;

            //Секретный ключ отправителя счета
            const string ownerSecretKey       = "eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6InNkbmNjaC0wMCIsInVzZXJfaWQiOiI3NzAxMzk4OTM5NiIsInNlY3JldCI6ImVjMDc5Y2RlNmYwNTMzZTMyNDM1MzFkMDQ0ZmJhNzM2NTc0ZWI2NWZkNDUzZmUzYWViNTFmMzUzNzI1MjNhNDQifX0=";
            const int    second               = 1000; //Одна секунда равняется 1000 мл.секунд
            const int    updateTime           = 10;   //Время для обновления статуса оплаты
            const int    numberDaysForPayment = 5;    //Количество дней для оплаты счета
            string       currentStatus;               //Текущий статус оплаты
            int          numberLoops = 15;

            BillPaymentsClient qiwiClient = BillPaymentsClientFactory.Create(secretKey: ownerSecretKey);


            BillResponse qiwiResponse = qiwiClient.CreateBill(
                info: new CreateBillInfo
            {
                BillId = Guid.NewGuid().ToString(),
                Amount = new MoneyAmount
                {
                    ValueDecimal = MoneyAmount,
                    CurrencyEnum = CurrencyEnum.Kzt
                },
                ExpirationDateTime = DateTime.Now.AddDays(numberDaysForPayment),
            }
                );

            BillResponse response = qiwiClient.GetBillInfo(billId: qiwiResponse.BillId);

            //Открыть URL в браузере
            Process process = new Process();

            process.StartInfo.UseShellExecute = true;
            process.StartInfo.FileName        = response.PayUrl.AbsoluteUri;
            process.Start();


            int counter = new int();

            while (true)
            {
                if (counter == numberLoops)
                {
                    return(false);
                }

                try
                {
                    currentStatus = qiwiClient.GetBillInfo(billId: qiwiResponse.BillId).Status.ValueString;
                }
                catch
                {
                    currentStatus = "WAITING";
                }
                Thread.Sleep(second * updateTime);
                Console.Clear();

                switch (currentStatus)
                {
                case "PAID":
                    return(true);

                case "REJECTED":
                    return(false);

                case "WAITING":
                    continue;
                }

                counter++;
            }
        }