From 3987f69202653f5081a25d6c7e3c5ef462977ce0 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 16 May 2024 16:21:52 +0300 Subject: [PATCH] Add td_api::getStarPaymentOptions. --- td/generate/scheme/td_api.tl | 14 ++++++++++++++ td/telegram/Premium.cpp | 37 ++++++++++++++++++++++++++++++++++++ td/telegram/Premium.h | 2 ++ td/telegram/Td.cpp | 6 ++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 63 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 691cea75f..704e50e4b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -822,6 +822,17 @@ premiumGiftCodePaymentOptions options:vector = Pre //@use_date Point in time (Unix timestamp) when the code was activated; 0 if none premiumGiftCodeInfo creator_id:MessageSender creation_date:int32 is_from_giveaway:Bool giveaway_message_id:int53 month_count:int32 user_id:int53 use_date:int32 = PremiumGiftCodeInfo; +//@description Describes an option for buying Telegram stars +//@currency ISO 4217 currency code for the payment +//@amount The amount to pay, in the smallest units of the currency +//@star_count Number of stars that will be purchased +//@store_product_id Identifier of the store product associated with the option; may be empty if none +starPaymentOption currency:string amount:int53 star_count:int53 store_product_id:string = StarPaymentOption; + +//@description Contains a list of options for buying Telegram stars @options The list of options +starPaymentOptions options:vector = StarPaymentOptions; + + //@class PremiumGiveawayParticipantStatus @description Contains information about status of a user in a Telegram Premium giveaway @@ -10742,6 +10753,9 @@ launchPrepaidPremiumGiveaway giveaway_id:int64 parameters:premiumGiveawayParamet //@message_id Identifier of the giveaway or a giveaway winners message in the chat getPremiumGiveawayInfo chat_id:int53 message_id:int53 = PremiumGiveawayInfo; +//@description Returns available options for Telegram stars purchase +getStarPaymentOptions = StarPaymentOptions; + //@description Checks whether an in-store purchase is possible. Must be called before any in-store purchase @purpose Transaction purpose canPurchaseFromStore purpose:StorePaymentPurpose = Ok; diff --git a/td/telegram/Premium.cpp b/td/telegram/Premium.cpp index 105312f3c..c4fa0c326 100644 --- a/td/telegram/Premium.cpp +++ b/td/telegram/Premium.cpp @@ -607,6 +607,39 @@ class GetGiveawayInfoQuery final : public Td::ResultHandler { } }; +class GetStarsTopupOptionsQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetStarsTopupOptionsQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(telegram_api::payments_getStarsTopupOptions())); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto results = result_ptr.move_as_ok(); + vector> options; + for (auto &result : results) { + options.push_back(td_api::make_object(result->currency_, result->amount_, + result->stars_, result->store_product_)); + } + + promise_.set_value(td_api::make_object(std::move(options))); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class CanPurchasePremiumQuery final : public Td::ResultHandler { Promise promise_; @@ -1159,6 +1192,10 @@ void get_premium_giveaway_info(Td *td, MessageFullId message_full_id, ->send(message_full_id.get_dialog_id(), server_message_id); } +void get_star_payment_options(Td *td, Promise> &&promise) { + td->create_handler(std::move(promise))->send(); +} + void can_purchase_premium(Td *td, td_api::object_ptr &&purpose, Promise &&promise) { td->create_handler(std::move(promise))->send(std::move(purpose)); } diff --git a/td/telegram/Premium.h b/td/telegram/Premium.h index e3659b73f..3d0440d6c 100644 --- a/td/telegram/Premium.h +++ b/td/telegram/Premium.h @@ -54,6 +54,8 @@ void launch_prepaid_premium_giveaway(Td *td, int64 giveaway_id, void get_premium_giveaway_info(Td *td, MessageFullId message_full_id, Promise> &&promise); +void get_star_payment_options(Td *td, Promise> &&promise); + void can_purchase_premium(Td *td, td_api::object_ptr &&purpose, Promise &&promise); void assign_app_store_transaction(Td *td, const string &receipt, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 9b98f71a4..f35f6fbe2 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -9388,6 +9388,12 @@ void Td::on_request(uint64 id, const td_api::getPremiumGiveawayInfo &request) { get_premium_giveaway_info(this, {DialogId(request.chat_id_), MessageId(request.message_id_)}, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getStarPaymentOptions &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + get_star_payment_options(this, std::move(promise)); +} + void Td::on_request(uint64 id, td_api::canPurchaseFromStore &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c60706390..a2d636622 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1833,6 +1833,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getPremiumGiveawayInfo &request); + void on_request(uint64 id, const td_api::getStarPaymentOptions &request); + void on_request(uint64 id, td_api::canPurchaseFromStore &request); void on_request(uint64 id, td_api::assignAppStoreTransaction &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index cfe380c6d..443483be4 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3380,6 +3380,8 @@ class CliClient final : public Actor { MessageId message_id; get_args(args, chat_id, message_id); send_request(td_api::make_object(chat_id, message_id)); + } else if (op == "gspo") { + send_request(td_api::make_object()); } else if (op == "cpfs" || op == "cpfsb") { UserId user_id; string currency;