Add td_api::PaymentReceiptType and td_api::paymentReceiptTypeStars.

This commit is contained in:
levlam 2024-05-24 14:14:07 +03:00
parent 95e4a4f6d9
commit 62acb0aecd
2 changed files with 74 additions and 32 deletions

View File

@ -2726,17 +2726,30 @@ validatedOrderInfo order_info_id:string shipping_options:vector<shippingOption>
//@description Contains the result of a payment request @success True, if the payment request was successful; otherwise, the verification_url will be non-empty @verification_url URL for additional payment credentials verification
paymentResult success:Bool verification_url:string = PaymentResult;
//@description Contains information about a successful payment
//@product_info Information about the product
//@date Point in time (Unix timestamp) when the payment was made
//@seller_bot_user_id User identifier of the seller bot
//@class PaymentReceiptType @description Describes type of a successful payment
//@description The payment was done using a third-party payment provider
//@payment_provider_user_id User identifier of the payment provider bot
//@invoice Information about the invoice
//@order_info Order information; may be null
//@shipping_option Chosen shipping option; may be null
//@credentials_title Title of the saved credentials chosen by the buyer
//@tip_amount The amount of tip chosen by the buyer in the smallest units of the currency
paymentReceipt product_info:productInfo date:int32 seller_bot_user_id:int53 payment_provider_user_id:int53 invoice:invoice order_info:orderInfo shipping_option:shippingOption credentials_title:string tip_amount:int53 = PaymentReceipt;
paymentReceiptTypeRegular payment_provider_user_id:int53 invoice:invoice order_info:orderInfo shipping_option:shippingOption credentials_title:string tip_amount:int53 = PaymentReceiptType;
//@description The payment was done using Telegram stars
//@star_count Number of stars that were paid
//@transaction_id Unique identifier of the transaction that can be used to dispute it
paymentReceiptTypeStars star_count:int53 transaction_id:string = PaymentReceiptType;
//@description Contains information about a successful payment
//@product_info Information about the product
//@date Point in time (Unix timestamp) when the payment was made
//@seller_bot_user_id User identifier of the seller bot
//@type Type of the payment receipt
paymentReceipt product_info:productInfo date:int32 seller_bot_user_id:int53 type:PaymentReceiptType = PaymentReceipt;
//@class InputInvoice @description Describes an invoice to process

View File

@ -714,36 +714,65 @@ class GetPaymentReceiptQuery final : public Td::ResultHandler {
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetPaymentReceiptQuery: " << to_string(ptr);
if (ptr->get_id() != telegram_api::payments_paymentReceipt::ID) {
return on_error(Status::Error(500, "Receive unsupported response"));
}
auto payment_receipt = telegram_api::move_object_as<telegram_api::payments_paymentReceipt>(ptr);
switch (ptr->get_id()) {
case telegram_api::payments_paymentReceiptStars::ID: {
auto payment_receipt = telegram_api::move_object_as<telegram_api::payments_paymentReceiptStars>(ptr);
td_->user_manager_->on_get_users(std::move(payment_receipt->users_), "GetPaymentReceiptQuery");
td_->user_manager_->on_get_users(std::move(payment_receipt->users_), "GetPaymentReceiptQuery");
UserId seller_bot_user_id(payment_receipt->bot_id_);
if (!seller_bot_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid seller " << seller_bot_user_id;
return on_error(Status::Error(500, "Receive invalid seller identifier"));
}
auto photo = get_web_document_photo(td_->file_manager_.get(), std::move(payment_receipt->photo_), dialog_id_);
if (payment_receipt->invoice_->prices_.size() != 1u) {
LOG(ERROR) << "Receive invalid prices " << to_string(payment_receipt->invoice_->prices_);
return on_error(Status::Error(500, "Receive invalid price"));
}
auto type = td_api::make_object<td_api::paymentFormTypeStars>();
UserId payments_provider_user_id(payment_receipt->provider_id_);
if (!payments_provider_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid payments provider " << payments_provider_user_id;
return on_error(Status::Error(500, "Receive invalid payments provider identifier"));
}
UserId seller_bot_user_id(payment_receipt->bot_id_);
if (!seller_bot_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid seller " << seller_bot_user_id;
return on_error(Status::Error(500, "Receive invalid seller identifier"));
}
auto photo = get_web_document_photo(td_->file_manager_.get(), std::move(payment_receipt->photo_), dialog_id_);
if (payment_receipt->tip_amount_ < 0 || !check_currency_amount(payment_receipt->tip_amount_)) {
LOG(ERROR) << "Receive invalid tip amount " << payment_receipt->tip_amount_;
payment_receipt->tip_amount_ = 0;
}
promise_.set_value(make_tl_object<td_api::paymentReceipt>(
get_product_info_object(td_, payment_receipt->title_, payment_receipt->description_, photo),
payment_receipt->date_, td_->user_manager_->get_user_id_object(seller_bot_user_id, "paymentReceipt seller"),
td_api::make_object<td_api::paymentReceiptTypeStars>(payment_receipt->invoice_->prices_[0]->amount_,
payment_receipt->transaction_id_)));
break;
}
case telegram_api::payments_paymentReceipt::ID: {
auto payment_receipt = telegram_api::move_object_as<telegram_api::payments_paymentReceipt>(ptr);
promise_.set_value(make_tl_object<td_api::paymentReceipt>(
get_product_info_object(td_, payment_receipt->title_, payment_receipt->description_, photo),
payment_receipt->date_, td_->user_manager_->get_user_id_object(seller_bot_user_id, "paymentReceipt seller"),
td_->user_manager_->get_user_id_object(payments_provider_user_id, "paymentReceipt provider"),
convert_invoice(std::move(payment_receipt->invoice_)), convert_order_info(std::move(payment_receipt->info_)),
convert_shipping_option(std::move(payment_receipt->shipping_)), std::move(payment_receipt->credentials_title_),
payment_receipt->tip_amount_));
td_->user_manager_->on_get_users(std::move(payment_receipt->users_), "GetPaymentReceiptQuery");
UserId payments_provider_user_id(payment_receipt->provider_id_);
if (!payments_provider_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid payments provider " << payments_provider_user_id;
return on_error(Status::Error(500, "Receive invalid payments provider identifier"));
}
UserId seller_bot_user_id(payment_receipt->bot_id_);
if (!seller_bot_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid seller " << seller_bot_user_id;
return on_error(Status::Error(500, "Receive invalid seller identifier"));
}
auto photo = get_web_document_photo(td_->file_manager_.get(), std::move(payment_receipt->photo_), dialog_id_);
if (payment_receipt->tip_amount_ < 0 || !check_currency_amount(payment_receipt->tip_amount_)) {
LOG(ERROR) << "Receive invalid tip amount " << payment_receipt->tip_amount_;
payment_receipt->tip_amount_ = 0;
}
promise_.set_value(make_tl_object<td_api::paymentReceipt>(
get_product_info_object(td_, payment_receipt->title_, payment_receipt->description_, photo),
payment_receipt->date_, td_->user_manager_->get_user_id_object(seller_bot_user_id, "paymentReceipt seller"),
td_api::make_object<td_api::paymentReceiptTypeRegular>(
td_->user_manager_->get_user_id_object(payments_provider_user_id, "paymentReceipt provider"),
convert_invoice(std::move(payment_receipt->invoice_)),
convert_order_info(std::move(payment_receipt->info_)),
convert_shipping_option(std::move(payment_receipt->shipping_)),
std::move(payment_receipt->credentials_title_), payment_receipt->tip_amount_)));
break;
}
default:
UNREACHABLE();
}
}
void on_error(Status status) final {