Add td_api::getStarPaymentOptions.

This commit is contained in:
levlam 2024-05-16 16:21:52 +03:00
parent 88ee1e8a65
commit 3987f69202
6 changed files with 63 additions and 0 deletions

View File

@ -822,6 +822,17 @@ premiumGiftCodePaymentOptions options:vector<premiumGiftCodePaymentOption> = 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<starPaymentOption> = 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;

View File

@ -607,6 +607,39 @@ class GetGiveawayInfoQuery final : public Td::ResultHandler {
}
};
class GetStarsTopupOptionsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::starPaymentOptions>> promise_;
public:
explicit GetStarsTopupOptionsQuery(Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&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<telegram_api::payments_getStarsTopupOptions>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto results = result_ptr.move_as_ok();
vector<td_api::object_ptr<td_api::starPaymentOption>> options;
for (auto &result : results) {
options.push_back(td_api::make_object<td_api::starPaymentOption>(result->currency_, result->amount_,
result->stars_, result->store_product_));
}
promise_.set_value(td_api::make_object<td_api::starPaymentOptions>(std::move(options)));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class CanPurchasePremiumQuery final : public Td::ResultHandler {
Promise<Unit> 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<td_api::object_ptr<td_api::starPaymentOptions>> &&promise) {
td->create_handler<GetStarsTopupOptionsQuery>(std::move(promise))->send();
}
void can_purchase_premium(Td *td, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise) {
td->create_handler<CanPurchasePremiumQuery>(std::move(promise))->send(std::move(purpose));
}

View File

@ -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<td_api::object_ptr<td_api::PremiumGiveawayInfo>> &&promise);
void get_star_payment_options(Td *td, Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise);
void can_purchase_premium(Td *td, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise);
void assign_app_store_transaction(Td *td, const string &receipt,

View File

@ -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();

View File

@ -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);

View File

@ -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<td_api::getPremiumGiveawayInfo>(chat_id, message_id));
} else if (op == "gspo") {
send_request(td_api::make_object<td_api::getStarPaymentOptions>());
} else if (op == "cpfs" || op == "cpfsb") {
UserId user_id;
string currency;