From b1b532b81874f52f3af7f972b49e579e2ad17a96 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 30 May 2022 16:09:50 +0300 Subject: [PATCH] Add invoice.recurring_payment_terms_of_service_url. --- td/generate/scheme/td_api.tl | 3 ++- td/telegram/Payments.cpp | 27 +++++++++++++++++++-------- td/telegram/Payments.h | 1 + td/telegram/Payments.hpp | 10 ++++++++++ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e03d90fd6..3b0a74af4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1492,6 +1492,7 @@ labeledPricePart label:string amount:int53 = LabeledPricePart; //@price_parts A list of objects used to calculate the total price of the product //@max_tip_amount The maximum allowed amount of tip in the smallest units of the currency //@suggested_tip_amounts Suggested amounts of tip in the smallest units of the currency +//@recurring_payment_terms_of_service_url An HTTP URL with terms of service for recurring payments. If non-emprt, the invoice payment will result in recurring payments and the user must accep¥ the terms of service before allowed to pay //@is_test True, if the payment is a test payment //@need_name True, if the user's name is needed for payment //@need_phone_number True, if the user's phone number is needed for payment @@ -1500,7 +1501,7 @@ labeledPricePart label:string amount:int53 = LabeledPricePart; //@send_phone_number_to_provider True, if the user's phone number will be sent to the provider //@send_email_address_to_provider True, if the user's email address will be sent to the provider //@is_flexible True, if the total price depends on the shipping method -invoice currency:string price_parts:vector max_tip_amount:int53 suggested_tip_amounts:vector is_test:Bool need_name:Bool need_phone_number:Bool need_email_address:Bool need_shipping_address:Bool send_phone_number_to_provider:Bool send_email_address_to_provider:Bool is_flexible:Bool = Invoice; +invoice currency:string price_parts:vector max_tip_amount:int53 suggested_tip_amounts:vector recurring_payment_terms_of_service_url:string is_test:Bool need_name:Bool need_phone_number:Bool need_email_address:Bool need_shipping_address:Bool send_phone_number_to_provider:Bool send_email_address_to_provider:Bool is_flexible:Bool = Invoice; //@description Order information @name Name of the user @phone_number Phone number of the user @email_address Email address of the user @shipping_address Shipping address for this order; may be null orderInfo name:string phone_number:string email_address:string shipping_address:address = OrderInfo; diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp index 71721e584..3d5646765 100644 --- a/td/telegram/Payments.cpp +++ b/td/telegram/Payments.cpp @@ -180,10 +180,11 @@ static tl_object_ptr convert_invoice(tl_object_ptr( - std::move(invoice->currency_), std::move(labeled_prices), invoice->max_tip_amount_, - vector(invoice->suggested_tip_amounts_), is_test, need_name, need_phone_number, need_email_address, - need_shipping_address, send_phone_number_to_provider, send_email_address_to_provider, is_flexible); + return make_tl_object(std::move(invoice->currency_), std::move(labeled_prices), + invoice->max_tip_amount_, vector(invoice->suggested_tip_amounts_), + std::move(invoice->recurring_terms_url_), is_test, need_name, + need_phone_number, need_email_address, need_shipping_address, + send_phone_number_to_provider, send_email_address_to_provider, is_flexible); } static tl_object_ptr convert_payment_provider( @@ -669,7 +670,8 @@ bool operator==(const Invoice &lhs, const Invoice &rhs) { lhs.send_phone_number_to_provider == rhs.send_phone_number_to_provider && lhs.send_email_address_to_provider == rhs.send_email_address_to_provider && lhs.is_flexible == rhs.is_flexible && lhs.currency == rhs.currency && lhs.price_parts == rhs.price_parts && - lhs.max_tip_amount == rhs.max_tip_amount && lhs.suggested_tip_amounts == rhs.suggested_tip_amounts; + lhs.max_tip_amount == rhs.max_tip_amount && lhs.suggested_tip_amounts == rhs.suggested_tip_amounts && + lhs.recurring_payment_terms_of_service_url == rhs.recurring_payment_terms_of_service_url; } bool operator!=(const Invoice &lhs, const Invoice &rhs) { @@ -683,8 +685,11 @@ StringBuilder &operator<<(StringBuilder &string_builder, const Invoice &invoice) << (invoice.need_email_address ? ", needs email address" : "") << (invoice.need_shipping_address ? ", needs shipping address" : "") << (invoice.send_phone_number_to_provider ? ", sends phone number to provider" : "") - << (invoice.send_email_address_to_provider ? ", sends email address to provider" : "") << " in " - << invoice.currency << " with price parts " << format::as_array(invoice.price_parts) + << (invoice.send_email_address_to_provider ? ", sends email address to provider" : "") + << (invoice.recurring_payment_terms_of_service_url.empty() + ? string() + : ", recurring payments terms of service at " + invoice.recurring_payment_terms_of_service_url) + << " in " << invoice.currency << " with price parts " << format::as_array(invoice.price_parts) << " and suggested tip amounts " << invoice.suggested_tip_amounts << " up to " << invoice.max_tip_amount << "]"; } @@ -842,6 +847,8 @@ Result process_input_message_invoice( result.invoice.max_tip_amount = input_invoice->invoice_->max_tip_amount_; result.invoice.suggested_tip_amounts = std::move(input_invoice->invoice_->suggested_tip_amounts_); + result.invoice.recurring_payment_terms_of_service_url = + std::move(input_invoice->invoice_->recurring_payment_terms_of_service_url_); result.invoice.is_test = input_invoice->invoice_->is_test_; result.invoice.need_name = input_invoice->invoice_->need_name_; result.invoice.need_phone_number = input_invoice->invoice_->need_phone_number_; @@ -903,6 +910,9 @@ static tl_object_ptr get_input_invoice(const Invoice &inv if (invoice.max_tip_amount != 0) { flags |= telegram_api::invoice::MAX_TIP_AMOUNT_MASK; } + if (!invoice.recurring_payment_terms_of_service_url.empty()) { + flags |= telegram_api::invoice::RECURRING_TERMS_URL_MASK; + } auto prices = transform(invoice.price_parts, [](const LabeledPricePart &price) { return telegram_api::make_object(price.label, price.amount); @@ -910,7 +920,8 @@ static tl_object_ptr get_input_invoice(const Invoice &inv return make_tl_object( flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, invoice.currency, std::move(prices), - invoice.max_tip_amount, vector(invoice.suggested_tip_amounts), string()); + invoice.max_tip_amount, vector(invoice.suggested_tip_amounts), + invoice.recurring_payment_terms_of_service_url); } static tl_object_ptr get_input_web_document(const FileManager *file_manager, diff --git a/td/telegram/Payments.h b/td/telegram/Payments.h index 49010ba98..13deb0e31 100644 --- a/td/telegram/Payments.h +++ b/td/telegram/Payments.h @@ -39,6 +39,7 @@ struct Invoice { vector price_parts; int64 max_tip_amount = 0; vector suggested_tip_amounts; + string recurring_payment_terms_of_service_url; bool is_test = false; bool need_name = false; bool need_phone_number = false; diff --git a/td/telegram/Payments.hpp b/td/telegram/Payments.hpp index 5eef1de6a..46113c4fd 100644 --- a/td/telegram/Payments.hpp +++ b/td/telegram/Payments.hpp @@ -30,6 +30,7 @@ void parse(LabeledPricePart &labeled_price_part, ParserT &parser) { template void store(const Invoice &invoice, StorerT &storer) { bool has_tip = invoice.max_tip_amount != 0; + bool is_recurring = !invoice.recurring_payment_terms_of_service_url.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(invoice.is_test); STORE_FLAG(invoice.need_name); @@ -40,6 +41,7 @@ void store(const Invoice &invoice, StorerT &storer) { STORE_FLAG(invoice.send_phone_number_to_provider); STORE_FLAG(invoice.send_email_address_to_provider); STORE_FLAG(has_tip); + STORE_FLAG(is_recurring); END_STORE_FLAGS(); store(invoice.currency, storer); store(invoice.price_parts, storer); @@ -47,11 +49,15 @@ void store(const Invoice &invoice, StorerT &storer) { store(invoice.max_tip_amount, storer); store(invoice.suggested_tip_amounts, storer); } + if (is_recurring) { + store(invoice.recurring_payment_terms_of_service_url, storer); + } } template void parse(Invoice &invoice, ParserT &parser) { bool has_tip; + bool is_recurring; BEGIN_PARSE_FLAGS(); PARSE_FLAG(invoice.is_test); PARSE_FLAG(invoice.need_name); @@ -62,6 +68,7 @@ void parse(Invoice &invoice, ParserT &parser) { PARSE_FLAG(invoice.send_phone_number_to_provider); PARSE_FLAG(invoice.send_email_address_to_provider); PARSE_FLAG(has_tip); + PARSE_FLAG(is_recurring); END_PARSE_FLAGS(); parse(invoice.currency, parser); parse(invoice.price_parts, parser); @@ -69,6 +76,9 @@ void parse(Invoice &invoice, ParserT &parser) { parse(invoice.max_tip_amount, parser); parse(invoice.suggested_tip_amounts, parser); } + if (is_recurring) { + parse(invoice.recurring_payment_terms_of_service_url, parser); + } } template