Esempio n. 1
0
        private static string GetQiwiPaymentMessage(ShopUserModel user)
        {
            var comment = GetUniqueComment();

            ShopUserRepository.UpdatePurchaseUniqueComment(user, comment);

            return(AnswerMessage.QiwiPaymentMethod
                   .Replace("{price}", user.LicenseBuyProcess.Price.ToString(CultureInfo.InvariantCulture))
                   .Replace("{comment}", comment));
        }
Esempio n. 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));
            }
        }