aboutsummaryrefslogtreecommitdiffhomepage
path: root/td/telegram/Premium.cpp
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2025-02-18 18:18:52 +0300
committerlevlam <levlam@telegram.org>2025-02-18 18:18:52 +0300
commit6371e5f898530ab307a82437863770a2d32a61e6 (patch)
treeef7d106b333e873ab6a95b02f98c7f3f141052b0 /td/telegram/Premium.cpp
parentaee91607e3e111611099325ced20b981228849e3 (diff)
Support gift code payment options in different currencies.
Diffstat (limited to 'td/telegram/Premium.cpp')
-rw-r--r--td/telegram/Premium.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/td/telegram/Premium.cpp b/td/telegram/Premium.cpp
index 66abfe91f..e9dd5ce4e 100644
--- a/td/telegram/Premium.cpp
+++ b/td/telegram/Premium.cpp
@@ -405,14 +405,15 @@ class GetPremiumGiftCodeOptionsQuery final : public Td::ResultHandler {
auto results = result_ptr.move_as_ok();
td::remove_if(results, [](const telegram_api::object_ptr<telegram_api::premiumGiftCodeOption> &payment_option) {
- return payment_option->users_ <= 0 || payment_option->months_ <= 0 || payment_option->amount_ <= 0;
+ return payment_option->users_ <= 0 || payment_option->months_ <= 0 || payment_option->amount_ <= 0 ||
+ payment_option->currency_.empty();
});
auto get_monthly_price = [](const telegram_api::object_ptr<telegram_api::premiumGiftCodeOption> &payment_option) {
return static_cast<double>(payment_option->amount_) / static_cast<double>(payment_option->months_);
};
- FlatHashMap<int32, double> max_prices;
+ FlatHashMap<int32, FlatHashMap<string, double>> max_prices;
for (auto &result : results) {
- auto &max_price = max_prices[result->users_];
+ auto &max_price = max_prices[result->users_][result->currency_];
auto price = get_monthly_price(result);
if (price > max_price) {
max_price = price;
@@ -426,7 +427,7 @@ class GetPremiumGiftCodeOptionsQuery final : public Td::ResultHandler {
} else if (result->store_quantity_ <= 0) {
result->store_quantity_ = 1;
}
- double relative_price = get_monthly_price(result) / max_prices[result->users_];
+ double relative_price = get_monthly_price(result) / max_prices[result->users_][result->currency_];
options.push_back(td_api::make_object<td_api::premiumGiftCodePaymentOption>(
result->currency_, result->amount_, static_cast<int32>(100 * (1.0 - relative_price)), result->users_,
result->months_, result->store_product_, result->store_quantity_,