private static void ClassInitialize_Api() { _testContext.Properties.Add( "apiDataRows", new Dictionary <BillPaymentsClient, ApiPresets> { { BillPaymentsClientFactory.Create(Config.MerchantSecretKey), new ApiPresets { Bills = new List <BillResponse>(), Refunds = new List <RefundResponse>() } }, { BillPaymentsClientFactory.Create( Config.MerchantSecretKey, null, ObjectMapperFactory.Create <NewtonsoftMapper>() ), new ApiPresets { Bills = new List <BillResponse>(), Refunds = new List <RefundResponse>() } } } ); }
public MainService(IWebHostEnvironment appEnvironment) { this.appEnvironment = appEnvironment; telegramClient = new TelegramBotClient("1669889973:AAFJ-s9KHXY2UASJFuCVeaRE3FxDzpsOBZ0"); qiwiClient = BillPaymentsClientFactory.Create( secretKey: "eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6ImRvb2c0aC0wMCIsInVzZXJfaWQiOiI3OTk2MDE4MTMyMiIsInNlY3JldCI6ImVjMjMwYjQ2Y2RmNWMwNGEyZGExMzg1MjY2MjFkYmExMmEyMGQyZTgzY2QyZTA4NThkMWY0OTAzMDM3NjRjNWEifX0=" ); }
public bool Purchase(decimal price) { try { var client = BillPaymentsClientFactory.Create( secretKey: "eyJ2ZXJzaW9uIjoiUDJQIiwiZGF0YSI6eyJwYXlpbl9tZXJjaGFudF9zaXRlX3VpZCI6InJpMmQ3ai0wMCIsInVzZXJfaWQiOiI3NzcxODM2NTkxOCIsInNlY3JldCI6IjQ2MzhkNjg4ODEzZTY1MjkwNWQ4YjMxNzI1N2I5ODUyNWI0NjE2ODAxMTE3NzYwMzQ1YmI1MWE3M2U2OWFmOWUifX0=" ); var invoice = client.CreateBill( info: new CreateBillInfo { BillId = RandomCodeGenerationService.Generate(10), Amount = new MoneyAmount { //Это тестовое значение суммы, для тестового режима ValueDecimal = 1m, CurrencyEnum = CurrencyEnum.Rub }, Comment = $"Вам выставлен счет на сумму {price} рублей. С уважением, Онлайн-Магазин Meloman", ExpirationDateTime = DateTime.Now.AddHours(3) } ); //Открываю форму оплаты в браузере по умолчанию (Я чет не могу затестить, т.к. на свой кошелек невозможно переводить. //Там было написано, что установите значение в 1 рубль для тестов. Можем вместе протестить это позже var invoiceURL = invoice.PayUrl.AbsoluteUri; invoiceURL = invoiceURL.Replace("&", "^&"); Process.Start(new ProcessStartInfo("cmd", $"/c start {invoiceURL}") { CreateNoWindow = true }); while (invoice.Status.ValueString == "WAITING" || invoice.Status.ValueString == "PAID") { if (invoice.Status.ValueString == "PAID") { return(true); } else if (invoice.Status.ValueString == "WAITING") { Console.Clear(); Console.WriteLine("Ваш заказ обрабатывается, пожалуйста подождите..."); System.Threading.Thread.Sleep(10000); continue; } else { client.CancelBill(invoice.BillId); return(false); }; } } catch (AggregateException aggregateException) { var exception = aggregateException.GetBaseException(); Console.WriteLine(exception.Message); } return(false); }
// создаю форму о для покупки предмета 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; } } }
private static void ClassInitialize_Fake() { _testContext.Properties.Add( "fakeDataRows", new Dictionary <BillPaymentsClient, FakeApiPresets>( new[] { new FakeClient(ObjectMapperFactory.Create()), new FakeClient(ObjectMapperFactory.Create <NewtonsoftMapper>()) } .Select(fakeClient => new KeyValuePair <BillPaymentsClient, FakeApiPresets>( BillPaymentsClientFactory.Create(Config.MerchantSecretKey, fakeClient, fakeClient.ObjectMapper), new FakeApiPresets { Client = fakeClient, Bills = new List <BillResponse>(), Refunds = new List <RefundResponse>() } )) ) ); }
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++; } }