public async Task <bool> UpdatePayments(string[] idAcc) { var client = new MongoClient("mongodb://localhost"); var database = client.GetDatabase("GamesAcc"); var paymentUpdate = database.GetCollection <PaymentsModel>("Payments"); var localInfoUserBill = BDwithPay.UserBillId; int i = 0; string Status = "WAIT"; // можно любой текст while (Status != "PAID") { Status = clientQiwi.GetBillInfo(localInfoUserBill).Status.ValueString; i++; if (i == 600) { paymentUpdate.UpdateOne(p => p.BillId == BDwithPay.UserBillId, Builders <PaymentsModel> .Update.Set(p => p.Status, "CANCEL")); clientQiwi.CancelBill(billId: localInfoUserBill); return(false); } var taskdealy = Task.Delay(1000); await taskdealy; } paymentUpdate.UpdateOne(p => p.BillId == BDwithPay.UserBillId, Builders <PaymentsModel> .Update.Set(p => p.Status, Status)); return(true); }
// создаю форму о для покупки предмета 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; } } }
public static bool CheckPay(User user, string billId) { try { using DB db = new DB(); var response = client.GetBillInfo(billId); if (response.Status.ValueEnum == BillStatusEnum.Paid) { user.IsDonate = true; db.Update(user); db.SaveChanges(); return(true); } return(false); } catch { return(false); } }
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); } } }
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++; } }