Add td_api::getPremiumGiftCodePaymentOptions.

This commit is contained in:
levlam 2023-09-28 21:26:33 +03:00
parent 4be2d8cbe5
commit ca1ae47242
6 changed files with 89 additions and 1 deletions

View File

@ -683,6 +683,18 @@ premiumPaymentOption currency:string amount:int53 discount_percentage:int32 mont
//@last_transaction_id Identifier of the last in-store transaction for the currently used option
premiumStatePaymentOption payment_option:premiumPaymentOption is_current:Bool is_upgrade:Bool last_transaction_id:string = PremiumStatePaymentOption;
//@description Describes an option for creating Telegram Premium gift codes
//@currency ISO 4217 currency code for Telegram Premium gift code payment
//@amount The amount to pay, in the smallest units of the currency
//@user_count Number of users which will be able to activate the gift codes
//@month_count Number of month the Telegram Premium subscription will be active
//@store_product_id Identifier of the store product associated with the option; may be empty if none
//@store_product_quantity Number of times the store product must be paid
premiumGiftCodePaymentOption currency:string amount:int53 user_count:int32 month_count:int32 store_product_id:string store_product_quantity:int32 = PremiumGiftCodePaymentOption;
//@description Contains a list of options for creating Telegram Premium gift codes @options The list of options
premiumGiftCodePaymentOptions options:vector<premiumGiftCodePaymentOption> = PremiumGiftCodePaymentOptions;
//@description Describes a custom emoji to be shown instead of the Telegram Premium badge
//@custom_emoji_id Identifier of the custom emoji in stickerFormatTgs format
@ -9014,6 +9026,10 @@ clickPremiumSubscriptionButton = Ok;
//@description Returns state of Telegram Premium subscription and promotion videos for Premium features
getPremiumState = PremiumState;
//@description Returns available options for Telegram Premium gift code creation
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by receivers of the gift codes and which is administered by the user; 0 if none
getPremiumGiftCodePaymentOptions boosted_chat_id:int53 = PremiumGiftCodePaymentOptions;
//@description Checks whether Telegram Premium purchase is possible. Must be called before in-store Premium purchase @purpose Transaction purpose
canPurchasePremium purpose:StorePaymentPurpose = Ok;

View File

@ -98,7 +98,7 @@ static Result<telegram_api::object_ptr<telegram_api::InputPeer>> get_boost_input
}
if (dialog_id.get_type() != DialogType::Channel ||
!td->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id())) {
return Status::Error(400, "Unallowed chat to boost specified");
return Status::Error(400, "Can't boost the chat");
}
if (!td->contacts_manager_->get_channel_status(dialog_id.get_channel_id()).is_administrator()) {
return Status::Error(400, "Not enough rights in the chat");
@ -228,6 +228,57 @@ class GetPremiumPromoQuery final : public Td::ResultHandler {
}
};
class GetPremiumGiftCodeOptionsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::premiumGiftCodePaymentOptions>> promise_;
DialogId boosted_dialog_id_;
public:
explicit GetPremiumGiftCodeOptionsQuery(Promise<td_api::object_ptr<td_api::premiumGiftCodePaymentOptions>> &&promise)
: promise_(std::move(promise)) {
}
void send(DialogId boosted_dialog_id) {
auto r_boost_input_peer = get_boost_input_peer(td_, boosted_dialog_id);
if (r_boost_input_peer.is_error()) {
return on_error(r_boost_input_peer.move_as_error());
}
auto boost_input_peer = r_boost_input_peer.move_as_ok();
int32 flags = 0;
if (boost_input_peer != nullptr) {
flags |= telegram_api::payments_getPremiumGiftCodeOptions::BOOST_PEER_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::payments_getPremiumGiftCodeOptions(flags, std::move(boost_input_peer))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_getPremiumGiftCodeOptions>(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::premiumGiftCodePaymentOption>> options;
for (auto &result : results) {
if (result->store_product_.empty()) {
result->store_quantity_ = 0;
} else if (result->store_quantity_ <= 0) {
result->store_quantity_ = 1;
}
options.push_back(td_api::make_object<td_api::premiumGiftCodePaymentOption>(
result->currency_, result->amount_, result->users_, result->months_, result->store_product_,
result->store_quantity_));
}
promise_.set_value(td_api::make_object<td_api::premiumGiftCodePaymentOptions>(std::move(options)));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class CanPurchasePremiumQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
@ -654,6 +705,11 @@ void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>>
td->create_handler<GetPremiumPromoQuery>(std::move(promise))->send();
}
void get_premium_gift_code_options(Td *td, DialogId boosted_dialog_id,
Promise<td_api::object_ptr<td_api::premiumGiftCodePaymentOptions>> &&promise) {
td->create_handler<GetPremiumGiftCodeOptionsQuery>(std::move(promise))->send(boosted_dialog_id);
}
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

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/td_api.h"
#include "td/utils/common.h"
@ -30,6 +31,9 @@ void click_premium_subscription_button(Td *td, Promise<Unit> &&promise);
void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>> &&promise);
void get_premium_gift_code_options(Td *td, DialogId boosted_dialog_id,
Promise<td_api::object_ptr<td_api::premiumGiftCodePaymentOptions>> &&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

@ -8789,6 +8789,12 @@ void Td::on_request(uint64 id, const td_api::getPremiumState &request) {
get_premium_state(this, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getPremiumGiftCodePaymentOptions &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
get_premium_gift_code_options(this, DialogId(request.boosted_chat_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::canPurchasePremium &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -1597,6 +1597,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getPremiumState &request);
void on_request(uint64 id, const td_api::getPremiumGiftCodePaymentOptions &request);
void on_request(uint64 id, td_api::canPurchasePremium &request);
void on_request(uint64 id, td_api::assignAppStoreTransaction &request);

View File

@ -3092,6 +3092,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::clickPremiumSubscriptionButton>());
} else if (op == "gprs") {
send_request(td_api::make_object<td_api::getPremiumState>());
} else if (op == "gpgcpo") {
ChatId boosted_chat_id;
get_args(args, boosted_chat_id);
send_request(td_api::make_object<td_api::getPremiumGiftCodePaymentOptions>(boosted_chat_id));
} else if (op == "cppr" || op == "cpprb") {
UserId user_id;
string currency;