Add td_api::createInvoiceLink.

This commit is contained in:
levlam 2022-05-06 16:37:11 +03:00
parent 0fbafead84
commit 1970f65f56
5 changed files with 55 additions and 0 deletions

View File

@ -5949,6 +5949,10 @@ deleteSavedOrderInfo = Ok;
deleteSavedCredentials = Ok;
//@description Creates a link for the given invoice; for bots only @invoice Information about the invoice of the type inputMessageInvoice
createInvoiceLink invoice:InputMessageContent = HttpUrl;
//@description Returns a user that can be contacted to get support
getSupportUser = User;

View File

@ -593,6 +593,32 @@ class ClearSavedInfoQuery final : public Td::ResultHandler {
}
};
class ExportInvoiceQuery final : public Td::ResultHandler {
Promise<string> promise_;
public:
explicit ExportInvoiceQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
}
void send(tl_object_ptr<telegram_api::inputMediaInvoice> &&input_media_invoice) {
send_query(G()->net_query_creator().create(telegram_api::payments_exportInvoice(std::move(input_media_invoice))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_exportInvoice>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto link = result_ptr.move_as_ok();
promise_.set_value(std::move(link->url_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetBankCardInfoQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::bankCardInfo>> promise_;
@ -1313,6 +1339,14 @@ void delete_saved_credentials(Td *td, Promise<Unit> &&promise) {
td->create_handler<ClearSavedInfoQuery>(std::move(promise))->send(true, false);
}
void export_invoice(Td *td, td_api::object_ptr<td_api::InputMessageContent> &&invoice, Promise<string> &&promise) {
if (invoice == nullptr) {
return promise.set_error(Status::Error(400, "Invoice must be non-empty"));
}
TRY_RESULT_PROMISE(promise, input_invoice, process_input_message_invoice(std::move(invoice), td));
td->create_handler<ExportInvoiceQuery>(std::move(promise))->send(get_input_media_invoice(input_invoice, td));
}
void get_bank_card_info(Td *td, const string &bank_card_number,
Promise<td_api::object_ptr<td_api::bankCardInfo>> &&promise) {
td->create_handler<GetBankCardInfoQuery>(std::move(promise))->send(bank_card_number);

View File

@ -202,6 +202,8 @@ void delete_saved_order_info(Td *td, Promise<Unit> &&promise);
void delete_saved_credentials(Td *td, Promise<Unit> &&promise);
void export_invoice(Td *td, td_api::object_ptr<td_api::InputMessageContent> &&invoice, Promise<string> &&promise);
void get_bank_card_info(Td *td, const string &bank_card_number,
Promise<td_api::object_ptr<td_api::bankCardInfo>> &&promise);

View File

@ -7539,6 +7539,19 @@ void Td::on_request(uint64 id, const td_api::deleteSavedCredentials &request) {
delete_saved_credentials(this, std::move(promise));
}
void Td::on_request(uint64 id, td_api::createInvoiceLink &request) {
CHECK_IS_BOT();
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(td_api::make_object<td_api::httpUrl>(result.move_as_ok()));
}
});
export_invoice(this, std::move(request.invoice_), std::move(query_promise));
}
void Td::on_request(uint64 id, td_api::getPassportElement &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.password_);

View File

@ -1220,6 +1220,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::deleteSavedCredentials &request);
void on_request(uint64 id, td_api::createInvoiceLink &request);
void on_request(uint64 id, td_api::getPassportElement &request);
void on_request(uint64 id, td_api::getAllPassportElements &request);