Add td_api::storePaymentPurposeStars.

This commit is contained in:
levlam 2024-05-16 14:18:00 +03:00
parent 60064f8c2c
commit d6ed36f218
3 changed files with 38 additions and 5 deletions

View File

@ -5256,6 +5256,12 @@ storePaymentPurposePremiumGiftCodes boosted_chat_id:int53 currency:string amount
//@amount Paid amount, in the smallest units of the currency
storePaymentPurposePremiumGiveaway parameters:premiumGiveawayParameters currency:string amount:int53 = StorePaymentPurpose;
//@description The user buying Telegram stars
//@currency ISO 4217 currency code of the payment currency
//@amount Paid amount, in the smallest units of the currency
//@star_count Number of bought stars
storePaymentPurposeStars currency:string amount:int53 star_count:int53 = StorePaymentPurpose;
//@class TelegramPaymentPurpose @description Describes a purpose of a payment toward Telegram

View File

@ -178,14 +178,14 @@ Result<telegram_api::object_ptr<telegram_api::InputPeer>> get_boost_input_peer(T
}
static Result<tl_object_ptr<telegram_api::InputStorePaymentPurpose>> get_input_store_payment_purpose(
Td *td, const td_api::object_ptr<td_api::StorePaymentPurpose> &purpose) {
Td *td, td_api::object_ptr<td_api::StorePaymentPurpose> &purpose) {
if (purpose == nullptr) {
return Status::Error(400, "Purchase purpose must be non-empty");
}
switch (purpose->get_id()) {
case td_api::storePaymentPurposePremiumSubscription::ID: {
auto p = static_cast<const td_api::storePaymentPurposePremiumSubscription *>(purpose.get());
auto p = static_cast<td_api::storePaymentPurposePremiumSubscription *>(purpose.get());
int32 flags = 0;
if (p->is_restore_) {
flags |= telegram_api::inputStorePaymentPremiumSubscription::RESTORE_MASK;
@ -197,17 +197,20 @@ static Result<tl_object_ptr<telegram_api::InputStorePaymentPurpose>> get_input_s
false /*ignored*/);
}
case td_api::storePaymentPurposeGiftedPremium::ID: {
auto p = static_cast<const td_api::storePaymentPurposeGiftedPremium *>(purpose.get());
auto p = static_cast<td_api::storePaymentPurposeGiftedPremium *>(purpose.get());
UserId user_id(p->user_id_);
TRY_RESULT(input_user, td->user_manager_->get_input_user(user_id));
if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) {
return Status::Error(400, "Invalid amount of the currency specified");
}
if (!clean_input_string(p->currency_)) {
return Status::Error(400, "Strings must be encoded in UTF-8");
}
return make_tl_object<telegram_api::inputStorePaymentGiftPremium>(std::move(input_user), p->currency_,
p->amount_);
}
case td_api::storePaymentPurposePremiumGiftCodes::ID: {
auto p = static_cast<const td_api::storePaymentPurposePremiumGiftCodes *>(purpose.get());
auto p = static_cast<td_api::storePaymentPurposePremiumGiftCodes *>(purpose.get());
vector<telegram_api::object_ptr<telegram_api::InputUser>> input_users;
for (auto user_id : p->user_ids_) {
TRY_RESULT(input_user, td->user_manager_->get_input_user(UserId(user_id)));
@ -216,6 +219,9 @@ static Result<tl_object_ptr<telegram_api::InputStorePaymentPurpose>> get_input_s
if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) {
return Status::Error(400, "Invalid amount of the currency specified");
}
if (!clean_input_string(p->currency_)) {
return Status::Error(400, "Strings must be encoded in UTF-8");
}
DialogId boosted_dialog_id(p->boosted_chat_id_);
TRY_RESULT(boost_input_peer, get_boost_input_peer(td, boosted_dialog_id));
int32 flags = 0;
@ -226,13 +232,27 @@ static Result<tl_object_ptr<telegram_api::InputStorePaymentPurpose>> get_input_s
flags, std::move(input_users), std::move(boost_input_peer), p->currency_, p->amount_);
}
case td_api::storePaymentPurposePremiumGiveaway::ID: {
auto p = static_cast<const td_api::storePaymentPurposePremiumGiveaway *>(purpose.get());
auto p = static_cast<td_api::storePaymentPurposePremiumGiveaway *>(purpose.get());
if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) {
return Status::Error(400, "Invalid amount of the currency specified");
}
if (!clean_input_string(p->currency_)) {
return Status::Error(400, "Strings must be encoded in UTF-8");
}
TRY_RESULT(parameters, GiveawayParameters::get_giveaway_parameters(td, p->parameters_.get()));
return parameters.get_input_store_payment_premium_giveaway(td, p->currency_, p->amount_);
}
case td_api::storePaymentPurposeStars::ID: {
auto p = static_cast<td_api::storePaymentPurposeStars *>(purpose.get());
if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) {
return Status::Error(400, "Invalid amount of the currency specified");
}
if (!clean_input_string(p->currency_)) {
return Status::Error(400, "Strings must be encoded in UTF-8");
}
return telegram_api::make_object<telegram_api::inputStorePaymentStars>(0, p->star_count_, p->currency_,
p->amount_);
}
default:
UNREACHABLE();
return nullptr;

View File

@ -3404,6 +3404,13 @@ class CliClient final : public Actor {
get_args(args, parameters, currency, amount);
send_request(td_api::make_object<td_api::canPurchasePremium>(
td_api::make_object<td_api::storePaymentPurposePremiumGiveaway>(parameters, currency, amount)));
} else if (op == "cpprs") {
string currency;
int64 amount;
int64 star_count;
get_args(args, currency, amount, star_count);
send_request(td_api::make_object<td_api::canPurchasePremium>(
td_api::make_object<td_api::storePaymentPurposeStars>(currency, amount, star_count)));
} else if (op == "gbf") {
send_request(td_api::make_object<td_api::getBusinessFeatures>(nullptr));
} else if (op == "atos") {