Add td_api::canPurchasePremium.
This commit is contained in:
parent
7153a17bd7
commit
9e13745487
@ -6403,6 +6403,9 @@ clickPremiumSubscriptionButton = Ok;
|
||||
//@description Returns state of Telegram Premium subscription and promotion videos for Premium features
|
||||
getPremiumState = PremiumState;
|
||||
|
||||
//@description Checks whether Telegram Premium purchase is possible. Must be called before in-store Premium purchase
|
||||
canPurchasePremium = Ok;
|
||||
|
||||
|
||||
//@description Accepts Telegram terms of services @terms_of_service_id Terms of service identifier
|
||||
acceptTermsOfService terms_of_service_id:string = Ok;
|
||||
|
@ -138,6 +138,35 @@ class GetPremiumPromoQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class CanPurchasePremiumQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit CanPurchasePremiumQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::payments_canPurchasePremium()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::payments_canPurchasePremium>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.ok();
|
||||
if (result) {
|
||||
return promise_.set_value(Unit());
|
||||
}
|
||||
on_error(Status::Error(400, "Premium can't be purchased"));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
const vector<Slice> &get_premium_limit_keys() {
|
||||
static const vector<Slice> limit_keys{"channels",
|
||||
"saved_gifs",
|
||||
@ -377,4 +406,8 @@ void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>>
|
||||
td->create_handler<GetPremiumPromoQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void can_purchase_premium(Td *td, Promise<Unit> &&promise) {
|
||||
td->create_handler<CanPurchasePremiumQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -31,4 +31,6 @@ void click_premium_subscription_button(Td *td, Promise<Unit> &&promise);
|
||||
|
||||
void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>> &&promise);
|
||||
|
||||
void can_purchase_premium(Td *td, Promise<Unit> &&promise);
|
||||
|
||||
} // namespace td
|
||||
|
@ -7892,6 +7892,12 @@ void Td::on_request(uint64 id, const td_api::getPremiumState &request) {
|
||||
get_premium_state(this, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::canPurchasePremium &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
can_purchase_premium(this, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.terms_of_service_id_);
|
||||
|
@ -1307,6 +1307,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::getPremiumState &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::canPurchasePremium &request);
|
||||
|
||||
void on_request(uint64 id, td_api::acceptTermsOfService &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getCountries &request);
|
||||
|
@ -2572,6 +2572,8 @@ class CliClient final : public Actor {
|
||||
send_request(td_api::make_object<td_api::clickPremiumSubscriptionButton>());
|
||||
} else if (op == "gprs") {
|
||||
send_request(td_api::make_object<td_api::getPremiumState>());
|
||||
} else if (op == "cppr") {
|
||||
send_request(td_api::make_object<td_api::canPurchasePremium>());
|
||||
} else if (op == "atos") {
|
||||
send_request(td_api::make_object<td_api::acceptTermsOfService>(args));
|
||||
} else if (op == "gdli") {
|
||||
|
Loading…
Reference in New Issue
Block a user