From 8673d3010936940cadc0d993cf9145c94a9e44f7 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 18 Jul 2022 15:17:01 +0300 Subject: [PATCH] Add gift support in assignGooglePlayTransaction. --- td/generate/scheme/td_api.tl | 8 ++++---- td/telegram/Premium.cpp | 16 +++++++++++----- td/telegram/Premium.h | 3 ++- td/telegram/Td.cpp | 5 ++++- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 9a26ff35c..12644b46d 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -469,9 +469,9 @@ chatAdministratorRights can_manage_chat:Bool can_change_info:Bool can_post_messa //@currency ISO 4217 currency code for Telegram Premium subscription payment //@amount The amount to pay, in the smallest units of the currency //@month_count Number of month the Telegram Premium subscription will be active -//@store_product Name of the store product associated with the option +//@store_product_id Identifier of the store product associated with the option //@payment_link An internal link to be opened for gifting Telegram Premium to the user if store payment isn't possible; may be null if direct payment isn't available -premiumGiftOption currency:string amount:int53 month_count:int32 store_product:string payment_link:InternalLinkType = PremiumGiftOption; +premiumGiftOption currency:string amount:int53 month_count:int32 store_product_id:string payment_link:InternalLinkType = PremiumGiftOption; //@description Represents a user @@ -6455,8 +6455,8 @@ canPurchasePremium purpose:StorePaymentPurpose = Ok; //@description Informs server about a purchase through App Store. For official applications only @receipt App Store receipt @purpose Transaction purpose assignAppStoreTransaction receipt:bytes purpose:StorePaymentPurpose = Ok; -//@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 purpose:StorePaymentPurpose = Ok; +//@description Informs server about a purchase through Google Play. For official applications only @package_name Application package name @store_product_id Identifier of the purchased store product @purchase_token Google Play purchase token @purpose Transaction purpose +assignGooglePlayTransaction package_name:string store_product_id:string purchase_token:string purpose:StorePaymentPurpose = Ok; //@description Accepts Telegram terms of services @terms_of_service_id Terms of service identifier diff --git a/td/telegram/Premium.cpp b/td/telegram/Premium.cpp index 0e6dc5744..146cf944d 100644 --- a/td/telegram/Premium.cpp +++ b/td/telegram/Premium.cpp @@ -247,14 +247,18 @@ class AssignPlayMarketTransactionQuery final : public Td::ResultHandler { explicit AssignPlayMarketTransactionQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(const string &purchase_token, td_api::object_ptr &&purpose) { + void send(const string &package_name, const string &store_product_id, const string &purchase_token, + td_api::object_ptr &&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(string()); - receipt->data_ = - json_encode(json_object([&purchase_token](auto &o) { o("purchase_token", purchase_token); })); + receipt->data_ = json_encode(json_object([&](auto &o) { + o("packageName", package_name); + o("purchaseToken", purchase_token); + o("productId", store_product_id); + })); send_query(G()->net_query_creator().create( telegram_api::payments_assignPlayMarketTransaction(std::move(receipt), r_input_purpose.move_as_ok()))); } @@ -525,10 +529,12 @@ void assign_app_store_transaction(Td *td, const string &receipt, td->create_handler(std::move(promise))->send(receipt, std::move(purpose)); } -void assign_play_market_transaction(Td *td, const string &purchase_token, +void assign_play_market_transaction(Td *td, const string &package_name, const string &store_product_id, + const string &purchase_token, td_api::object_ptr &&purpose, Promise &&promise) { - td->create_handler(std::move(promise))->send(purchase_token, std::move(purpose)); + td->create_handler(std::move(promise)) + ->send(package_name, store_product_id, purchase_token, std::move(purpose)); } } // namespace td diff --git a/td/telegram/Premium.h b/td/telegram/Premium.h index c8422f0ad..a385788bf 100644 --- a/td/telegram/Premium.h +++ b/td/telegram/Premium.h @@ -35,7 +35,8 @@ void can_purchase_premium(Td *td, td_api::object_ptr &&purpose, Promise &&promise); -void assign_play_market_transaction(Td *td, const string &purchase_token, +void assign_play_market_transaction(Td *td, const string &package_name, const string &store_product_id, + const string &purchase_token, td_api::object_ptr &&purpose, Promise &&promise); } // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index db868c243..2ded4e21e 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7936,9 +7936,12 @@ void Td::on_request(uint64 id, td_api::assignAppStoreTransaction &request) { void Td::on_request(uint64 id, td_api::assignGooglePlayTransaction &request) { CHECK_IS_USER(); + CLEAN_INPUT_STRING(request.package_name_); + CLEAN_INPUT_STRING(request.store_product_id_); CLEAN_INPUT_STRING(request.purchase_token_); CREATE_OK_REQUEST_PROMISE(); - assign_play_market_transaction(this, request.purchase_token_, std::move(request.purpose_), std::move(promise)); + assign_play_market_transaction(this, request.package_name_, request.store_product_id_, request.purchase_token_, + std::move(request.purpose_), std::move(promise)); } void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {