Add td_api::inputInvoiceTelegram.

This commit is contained in:
levlam 2023-10-03 18:27:56 +03:00
parent e608fdca7b
commit a98a9fb971
5 changed files with 118 additions and 10 deletions

View File

@ -2228,6 +2228,9 @@ inputInvoiceMessage chat_id:int53 message_id:int53 = InputInvoice;
//@description An invoice from a link of the type internalLinkTypeInvoice @name Name of the invoice //@description An invoice from a link of the type internalLinkTypeInvoice @name Name of the invoice
inputInvoiceName name:string = InputInvoice; inputInvoiceName name:string = InputInvoice;
//@description An invoice for a payment toward Telegram; must not be used in the in-store apps @purpose Transaction purpose
inputInvoiceTelegram purpose:TelegramPaymentPurpose = InputInvoice;
//@class MessageExtendedMedia @description Describes a media, which is attached to an invoice //@class MessageExtendedMedia @description Describes a media, which is attached to an invoice
@ -4409,22 +4412,22 @@ premiumState state:formattedText payment_options:vector<premiumStatePaymentOptio
//@class StorePaymentPurpose @description Describes a purpose of an in-store payment //@class StorePaymentPurpose @description Describes a purpose of an in-store payment
//@description The user subscribed to Telegram Premium @is_restore Pass true if this is a restore of a Telegram Premium purchase; only for App Store @is_upgrade Pass true if this is an upgrade from a monthly subscription to early subscription; only for App Store //@description The user subscribing to Telegram Premium @is_restore Pass true if this is a restore of a Telegram Premium purchase; only for App Store @is_upgrade Pass true if this is an upgrade from a monthly subscription to early subscription; only for App Store
storePaymentPurposePremiumSubscription is_restore:Bool is_upgrade:Bool = StorePaymentPurpose; storePaymentPurposePremiumSubscription is_restore:Bool is_upgrade:Bool = StorePaymentPurpose;
//@description The user gifted Telegram Premium to another user @user_id Identifier of the user to which Premium was gifted @currency ISO 4217 currency code of the payment currency @amount Paid amount, in the smallest units of the currency //@description The user gifting Telegram Premium to another user @user_id Identifier of the user to which Premium was gifted @currency ISO 4217 currency code of the payment currency @amount Paid amount, in the smallest units of the currency
storePaymentPurposeGiftedPremium user_id:int53 currency:string amount:int53 = StorePaymentPurpose; storePaymentPurposeGiftedPremium user_id:int53 currency:string amount:int53 = StorePaymentPurpose;
//@description The user created Telegram Premium gift codes for other users //@description The user creating Telegram Premium gift codes for other users
//@user_ids Identifiers of the users which can activate the gift codes
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user; 0 if none //@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user; 0 if none
//@currency ISO 4217 currency code of the payment currency //@currency ISO 4217 currency code of the payment currency
//@amount Paid amount, in the smallest units of the currency //@amount Paid amount, in the smallest units of the currency
storePaymentPurposePremiumGiftCodes user_ids:vector<int53> boosted_chat_id:int53 currency:string amount:int53 = StorePaymentPurpose; //@user_ids Identifiers of the users which can activate the gift codes
storePaymentPurposePremiumGiftCodes boosted_chat_id:int53 currency:string amount:int53 user_ids:vector<int53> = StorePaymentPurpose;
//@description The user created a Telegram Premium giveaway for subscribers of a channel chat //@description The user creating a Telegram Premium giveaway for subscribers of a channel chat
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user //@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user
//@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible //@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible for the giveaway
//@date Point in time (Unix timestamp) when the giveaway will be performed; must be from 1 minute to 365 days in the future //@date Point in time (Unix timestamp) when the giveaway will be performed; must be from 1 minute to 365 days in the future
//@only_new_subscribers Pass true if only new subscribers of the chats will be eligible for the giveaway //@only_new_subscribers Pass true if only new subscribers of the chats will be eligible for the giveaway
//@currency ISO 4217 currency code of the payment currency //@currency ISO 4217 currency code of the payment currency
@ -4432,6 +4435,28 @@ storePaymentPurposePremiumGiftCodes user_ids:vector<int53> boosted_chat_id:int53
storePaymentPurposePremiumGiveaway boosted_chat_id:int53 additional_chat_ids:vector<int53> date:int32 only_new_subscribers:Bool currency:string amount:int53 = StorePaymentPurpose; storePaymentPurposePremiumGiveaway boosted_chat_id:int53 additional_chat_ids:vector<int53> date:int32 only_new_subscribers:Bool currency:string amount:int53 = StorePaymentPurpose;
//@class TelegramPaymentPurpose @description Describes a purpose of a payment toward Telegram
//@description The user creating Telegram Premium gift codes for other users
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user; 0 if none
//@currency ISO 4217 currency code of the payment currency
//@amount Paid amount, in the smallest units of the currency
//@user_ids Identifiers of the users which can activate the gift codes
//@month_count Number of month the Telegram Premium subscription will be active for the users
telegramPaymentPurposePremiumGiftCodes boosted_chat_id:int53 currency:string amount:int53 user_ids:vector<int53> month_count:int32 = TelegramPaymentPurpose;
//@description The user creating a Telegram Premium giveaway for subscribers of a channel chat
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user
//@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible for the giveaway
//@date Point in time (Unix timestamp) when the giveaway will be performed; must be from 1 minute to 365 days in the future
//@only_new_subscribers Pass true, if only new subscribers of the chats will be eligible for the giveaway
//@currency ISO 4217 currency code of the payment currency
//@amount Paid amount, 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 for the users
telegramPaymentPurposePremiumGiveaway boosted_chat_id:int53 additional_chat_ids:vector<int53> date:int32 only_new_subscribers:Bool currency:string amount:int53 user_count:int32 month_count:int32 = TelegramPaymentPurpose;
//@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method. //@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method.
//-To use specific push notification service, the correct application platform must be specified and a valid server authentication data must be uploaded at https://my.telegram.org //-To use specific push notification service, the correct application platform must be specified and a valid server authentication data must be uploaded at https://my.telegram.org

View File

@ -17,6 +17,7 @@
#include "td/telegram/misc.h" #include "td/telegram/misc.h"
#include "td/telegram/PasswordManager.h" #include "td/telegram/PasswordManager.h"
#include "td/telegram/Photo.h" #include "td/telegram/Photo.h"
#include "td/telegram/Premium.h"
#include "td/telegram/ServerMessageId.h" #include "td/telegram/ServerMessageId.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
@ -29,6 +30,7 @@
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/JsonBuilder.h" #include "td/utils/JsonBuilder.h"
#include "td/utils/logging.h" #include "td/utils/logging.h"
#include "td/utils/Random.h"
#include "td/utils/Status.h" #include "td/utils/Status.h"
namespace td { namespace td {
@ -68,6 +70,83 @@ Result<InputInvoiceInfo> get_input_invoice_info(Td *td, td_api::object_ptr<td_ap
result.input_invoice_ = make_tl_object<telegram_api::inputInvoiceSlug>(invoice->name_); result.input_invoice_ = make_tl_object<telegram_api::inputInvoiceSlug>(invoice->name_);
break; break;
} }
case td_api::inputInvoiceTelegram::ID: {
auto invoice = td_api::move_object_as<td_api::inputInvoiceTelegram>(input_invoice);
if (invoice->purpose_ == nullptr) {
return Status::Error(400, "Purpose must not be empty");
}
switch (invoice->purpose_->get_id()) {
case td_api::telegramPaymentPurposePremiumGiftCodes::ID: {
auto p = static_cast<const td_api::telegramPaymentPurposePremiumGiftCodes *>(invoice->purpose_.get());
vector<telegram_api::object_ptr<telegram_api::InputUser>> input_users;
for (auto user_id : p->user_ids_) {
TRY_RESULT(input_user, td->contacts_manager_->get_input_user(UserId(user_id)));
input_users.push_back(std::move(input_user));
}
if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) {
return Status::Error(400, "Invalid amount of the currency specified");
}
DialogId boosted_dialog_id(p->boosted_chat_id_);
TRY_RESULT(boost_input_peer, get_boost_input_peer(td, boosted_dialog_id));
int32 flags = 0;
if (boost_input_peer != nullptr) {
flags |= telegram_api::inputStorePaymentPremiumGiftCode::BOOST_PEER_MASK;
}
auto option = telegram_api::make_object<telegram_api::premiumGiftCodeOption>(
0, input_users.size(), p->month_count_, string(), 0, p->currency_, p->amount_);
auto purpose = telegram_api::make_object<telegram_api::inputStorePaymentPremiumGiftCode>(
flags, std::move(input_users), std::move(boost_input_peer), p->currency_, p->amount_);
result.dialog_id_ = boosted_dialog_id;
result.input_invoice_ = telegram_api::make_object<telegram_api::inputInvoicePremiumGiftCode>(
std::move(purpose), std::move(option));
break;
}
case td_api::telegramPaymentPurposePremiumGiveaway::ID: {
auto p = static_cast<const td_api::telegramPaymentPurposePremiumGiveaway *>(invoice->purpose_.get());
if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) {
return Status::Error(400, "Invalid amount of the currency specified");
}
DialogId boosted_dialog_id(p->boosted_chat_id_);
TRY_RESULT(boost_input_peer, get_boost_input_peer(td, boosted_dialog_id));
if (boost_input_peer == nullptr) {
return Status::Error(400, "Boosted chat can't be empty");
}
vector<telegram_api::object_ptr<telegram_api::InputPeer>> additional_input_peers;
for (auto additional_chat_id : p->additional_chat_ids_) {
TRY_RESULT(input_peer, get_boost_input_peer(td, DialogId(additional_chat_id)));
if (input_peer == nullptr) {
return Status::Error(400, "Additional chat can't be empty");
}
additional_input_peers.push_back(std::move(input_peer));
}
int64 random_id;
do {
random_id = Random::secure_int64();
} while (random_id == 0);
int32 flags = 0;
if (p->only_new_subscribers_) {
flags |= telegram_api::inputStorePaymentPremiumGiveaway::ONLY_NEW_SUBSCRIBERS_MASK;
}
if (!additional_input_peers.empty()) {
flags |= telegram_api::inputStorePaymentPremiumGiveaway::ADDITIONAL_PEERS_MASK;
}
auto option = telegram_api::make_object<telegram_api::premiumGiftCodeOption>(
0, p->user_count_, p->month_count_, string(), 0, p->currency_, p->amount_);
auto purpose = telegram_api::make_object<telegram_api::inputStorePaymentPremiumGiveaway>(
flags, false /*ignored*/, std::move(boost_input_peer), std::move(additional_input_peers),
vector<string>(), random_id, p->date_, p->currency_, p->amount_);
result.input_invoice_ = telegram_api::make_object<telegram_api::inputInvoicePremiumGiftCode>(
std::move(purpose), std::move(option));
break;
}
default:
UNREACHABLE();
}
break;
}
default: default:
UNREACHABLE(); UNREACHABLE();
} }

View File

@ -90,7 +90,7 @@ static td_api::object_ptr<td_api::PremiumFeature> get_premium_feature_object(Sli
return nullptr; return nullptr;
} }
static Result<telegram_api::object_ptr<telegram_api::InputPeer>> get_boost_input_peer(Td *td, DialogId dialog_id) { Result<telegram_api::object_ptr<telegram_api::InputPeer>> get_boost_input_peer(Td *td, DialogId dialog_id) {
if (dialog_id == DialogId()) { if (dialog_id == DialogId()) {
return nullptr; return nullptr;
} }

View File

@ -8,15 +8,19 @@
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/Promise.h" #include "td/utils/Promise.h"
#include "td/utils/Slice.h" #include "td/utils/Slice.h"
#include "td/utils/Status.h"
namespace td { namespace td {
class Td; class Td;
Result<telegram_api::object_ptr<telegram_api::InputPeer>> get_boost_input_peer(Td *td, DialogId dialog_id);
const vector<Slice> &get_premium_limit_keys(); const vector<Slice> &get_premium_limit_keys();
void get_premium_limit(const td_api::object_ptr<td_api::PremiumLimitType> &limit_type, void get_premium_limit(const td_api::object_ptr<td_api::PremiumLimitType> &limit_type,

View File

@ -3119,8 +3119,8 @@ class CliClient final : public Actor {
boosted_chat_id, Auto(), static_cast<int32>(user_id) /*date*/, rand_bool(), currency, amount))); boosted_chat_id, Auto(), static_cast<int32>(user_id) /*date*/, rand_bool(), currency, amount)));
} else { } else {
send_request(td_api::make_object<td_api::canPurchasePremium>( send_request(td_api::make_object<td_api::canPurchasePremium>(
td_api::make_object<td_api::storePaymentPurposePremiumGiftCodes>(vector<int64>{user_id}, boosted_chat_id, td_api::make_object<td_api::storePaymentPurposePremiumGiftCodes>(boosted_chat_id, currency, amount,
currency, amount))); vector<int64>{user_id})));
} }
} else if (op == "atos") { } else if (op == "atos") {
send_request(td_api::make_object<td_api::acceptTermsOfService>(args)); send_request(td_api::make_object<td_api::acceptTermsOfService>(args));