예제 #1
0
        private static TelegramShopMessageHandler GetLicenseKeyAddPageProcessor(MessageEventArgs e, ShopUserModel user)
        {
            if (e.Message.Text == MenuMessage.Back)
            {
                return(new BackMessageHandler(EDialogState.Main, AnswerMessage.MainMenu));
            }

            if (LicenseServerHandler.IsLicenseExist(e.Message.Text))
            {
                ShopUserRepository.AddLicenseKey(user, e.Message.Text);
                return(new LicenseRenewSubscriptionMessageHandler());
            }

            throw new ArgumentException(AnswerMessage.LicenseKeyNotExist);
        }
예제 #2
0
        public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
        {
            ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.QiwiPaymentVerification);

            if (cachedPayments != null && IsCachedOld() == false)
            {
                await telegramShop.SendMessage(
                    e.Message.Chat.Id,
                    GetQiwiTimeToNewRequestLeftMessage(),
                    GetKeyboard(userModel.CurrentDialogState));

                return;
            }

            var payments = telegramShop.Qiwi.GetIncomingTransactions().Result;

            lastRequestDate = DateTime.Now;
            cachedPayments  = payments;

            var isPaymentPresent = IsPaymentPresent(
                userModel.LicenseBuyProcess.Comment,
                userModel.LicenseBuyProcess.Price,
                payments);

            if (isPaymentPresent)
            {
                await telegramShop.BoldLog($"@{userModel.Telegram} bought license for {userModel.LicenseBuyProcess.Days} days for {userModel.LicenseBuyProcess.Price} RUB");

                ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.Main);

                if (userModel.LicenseBuyProcess.LicenseKey == null)
                {
                    var newLicenseKey = GetNewLicenseKey(userModel.Telegram);
                    LicenseServerHandler.GetNewLicense(userModel.LicenseBuyProcess.Days);

                    ShopUserRepository.AddLicenseKey(userModel, newLicenseKey);

                    await telegramShop.SendMessage(
                        e.Message.Chat.Id,
                        GetQiwiNewLicenseKeyAddedMessage(newLicenseKey, userModel.LicenseBuyProcess.Days),
                        GetKeyboard(userModel.CurrentDialogState));
                }
                else
                {
                    LicenseServerHandler.AddDaysForExistLicense(
                        userModel.LicenseBuyProcess.LicenseKey,
                        userModel.LicenseBuyProcess.Days);

                    await telegramShop.SendMessage(
                        e.Message.Chat.Id,
                        GetQiwiLicenseKeyDaysAddedMessage(
                            userModel.LicenseBuyProcess.LicenseKey,
                            userModel.LicenseBuyProcess.Days),
                        GetKeyboard(userModel.CurrentDialogState));
                }

                ShopUserRepository.UpdatePurchaseUniqueComment(userModel, null);
                ShopUserRepository.UpdateUserBuyLicenseKey(userModel, null);
                ShopUserRepository.UpdateUserLicenseDuration(userModel, 0, 0);
            }
            else
            {
                await telegramShop.SendMessage(
                    e.Message.Chat.Id,
                    GetQiwiTimeToNewRequestLeftMessage(),
                    GetKeyboard(userModel.CurrentDialogState));
            }
        }