Add td_api::StorePaymentPurpose.

This commit is contained in:
levlam 2022-07-01 19:27:59 +03:00
parent 035f24b8e9
commit 54c052adce
5 changed files with 71 additions and 25 deletions

View File

@ -3018,6 +3018,15 @@ premiumFeaturePromotionAnimation feature:PremiumFeature animation:animation = Pr
premiumState state:formattedText currency:string monthly_amount:int53 animations:vector<premiumFeaturePromotionAnimation> = PremiumState; premiumState state:formattedText currency:string monthly_amount:int53 animations:vector<premiumFeaturePromotionAnimation> = PremiumState;
//@class StorePaymentPurpose @description Describes a purpose of an in-store payment
//@description The user subscribed to Telegram Premium @is_restore Pass true if this is a restore of a Telegram Premium purchase; only for App Store
storePaymentPurposePremiumSubscription is_restore:Bool = StorePaymentPurpose;
//@description The user gifted Telegram Premium to another user @user_id Identifier of the user for which Premium was gifted @currency ISO 4217 currency code of the payment currency @amount Paid amount, in the smallest units of the currency
storePaymentPurposeGiftedPremium user_id:int53 currency:string amount:int64 = StorePaymentPurpose;
//@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method. To use specific push notification service, the correct application platform must be specified and a valid server authentication data must be uploaded at https://my.telegram.org //@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method. To use specific push notification service, the correct application platform must be specified and a valid server authentication data must be uploaded at https://my.telegram.org
//@description A token for Firebase Cloud Messaging @token Device registration token; may be empty to deregister a device @encrypt True, if push notifications must be additionally encrypted //@description A token for Firebase Cloud Messaging @token Device registration token; may be empty to deregister a device @encrypt True, if push notifications must be additionally encrypted
@ -6420,11 +6429,11 @@ getPremiumState = PremiumState;
//@description Checks whether Telegram Premium purchase is possible. Must be called before in-store Premium purchase //@description Checks whether Telegram Premium purchase is possible. Must be called before in-store Premium purchase
canPurchasePremium = Ok; canPurchasePremium = Ok;
//@description Informs server about a Telegram Premium purchase through App Store. For official applications only @receipt App Store receipt @is_restore Pass true if this is a restore of a Telegram Premium purchase //@description Informs server about a purchase through App Store. For official applications only @receipt App Store receipt @purpose Transaction purpose
assignAppStoreTransaction receipt:bytes is_restore:Bool = Ok; assignAppStoreTransaction receipt:bytes purpose:StorePaymentPurpose = Ok;
//@description Informs server about a Telegram Premium purchase through Google Play. For official applications only @purchase_token Google Play purchase token //@description Informs server about a purchase through Google Play. For official applications only @purchase_token Google Play purchase token @purpose Transaction purpose
assignGooglePlayTransaction purchase_token:string = Ok; assignGooglePlayTransaction purchase_token:string purpose:StorePaymentPurpose = Ok;
//@description Accepts Telegram terms of services @terms_of_service_id Terms of service identifier //@description Accepts Telegram terms of services @terms_of_service_id Terms of service identifier

View File

@ -67,6 +67,34 @@ static td_api::object_ptr<td_api::PremiumFeature> get_premium_feature_object(Sli
return nullptr; return nullptr;
} }
static Result<tl_object_ptr<telegram_api::InputStorePaymentPurpose>> get_input_store_payment_purpose(
Td *td, const td_api::object_ptr<td_api::StorePaymentPurpose> &purpose) {
if (purpose == nullptr) {
return Status::Error(400, "Purchase purpose must be non-empty");
}
switch (purpose->get_id()) {
case td_api::storePaymentPurposePremiumSubscription::ID: {
auto p = static_cast<const td_api::storePaymentPurposePremiumSubscription *>(purpose.get());
int32 flags = 0;
if (p->is_restore_) {
flags |= telegram_api::inputStorePaymentPremiumSubscription::RESTORE_MASK;
}
return make_tl_object<telegram_api::inputStorePaymentPremiumSubscription>(flags, false /*ignored*/);
}
case td_api::storePaymentPurposeGiftedPremium::ID: {
auto p = static_cast<const td_api::storePaymentPurposeGiftedPremium *>(purpose.get());
UserId user_id(p->user_id_);
TRY_RESULT(input_user, td->contacts_manager_->get_input_user(user_id));
return make_tl_object<telegram_api::inputStorePaymentGiftPremium>(std::move(input_user), p->currency_,
p->amount_);
}
default:
UNREACHABLE();
return nullptr;
}
}
class GetPremiumPromoQuery final : public Td::ResultHandler { class GetPremiumPromoQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::premiumState>> promise_; Promise<td_api::object_ptr<td_api::premiumState>> promise_;
@ -178,14 +206,14 @@ class AssignAppStoreTransactionQuery final : public Td::ResultHandler {
explicit AssignAppStoreTransactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit AssignAppStoreTransactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
void send(const string &receipt, bool is_restore) { void send(const string &receipt, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose) {
int32 flags = 0; auto r_input_purpose = get_input_store_payment_purpose(td_, purpose);
if (is_restore) { if (r_input_purpose.is_error()) {
flags |= telegram_api::inputStorePaymentPremiumSubscription::RESTORE_MASK; return on_error(r_input_purpose.move_as_error());
} }
send_query(G()->net_query_creator().create(telegram_api::payments_assignAppStoreTransaction(
BufferSlice(receipt), send_query(G()->net_query_creator().create(
make_tl_object<telegram_api::inputStorePaymentPremiumSubscription>(flags, false /*ignored*/)))); telegram_api::payments_assignAppStoreTransaction(BufferSlice(receipt), r_input_purpose.move_as_ok())));
} }
void on_result(BufferSlice packet) final { void on_result(BufferSlice packet) final {
@ -211,12 +239,16 @@ class AssignPlayMarketTransactionQuery final : public Td::ResultHandler {
explicit AssignPlayMarketTransactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit AssignPlayMarketTransactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
void send(const string &purchase_token) { void send(const string &purchase_token, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose) {
auto r_input_purpose = get_input_store_payment_purpose(td_, purpose);
if (r_input_purpose.is_error()) {
return on_error(r_input_purpose.move_as_error());
}
auto receipt = make_tl_object<telegram_api::dataJSON>(string()); auto receipt = make_tl_object<telegram_api::dataJSON>(string());
receipt->data_ = receipt->data_ =
json_encode<string>(json_object([&purchase_token](auto &o) { o("purchase_token", purchase_token); })); json_encode<string>(json_object([&purchase_token](auto &o) { o("purchase_token", purchase_token); }));
send_query(G()->net_query_creator().create(telegram_api::payments_assignPlayMarketTransaction( send_query(G()->net_query_creator().create(
std::move(receipt), make_tl_object<telegram_api::inputStorePaymentPremiumSubscription>(0, false /*ignored*/)))); telegram_api::payments_assignPlayMarketTransaction(std::move(receipt), r_input_purpose.move_as_ok())));
} }
void on_result(BufferSlice packet) final { void on_result(BufferSlice packet) final {
@ -478,12 +510,15 @@ void can_purchase_premium(Td *td, Promise<Unit> &&promise) {
td->create_handler<CanPurchasePremiumQuery>(std::move(promise))->send(); td->create_handler<CanPurchasePremiumQuery>(std::move(promise))->send();
} }
void assign_app_store_transaction(Td *td, const string &receipt, bool is_restore, Promise<Unit> &&promise) { void assign_app_store_transaction(Td *td, const string &receipt,
td->create_handler<AssignAppStoreTransactionQuery>(std::move(promise))->send(receipt, is_restore); td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise) {
td->create_handler<AssignAppStoreTransactionQuery>(std::move(promise))->send(receipt, std::move(purpose));
} }
void assign_play_market_transaction(Td *td, const string &purchase_token, Promise<Unit> &&promise) { void assign_play_market_transaction(Td *td, const string &purchase_token,
td->create_handler<AssignPlayMarketTransactionQuery>(std::move(promise))->send(purchase_token); td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose,
Promise<Unit> &&promise) {
td->create_handler<AssignPlayMarketTransactionQuery>(std::move(promise))->send(purchase_token, std::move(purpose));
} }
} // namespace td } // namespace td

View File

@ -32,8 +32,10 @@ void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>>
void can_purchase_premium(Td *td, Promise<Unit> &&promise); void can_purchase_premium(Td *td, Promise<Unit> &&promise);
void assign_app_store_transaction(Td *td, const string &receipt, bool is_restore, Promise<Unit> &&promise); void assign_app_store_transaction(Td *td, const string &receipt,
td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise);
void assign_play_market_transaction(Td *td, const string &purchase_token, Promise<Unit> &&promise); void assign_play_market_transaction(Td *td, const string &purchase_token,
td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise);
} // namespace td } // namespace td

View File

@ -5196,7 +5196,7 @@ void Td::on_request(uint64 id, const td_api::clickAnimatedEmojiMessage &request)
} }
void Td::on_request(uint64 id, const td_api::getInternalLinkType &request) { void Td::on_request(uint64 id, const td_api::getInternalLinkType &request) {
auto type = link_manager_->parse_internal_link(request.link_); auto type = LinkManager::parse_internal_link(request.link_);
send_closure(actor_id(this), &Td::send_result, id, type == nullptr ? nullptr : type->get_internal_link_type_object()); send_closure(actor_id(this), &Td::send_result, id, type == nullptr ? nullptr : type->get_internal_link_type_object());
} }
@ -7918,17 +7918,17 @@ void Td::on_request(uint64 id, const td_api::canPurchasePremium &request) {
can_purchase_premium(this, std::move(promise)); can_purchase_premium(this, std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::assignAppStoreTransaction &request) { void Td::on_request(uint64 id, td_api::assignAppStoreTransaction &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
assign_app_store_transaction(this, request.receipt_, request.is_restore_, std::move(promise)); assign_app_store_transaction(this, request.receipt_, std::move(request.purpose_), std::move(promise));
} }
void Td::on_request(uint64 id, td_api::assignGooglePlayTransaction &request) { void Td::on_request(uint64 id, td_api::assignGooglePlayTransaction &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.purchase_token_); CLEAN_INPUT_STRING(request.purchase_token_);
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
assign_play_market_transaction(this, request.purchase_token_, std::move(promise)); assign_play_market_transaction(this, request.purchase_token_, std::move(request.purpose_), std::move(promise));
} }
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) { void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {

View File

@ -1309,7 +1309,7 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::canPurchasePremium &request); void on_request(uint64 id, const td_api::canPurchasePremium &request);
void on_request(uint64 id, const td_api::assignAppStoreTransaction &request); void on_request(uint64 id, td_api::assignAppStoreTransaction &request);
void on_request(uint64 id, td_api::assignGooglePlayTransaction &request); void on_request(uint64 id, td_api::assignGooglePlayTransaction &request);