Как проверить статуст платежа Qiwi API

пишу Телеграмм бота на C#. Мне нужно подключить оплату через Qiwi API, с формой я разобрался теперь мне осталось сделать проверку статуса платежа и вернуть сумму на которую был пополнен счёт.

    class Qiwi
{
    public string TelegramBillId { get; set; }
    public string CreateForm(decimal sum)
    {
        BillPaymentsClient client = BillPaymentsClientFactory.Create(
            secretKey: "eyJ2ZXJzaW9"
            );

        var form = client.CreatePaymentForm(
            paymentInfo: new PaymentInfo
            {
                PublicKey = "48e7qUxn9",
                Amount = new MoneyAmount
                {
                    ValueDecimal = sum,
                    CurrencyEnum = CurrencyEnum.Rub
                },
                BillId = CreateBillId()
            }
            );
        var responce = client.GetBillInfo(TelegramBillId);
        return form.ToString();
    }
    private string CreateBillId()
    {
        TelegramBillId = Guid.NewGuid().ToString();
        return TelegramBillId;
    }
}

Ответы (1 шт):

Автор решения: Дмитрий Степанов

Вдруг кому-то понадобится.Возможно, сделано криво, но оно работает.

   public static class Qiwi
{
    public static string TelegramBillId { get; set; }
   
    public static string CreateForm(decimal sum)
    {
        CreateTelegramBildId();
        BillPaymentsClient client = BillPaymentsClientFactory.Create(
            secretKey: ""
            );
        
        BillResponse form = client.CreateBill(
            info: new CreateBillInfo
            {
                BillId = TelegramBillId,
                Amount = new MoneyAmount
                {
                    ValueDecimal = sum,
                    CurrencyEnum = CurrencyEnum.Rub
                },
                Comment = Guid.NewGuid().ToString(),
                ExpirationDateTime = DateTime.Now.AddDays(2),
                Customer = new Customer
                {
                    Account = Guid.NewGuid().ToString(),
                },
            }
            );

        BillResponse responseStatus = client.GetBillInfo(billId: form.BillId);
        string status = responseStatus.Status.ValueString;
        Customer customer = form.Customer;
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine($"Пользователь пытается пополнить счёт статус {status}");
        return form.PayUrl.ToString();
    }
    
    private static string CreateTelegramBildId()
    {
        TelegramBillId = Guid.NewGuid().ToString();
        return TelegramBillId;
    }
    
    private static string DefaultTelegramBildId()
    {
        TelegramBillId = null;
        return TelegramBillId;
    }
    
    private static string CheckStatus()
    {
        if(TelegramBillId != null)
        {
            BillPaymentsClient client = BillPaymentsClientFactory.Create(
                secretKey: ""
                );
            BillResponse responseStatus = client.GetBillInfo(TelegramBillId);
            string status = responseStatus.Status.ValueString;
            return status;
        }
        else
        {
            return "fail";
        }
    }
    
    public static string StatusMessage()
    {
        string result;
        string status = CheckStatus();
        if(status == "PAID")
        {
            result = $"{char.ConvertFromUtf32(0x2705)} Баланс пополнен";
            DefaultTelegramBildId();
        }
        else if(status == "WAITING")
        {
            result = $"{char.ConvertFromUtf32(0x231A)} Счёт ожидает оплаты";
        }
        else
        {
            result = $"{char.ConvertFromUtf32(0x274C)} Ошибка";
        }
        return result;
    }
}
→ Ссылка