Bladeren bron

Payments template

Tigran 3 jaren geleden
bovenliggende
commit
cf4a39f070

+ 6 - 35
CardCollector/Commands/Message/TextMessage/ShowSampleMessage.cs

@@ -2,7 +2,9 @@
 using CardCollector.Controllers;
 using CardCollector.DataBase.Entity;
 using CardCollector.Resources;
+using Telegram.Bot;
 using Telegram.Bot.Types;
+using Telegram.Bot.Types.Payments;
 using Telegram.Bot.Types.ReplyMarkups;
 
 namespace CardCollector.Commands.Message.TextMessage
@@ -15,42 +17,11 @@ namespace CardCollector.Commands.Message.TextMessage
         protected override string CommandText => Text.show_sample;
         public override async Task Execute()
         {
-            await MessageController.SendMessage(User, "Текущие примененные фильтры:" +
-                                                      "\nАвтор (все)\nТир (все)\nЭмоция (все)\nСортировка(нет)" +
-                                                      "\n\nУстановите фильтры кнопками ниже:",
-                new InlineKeyboardMarkup(new []
+            await Bot.Client.SendInvoiceAsync(User.ChatId, "test", "test", "test", "401643678:TEST:f13667cd-bbf7-4ca1-ba9e-7aa49e4d3faa",
+                "USD", new []
                 {
-                    new [] {InlineKeyboardButton.WithCallbackData("Автор")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Тир")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Эмоция")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Сортировка")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Отмена")},
-                    new [] {InlineKeyboardButton.WithSwitchInlineQueryCurrentChat("Показать стикеры")},
-                }));
-            await MessageController.SendMessage(User, "Выберите автора из списка ниже:",
-                new InlineKeyboardMarkup(new []
-                {
-                    new [] {InlineKeyboardButton.WithCallbackData("Все")},
-                    new [] {InlineKeyboardButton.WithCallbackData("А"),InlineKeyboardButton.WithCallbackData("Б")},
-                    new [] {InlineKeyboardButton.WithCallbackData("В"),InlineKeyboardButton.WithCallbackData("Г"),},
-                    new [] {InlineKeyboardButton.WithCallbackData("Д"),InlineKeyboardButton.WithCallbackData("Е"),},
-                    new [] {InlineKeyboardButton.WithCallbackData("Ё"),InlineKeyboardButton.WithCallbackData("Ж"),},
-                    new [] {InlineKeyboardButton.WithCallbackData("З"),InlineKeyboardButton.WithCallbackData("З"),},
-                    new [] {InlineKeyboardButton.WithCallbackData("←"),InlineKeyboardButton.WithCallbackData("→")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Отмена")},
-                }));
-            await MessageController.SendMessage(User, "Текущие примененные фильтры:" +
-                                                      "\nАвтор (Г)\nТир (все)\nЭмоция (все)\nСортировка(нет)" +
-                                                      "\n\nУстановите фильтры кнопками ниже:",
-                new InlineKeyboardMarkup(new []
-                {
-                    new [] {InlineKeyboardButton.WithCallbackData("Автор")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Тир")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Эмоция")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Сортировка")},
-                    new [] {InlineKeyboardButton.WithCallbackData("Отмена")},
-                    new [] {InlineKeyboardButton.WithSwitchInlineQueryCurrentChat("Показать стикеры")},
-                }));
+                    new LabeledPrice("text", 100)
+                });
         }
 
         /* Нужно помимо совпадения текста проверить пользователя на уровень привилегий */

+ 48 - 0
CardCollector/Commands/PreCheckoutQuery/PreCheckoutQuery.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using CardCollector.DataBase.Entity;
+using CardCollector.DataBase.EntityDao;
+using Telegram.Bot.Types;
+
+namespace CardCollector.Commands.PreCheckoutQuery
+{
+    public abstract class PreCheckoutQuery : UpdateModel
+    {
+        protected string PreCheckoutQueryId;
+        
+        private static readonly List<PreCheckoutQuery> List = new()
+            {
+                // Стандартная обработка платежа
+                new StandartPreCheckoutQuery(),
+            };
+
+        /* Метод, создающий объекты команд исходя из полученного обновления */
+        public static async Task<UpdateModel> Factory(Update update)
+        {
+            /* Данные определяем исходя из типа сообщения */
+            var data = update.PreCheckoutQuery!.Id;
+            
+            // Объект пользователя
+            var user = await UserDao.GetUser(update.PreCheckoutQuery!.From);
+            
+            // Если пользователь заблокирован игонрируем
+            if (user.IsBlocked) return new IgnoreUpdate();
+            
+            // Возвращаем объект, если команда совпала
+            foreach (var item in List.Where(item => item.IsMatches(data)))
+                if(Activator.CreateInstance(item.GetType(), user, update) is PreCheckoutQuery executor)
+                    if (executor.IsMatches(data)) return executor;
+        
+            // Возвращаем команда не найдена, если код дошел до сюда
+            return new CommandNotFound(user, update, data);
+        }
+
+        protected PreCheckoutQuery() { }
+        protected PreCheckoutQuery(UserEntity user, Update update) : base(user, update)
+        {
+            PreCheckoutQueryId = update.PreCheckoutQuery!.Id;
+        }
+    }
+}

+ 20 - 0
CardCollector/Commands/PreCheckoutQuery/StandartPreCheckoutQuery.cs

@@ -0,0 +1,20 @@
+using System.Threading.Tasks;
+using CardCollector.DataBase.Entity;
+using Telegram.Bot;
+using Telegram.Bot.Types;
+
+namespace CardCollector.Commands.PreCheckoutQuery
+{
+    public class StandartPreCheckoutQuery : PreCheckoutQuery
+    {
+        protected override string CommandText => "";
+
+        public override async Task Execute()
+        {
+            await Bot.Client.AnswerPreCheckoutQueryAsync(PreCheckoutQueryId);
+        }
+
+        public StandartPreCheckoutQuery() { }
+        public StandartPreCheckoutQuery(UserEntity user, Update update) : base(user, update) { }
+    }
+}

+ 4 - 0
CardCollector/Controllers/MessageController.cs

@@ -10,12 +10,14 @@ using Telegram.Bot.Types;
 using Telegram.Bot.Types.Enums;
 using Telegram.Bot.Types.InlineQueryResults;
 using Telegram.Bot.Types.InputFiles;
+using Telegram.Bot.Types.Payments;
 using Telegram.Bot.Types.ReplyMarkups;
 using Message = CardCollector.Commands.Message.Message;
 using CallBackQuery = CardCollector.Commands.CallbackQuery.CallbackQuery;
 using MyChatMember = CardCollector.Commands.MyChatMember.MyChatMember;
 using InlineQuery = CardCollector.Commands.InlineQuery.InlineQuery;
 using ChosenInlineResult = CardCollector.Commands.ChosenInlineResult.ChosenInlineResult;
+using PreCheckoutQuery = CardCollector.Commands.PreCheckoutQuery.PreCheckoutQuery;
 using TgMessage = Telegram.Bot.Types.Message;
 
 namespace CardCollector.Controllers
@@ -42,6 +44,8 @@ namespace CardCollector.Controllers
                     UpdateType.InlineQuery => await InlineQuery.Factory(update),
                     // Тип обновления - выбор результата в инлайн меню
                     UpdateType.ChosenInlineResult => await ChosenInlineResult.Factory(update),
+                    // Тип обновления - платеж
+                    UpdateType.PreCheckoutQuery => await PreCheckoutQuery.Factory(update),
                     _ => throw new ArgumentOutOfRangeException()
                 };
                 // Обработать команду