Respected accessibility of premium for credits purchasing.

This commit is contained in:
23rd 2024-05-28 16:28:35 +03:00 committed by John Preston
parent 9a5923676a
commit cd7507fb23
3 changed files with 23 additions and 6 deletions

View file

@ -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#one" = "{count} Star Needed";
"lng_credits_small_balance_title#other" = "{count} Stars 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_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_title" = "Location";
"lng_location_about" = "Display the location of your business on your account."; "lng_location_about" = "Display the location of your business on your account.";

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h" #include "data/data_user.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "lang/lang_keys.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "payments/payments_checkout_process.h" // NonPanelPaymentForm. #include "payments/payments_checkout_process.h" // NonPanelPaymentForm.
@ -80,13 +81,19 @@ Fn<void(NonPanelPaymentForm)> ProcessNonPanelPaymentFormFactory(
- int64(slice.balance); - int64(slice.balance);
if (creditsNeeded <= 0) { if (creditsNeeded <= 0) {
sendBox(); sendBox();
} else { } else if (strong->session().premiumPossible()) {
strong->uiShow()->show(Box( strong->uiShow()->show(Box(
Settings::SmallBalanceBox, Settings::SmallBalanceBox,
strong, strong,
creditsNeeded, creditsNeeded,
form->botId, form->botId,
sendBox)); sendBox));
} else {
strong->uiShow()->showToast(
tr::lng_credits_purchase_blocked(tr::now));
if (maybeReturnToBot) {
maybeReturnToBot(CheckoutResult::Failed);
}
} }
} }
lifetime->destroy(); lifetime->destroy();

View file

@ -286,11 +286,20 @@ void FillCreditOptions(
const auto apiCredits = content->lifetime().make_state<ApiOptions>( const auto apiCredits = content->lifetime().make_state<ApiOptions>(
controller->session().user()); controller->session().user());
apiCredits->request( if (controller->session().premiumPossible()) {
) | rpl::start_with_error_done([=](const QString &error) { apiCredits->request(
controller->showToast(error); ) | rpl::start_with_error_done([=](const QString &error) {
}, [=] { controller->showToast(error);
fill(apiCredits->options()); }, [=] {
fill(apiCredits->options());
}, content->lifetime());
}
controller->session().premiumPossibleValue(
) | rpl::start_with_next([=](bool premiumPossible) {
if (!premiumPossible) {
fill({});
}
}, content->lifetime()); }, content->lifetime());
} }