Add optional invoice name to messagePaymentSuccessful.

This commit is contained in:
levlam 2022-05-11 18:52:45 +03:00
parent 0909f88bc3
commit 4ef4933536
3 changed files with 16 additions and 12 deletions

View File

@ -1955,8 +1955,8 @@ messageCustomServiceAction text:string = MessageContent;
//@description A new high score was achieved in a game @game_message_id Identifier of the message with the game, can be an identifier of a deleted message @game_id Identifier of the game; may be different from the games presented in the message with the game @score New score //@description A new high score was achieved in a game @game_message_id Identifier of the message with the game, can be an identifier of a deleted message @game_id Identifier of the game; may be different from the games presented in the message with the game @score New score
messageGameScore game_message_id:int53 game_id:int64 score:int32 = MessageContent; messageGameScore game_message_id:int53 game_id:int64 score:int32 = MessageContent;
//@description A payment has been completed @invoice_chat_id Identifier of the chat, containing the corresponding invoice message; 0 if unknown @invoice_message_id Identifier of the message with the corresponding invoice; can be an identifier of a deleted message @currency Currency for the price of the product @total_amount Total price for the product, in the smallest units of the currency //@description A payment has been completed @invoice_chat_id Identifier of the chat, containing the corresponding invoice message; 0 if unknown @invoice_message_id Identifier of the message with the corresponding invoice; can be an identifier of a deleted message @currency Currency for the price of the product @total_amount Total price for the product, in the smallest units of the currency @invoice_name Name of the invoice; may be empty if unknown
messagePaymentSuccessful invoice_chat_id:int53 invoice_message_id:int53 currency:string total_amount:int53 = MessageContent; messagePaymentSuccessful invoice_chat_id:int53 invoice_message_id:int53 currency:string total_amount:int53 invoice_name:string = MessageContent;
//@description A payment has been completed; for bots only @currency Currency for price of the product //@description A payment has been completed; for bots only @currency Currency for price of the product
//@total_amount Total price for the product, in the smallest units of the currency @invoice_payload Invoice payload @shipping_option_id Identifier of the shipping option chosen by the user; may be empty if not applicable @order_info Information about the order; may be null //@total_amount Total price for the product, in the smallest units of the currency @invoice_payload Invoice payload @shipping_option_id Identifier of the shipping option chosen by the user; may be empty if not applicable @order_info Information about the order; may be null

View File

@ -500,9 +500,9 @@ class MessagePaymentSuccessful final : public MessageContent {
MessageId invoice_message_id; MessageId invoice_message_id;
string currency; string currency;
int64 total_amount = 0; int64 total_amount = 0;
string invoice_payload; // or invoice_slug for users
// bots only part // bots only part
string invoice_payload;
string shipping_option_id; string shipping_option_id;
unique_ptr<OrderInfo> order_info; unique_ptr<OrderInfo> order_info;
string telegram_payment_charge_id; string telegram_payment_charge_id;
@ -510,11 +510,12 @@ class MessagePaymentSuccessful final : public MessageContent {
MessagePaymentSuccessful() = default; MessagePaymentSuccessful() = default;
MessagePaymentSuccessful(DialogId invoice_dialog_id, MessageId invoice_message_id, string &&currency, MessagePaymentSuccessful(DialogId invoice_dialog_id, MessageId invoice_message_id, string &&currency,
int64 total_amount) int64 total_amount, string &&invoice_payload)
: invoice_dialog_id(invoice_dialog_id) : invoice_dialog_id(invoice_dialog_id)
, invoice_message_id(invoice_message_id) , invoice_message_id(invoice_message_id)
, currency(std::move(currency)) , currency(std::move(currency))
, total_amount(total_amount) { , total_amount(total_amount)
, invoice_payload(std::move(invoice_payload)) {
} }
MessageContentType get_type() const final { MessageContentType get_type() const final {
@ -4772,13 +4773,16 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
LOG(ERROR) << "Receive MessageActionPaymentSent in " << owner_dialog_id; LOG(ERROR) << "Receive MessageActionPaymentSent in " << owner_dialog_id;
break; break;
} }
auto payment_sent = move_tl_object_as<telegram_api::messageActionPaymentSent>(action);
if (!reply_to_message_id.is_valid()) { if (!reply_to_message_id.is_valid()) {
LOG(ERROR) << "Receive succesful payment message with " << reply_to_message_id << " in " << owner_dialog_id; if (reply_to_message_id != MessageId() || payment_sent->invoice_slug_.empty()) {
LOG(ERROR) << "Receive succesful payment message with " << reply_to_message_id << " in " << owner_dialog_id;
}
reply_to_message_id = MessageId(); reply_to_message_id = MessageId();
} }
auto payment_sent = move_tl_object_as<telegram_api::messageActionPaymentSent>(action);
return td::make_unique<MessagePaymentSuccessful>(reply_in_dialog_id, reply_to_message_id, return td::make_unique<MessagePaymentSuccessful>(reply_in_dialog_id, reply_to_message_id,
std::move(payment_sent->currency_), payment_sent->total_amount_); std::move(payment_sent->currency_), payment_sent->total_amount_,
std::move(payment_sent->invoice_slug_));
} }
case telegram_api::messageActionPaymentSentMe::ID: { case telegram_api::messageActionPaymentSentMe::ID: {
if (!td->auth_manager_->is_bot()) { if (!td->auth_manager_->is_bot()) {
@ -4787,8 +4791,8 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
} }
auto payment_sent = move_tl_object_as<telegram_api::messageActionPaymentSentMe>(action); auto payment_sent = move_tl_object_as<telegram_api::messageActionPaymentSentMe>(action);
auto result = td::make_unique<MessagePaymentSuccessful>( auto result = td::make_unique<MessagePaymentSuccessful>(
DialogId(), MessageId(), std::move(payment_sent->currency_), payment_sent->total_amount_); DialogId(), MessageId(), std::move(payment_sent->currency_), payment_sent->total_amount_,
result->invoice_payload = payment_sent->payload_.as_slice().str(); payment_sent->payload_.as_slice().str());
result->shipping_option_id = std::move(payment_sent->shipping_option_id_); result->shipping_option_id = std::move(payment_sent->shipping_option_id_);
result->order_info = get_order_info(std::move(payment_sent->info_)); result->order_info = get_order_info(std::move(payment_sent->info_));
result->telegram_payment_charge_id = std::move(payment_sent->charge_->id_); result->telegram_payment_charge_id = std::move(payment_sent->charge_->id_);
@ -5089,7 +5093,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
} else { } else {
auto invoice_dialog_id = m->invoice_dialog_id.is_valid() ? m->invoice_dialog_id : dialog_id; auto invoice_dialog_id = m->invoice_dialog_id.is_valid() ? m->invoice_dialog_id : dialog_id;
return make_tl_object<td_api::messagePaymentSuccessful>(invoice_dialog_id.get(), m->invoice_message_id.get(), return make_tl_object<td_api::messagePaymentSuccessful>(invoice_dialog_id.get(), m->invoice_message_id.get(),
m->currency, m->total_amount); m->currency, m->total_amount, m->invoice_payload);
} }
} }
case MessageContentType::ContactRegistered: case MessageContentType::ContactRegistered:

View File

@ -4878,7 +4878,7 @@ class CliClient final : public Actor {
if (it->part_size > left_size) { if (it->part_size > left_size) {
it->part_size = left_size; it->part_size = left_size;
} }
BufferSlice block(it->part_size); BufferSlice block(narrow_cast<size_t>(it->part_size));
FileFd::open(it->source, FileFd::Flags::Read).move_as_ok().pread(block.as_slice(), it->local_size).ensure(); FileFd::open(it->source, FileFd::Flags::Read).move_as_ok().pread(block.as_slice(), it->local_size).ensure();
if (rand_bool()) { if (rand_bool()) {
auto open_flags = FileFd::Flags::Write | (it->local_size ? 0 : FileFd::Flags::Truncate | FileFd::Flags::Create); auto open_flags = FileFd::Flags::Write | (it->local_size ? 0 : FileFd::Flags::Truncate | FileFd::Flags::Create);