Support Terms of Service for non-recurring payments.

This commit is contained in:
levlam 2023-09-12 17:30:17 +03:00
parent d1a2ca9261
commit 1558edd3dd
4 changed files with 23 additions and 5 deletions

View File

@ -2088,6 +2088,7 @@ labeledPricePart label:string amount:int53 = LabeledPricePart;
//@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-empty, the invoice payment will result in recurring payments and the user must accept the terms of service before allowed to pay
//@terms_of_service_url An HTTP URL with terms of service for non-recurring payments. If non-empty, then the user must accept 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
@ -2096,7 +2097,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<labeledPricePart> max_tip_amount:int53 suggested_tip_amounts:vector<int53> 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;
invoice currency:string price_parts:vector<labeledPricePart> max_tip_amount:int53 suggested_tip_amounts:vector<int53> recurring_payment_terms_of_service_url:string 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

View File

@ -35,7 +35,8 @@ bool operator==(const InputInvoice &lhs, const InputInvoice &rhs) {
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.recurring_payment_terms_of_service_url_ == rhs.recurring_payment_terms_of_service_url_;
lhs.recurring_payment_terms_of_service_url_ == rhs.recurring_payment_terms_of_service_url_ &&
lhs.terms_of_service_url_ == rhs.terms_of_service_url_;
};
return lhs.title_ == rhs.title_ && lhs.description_ == rhs.description_ && lhs.photo_ == rhs.photo_ &&
@ -129,6 +130,12 @@ Result<InputInvoice> InputInvoice::process_input_message_invoice(
if (!clean_input_string(input_invoice->invoice_->currency_)) {
return Status::Error(400, "Invoice currency must be encoded in UTF-8");
}
if (!clean_input_string(input_invoice->invoice_->recurring_payment_terms_of_service_url_)) {
return Status::Error(400, "Invoice terms of service URL must be encoded in UTF-8");
}
if (!clean_input_string(input_invoice->invoice_->terms_of_service_url_)) {
return Status::Error(400, "Invoice terms of service URL must be encoded in UTF-8");
}
InputInvoice result;
result.title_ = std::move(input_invoice->title_);
@ -200,6 +207,7 @@ Result<InputInvoice> InputInvoice::process_input_message_invoice(
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_.terms_of_service_url_ = std::move(input_invoice->invoice_->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_;
@ -267,9 +275,14 @@ tl_object_ptr<telegram_api::invoice> InputInvoice::Invoice::get_input_invoice()
if (max_tip_amount_ != 0) {
flags |= telegram_api::invoice::MAX_TIP_AMOUNT_MASK;
}
string terms_of_service_url;
if (!recurring_payment_terms_of_service_url_.empty()) {
flags |= telegram_api::invoice::RECURRING_MASK;
flags |= telegram_api::invoice::TERMS_URL_MASK;
terms_of_service_url = recurring_payment_terms_of_service_url_;
} else if (!terms_of_service_url_.empty()) {
flags |= telegram_api::invoice::TERMS_URL_MASK;
terms_of_service_url = terms_of_service_url_;
}
auto prices = transform(price_parts_, [](const LabeledPricePart &price) {
@ -278,7 +291,7 @@ tl_object_ptr<telegram_api::invoice> InputInvoice::Invoice::get_input_invoice()
return make_tl_object<telegram_api::invoice>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, currency_, std::move(prices),
max_tip_amount_, vector<int64>(suggested_tip_amounts_), recurring_payment_terms_of_service_url_);
max_tip_amount_, vector<int64>(suggested_tip_amounts_), terms_of_service_url);
}
static tl_object_ptr<telegram_api::inputWebDocument> get_input_web_document(const FileManager *file_manager,

View File

@ -30,6 +30,7 @@ class InputInvoice {
int64 max_tip_amount_ = 0;
vector<int64> suggested_tip_amounts_;
string recurring_payment_terms_of_service_url_;
string terms_of_service_url_;
bool is_test_ = false;
bool need_name_ = false;
bool need_phone_number_ = false;

View File

@ -194,13 +194,16 @@ static tl_object_ptr<td_api::invoice> convert_invoice(tl_object_ptr<telegram_api
}
string recurring_terms_url;
string terms_url;
if (invoice->recurring_) {
recurring_terms_url = std::move(invoice->terms_url_);
} else {
terms_url = std::move(invoice->terms_url_);
}
return make_tl_object<td_api::invoice>(std::move(invoice->currency_), std::move(labeled_prices),
invoice->max_tip_amount_, std::move(invoice->suggested_tip_amounts_),
recurring_terms_url, is_test, need_name, need_phone_number, need_email_address,
need_shipping_address, send_phone_number_to_provider,
recurring_terms_url, 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);
}