From cd7507fb23b1fd4eaa07ec9cdf59a81fc69cb569 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 28 May 2024 16:28:35 +0300 Subject: [PATCH] Respected accessibility of premium for credits purchasing. --- Telegram/Resources/langs/lang.strings | 1 + .../payments/payments_non_panel_process.cpp | 9 ++++++++- .../settings/settings_credits_graphics.cpp | 19 ++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index eb8eecb58c..9d6823fb59 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2328,6 +2328,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_credits_small_balance_title#one" = "{count} Star Needed"; "lng_credits_small_balance_title#other" = "{count} Stars Needed"; "lng_credits_small_balance_about" = "Buy **Stars** and use them on **{bot}** and other miniapps."; +"lng_credits_purchase_blocked" = "Sorry, you can't purchase this item with Telegram Stars."; "lng_location_title" = "Location"; "lng_location_about" = "Display the location of your business on your account."; diff --git a/Telegram/SourceFiles/payments/payments_non_panel_process.cpp b/Telegram/SourceFiles/payments/payments_non_panel_process.cpp index efab4dd89f..112cdd5762 100644 --- a/Telegram/SourceFiles/payments/payments_non_panel_process.cpp +++ b/Telegram/SourceFiles/payments/payments_non_panel_process.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "history/history_item.h" #include "history/history_item_components.h" +#include "lang/lang_keys.h" #include "main/main_session.h" #include "mainwidget.h" #include "payments/payments_checkout_process.h" // NonPanelPaymentForm. @@ -80,13 +81,19 @@ Fn ProcessNonPanelPaymentFormFactory( - int64(slice.balance); if (creditsNeeded <= 0) { sendBox(); - } else { + } else if (strong->session().premiumPossible()) { strong->uiShow()->show(Box( Settings::SmallBalanceBox, strong, creditsNeeded, form->botId, sendBox)); + } else { + strong->uiShow()->showToast( + tr::lng_credits_purchase_blocked(tr::now)); + if (maybeReturnToBot) { + maybeReturnToBot(CheckoutResult::Failed); + } } } lifetime->destroy(); diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 066adf6f04..e9f825eadd 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -286,11 +286,20 @@ void FillCreditOptions( const auto apiCredits = content->lifetime().make_state( controller->session().user()); - apiCredits->request( - ) | rpl::start_with_error_done([=](const QString &error) { - controller->showToast(error); - }, [=] { - fill(apiCredits->options()); + if (controller->session().premiumPossible()) { + apiCredits->request( + ) | rpl::start_with_error_done([=](const QString &error) { + controller->showToast(error); + }, [=] { + fill(apiCredits->options()); + }, content->lifetime()); + } + + controller->session().premiumPossibleValue( + ) | rpl::start_with_next([=](bool premiumPossible) { + if (!premiumPossible) { + fill({}); + } }, content->lifetime()); }